/
FrameSupportSpec.groovy
226 lines (184 loc) · 4.88 KB
/
FrameSupportSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package geb.frame
import geb.test.GebSpecWithServer
import geb.Page
import geb.Module
import spock.lang.Unroll
import org.openqa.selenium.WebElement
import org.openqa.selenium.NoSuchFrameException
class FrameSupportSpec extends GebSpecWithServer {
def setupSpec() {
responseHtml { request, response ->
def pageText = (~'/(.*)').matcher(request.requestURI)[0][1]
if (pageText == "frames") {
response.outputStream << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">"
}
head {
title pageText
}
if (pageText == "frames") {
frameset(rows: "25%,75%") {
frame(name: 'header', id: 'header-id', src: '/header')
frame(id: 'footer', src: '/footer')
}
} else if (pageText == "iframe") {
body { iframe(id: 'inline', src: '/inline') }
} else {
body { span("$pageText") }
}
}
}
def setup() {
go "frames"
}
def "verify the server is configured correctly for main page"() {
expect:
$('frame').size() == 2
}
@Unroll("verify that server is configured correctly for frame page: #text")
def "verify that server is configured correctly for frame pages"() {
when:
go "$text"
then:
$('span').text() == text
where:
text << ['header', 'footer', 'inline']
}
@Unroll("expect withFrame to fail if called for a non existing frame '#frame'")
def "expect withFrame to fail if called for a non existing frame"() {
when:
withFrame(frame) {}
then:
thrown(NoSuchFrameException)
where:
frame << ['frame', 'idontexist']
}
@Unroll
def "expect withFrame to fail if called for a navigator that doesn't contain a frame"() {
when:
withFrame(navigatorFactory.call()) {}
then:
NoSuchFrameException e = thrown()
e.message.startsWith(message)
where:
message | navigatorFactory
'' | { $('span') }
'No elements for given content:' | { $('') }
}
def "expect withFrame to fail if called for an empty navigator"() {
when:
withFrame($('nonexistingelem')) {}
then:
thrown(NoSuchFrameException)
}
@Unroll("expect the closure argument passed to withFrame to be executed for '#frame' as frame identifier")
def "expect the closure argument passed to withFrame to be executed"() {
given:
go pagePath
when:
boolean called = false
withFrame(frameid) {
called = true
}
then:
called
where:
pagePath | frameid
"frames" | "header"
"iframe" | "inline"
"frames" | 0
}
def "expect the closure argument passed to withFrame to be executed for navigator as frame identifier"() {
when:
boolean called = false
withFrame($('#footer')) {
called = true
}
then:
called
}
private String getFrameText(frame) {
withFrame(frame) {
$("span").text()
}
}
@Unroll("withFrame changes focus to frame and returns closure return value for frame identifier '#frame'")
def "withFrame changes focus to frame with given identifier and returns closure return value"() {
given:
go pagePath
expect:
getFrameText(frame) == text
where:
pagePath |frame | text
"frames" | 'header' | 'header'
"frames" | 'footer' | 'footer'
"iframe" | 'inline' | 'inline'
"frames" | 0 | 'header'
"frames" | 1 | 'footer'
"iframe" | 0 | 'inline'
}
@Unroll("withFrame changes focus to frame and returns closure return value for selector '#selector'")
def "withFrame changes focus to frame with given selector and returns closure return value"() {
given:
go pagePath
expect:
getFrameText($(selector)) == text
where:
pagePath | selector | text
"frames" | '#header-id' | 'header'
"frames" | '#footer' | 'footer'
"iframe" | '#inline' | 'inline'
}
private boolean isInFramesContext() {
title == 'frames'
}
@Unroll
def "ensure original context is kept after a withFrame call"() {
when:
withFrame(frame) {}
then:
inFramesContext
when:
withFrame(frame) { throw new Exception() }
then:
thrown(Exception)
inFramesContext
where:
frame << ['header', 0]
}
def "ensure pages and modules have withFrame available"() {
when:
to FrameSupportSpecPage
then:
page.callAllVariantsOfWithFrame() == 3
page.returnValueOfWithFrameCallForPageContent == 'footer'
mod.callAllVariantsOfWithFrame() == 3
}
}
class FrameSupportSpecPage extends Page {
static url = "/frames"
static content = {
footer { $('#footer') }
mod { module FrameSupportSpecModule }
}
def callAllVariantsOfWithFrame() {
def count = 0
def block = { count++ }
withFrame(0, block)
withFrame('header', block)
withFrame(footer, block)
count
}
def getReturnValueOfWithFrameCallForPageContent() {
withFrame(footer) { $('span').text() }
}
}
class FrameSupportSpecModule extends Module {
def callAllVariantsOfWithFrame() {
def count = 0
def block = { count++ }
withFrame(0, block)
withFrame('header', block)
withFrame($('#footer'), block)
count
}
}