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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import urllib
from marionette_driver.by import By
from marionette_driver import errors
from marionette_driver.wait import Wait
from marionette_harness import MarionetteTestCase
def inline(doc):
return "data:text/html;charset=utf-8,{}".format(urllib.quote(doc))
# The <a> element in the following HTML is not interactable because it
# is hidden by an overlay when scrolled into the top of the viewport.
# It should be interactable when scrolled in at the bottom of the
# viewport.
fixed_overlay = inline("""
<style>
* { margin: 0; padding: 0; }
body { height: 300vh }
div, a { display: block }
div {
background-color: pink;
position: fixed;
width: 100%;
height: 40px;
top: 0;
}
a {
margin-top: 1000px;
}
</style>
<div>overlay</div>
<a href=#>link</a>
<script>
window.clicked = false;
let link = document.querySelector("a");
link.addEventListener("click", () => window.clicked = true);
</script>
""")
obscured_overlay = inline("""
<style>
* { margin: 0; padding: 0; }
body { height: 100vh }
#overlay {
background-color: pink;
position: absolute;
width: 100%;
height: 100%;
}
</style>
<div id=overlay></div>
<a id=obscured href=#>link</a>
<script>
window.clicked = false;
let link = document.querySelector("#obscured");
link.addEventListener("click", () => window.clicked = true);
</script>
""")
class TestLegacyClick(MarionetteTestCase):
"""Uses legacy Selenium element displayedness checks."""
def setUp(self):
MarionetteTestCase.setUp(self)
self.marionette.delete_session()
self.marionette.start_session()
def test_click(self):
self.marionette.navigate(inline("""
<button>click me</button>
<script>
window.clicks = 0;
let button = document.querySelector("button");
button.addEventListener("click", () => window.clicks++);
</script>
"""))
button = self.marionette.find_element(By.TAG_NAME, "button")
button.click()
self.assertEqual(1, self.marionette.execute_script("return window.clicks", sandbox=None))
def test_click_number_link(self):
test_html = self.marionette.absolute_url("clicks.html")
self.marionette.navigate(test_html)
self.marionette.find_element(By.LINK_TEXT, "333333").click()
Wait(self.marionette, timeout=30, ignored_exceptions=errors.NoSuchElementException).until(
lambda m: m.find_element(By.ID, "username"))
self.assertEqual(self.marionette.title, "XHTML Test Page")
def test_clicking_an_element_that_is_not_displayed_raises(self):
test_html = self.marionette.absolute_url("hidden.html")
self.marionette.navigate(test_html)
with self.assertRaises(errors.ElementNotInteractableException):
self.marionette.find_element(By.ID, "child").click()
def test_clicking_on_a_multiline_link(self):
test_html = self.marionette.absolute_url("clicks.html")
self.marionette.navigate(test_html)
self.marionette.find_element(By.ID, "overflowLink").click()
self.wait_for_condition(lambda mn: self.marionette.title == "XHTML Test Page")
def test_scroll_into_view_near_end(self):
self.marionette.navigate(fixed_overlay)
link = self.marionette.find_element(By.TAG_NAME, "a")
link.click()
self.assertTrue(self.marionette.execute_script("return window.clicked", sandbox=None))
class TestClick(TestLegacyClick):
"""Uses WebDriver specification compatible element interactability
checks.
"""
def setUp(self):
TestLegacyClick.setUp(self)
self.marionette.delete_session()
self.marionette.start_session(
{"requiredCapabilities": {"specificationLevel": 1}})
def test_click_element_obscured_by_absolute_positioned_element(self):
self.marionette.navigate(obscured_overlay)
overlay = self.marionette.find_element(By.ID, "overlay")
obscured = self.marionette.find_element(By.ID, "obscured")
overlay.click()
with self.assertRaises(errors.ElementClickInterceptedException):
obscured.click()
def test_centre_outside_viewport_vertically(self):
self.marionette.navigate(inline("""
<style>
* { margin: 0; padding: 0; }
div {
display: block;
position: absolute;
background-color: blue;
width: 200px;
height: 200px;
/* move centre point off viewport vertically */
top: -105px;
}
</style>
<div></div>"""))
self.marionette.find_element(By.TAG_NAME, "div").click()
def test_centre_outside_viewport_horizontally(self):
self.marionette.navigate(inline("""
<style>
* { margin: 0; padding: 0; }
div {
display: block;
position: absolute;
background-color: blue;
width: 200px;
height: 200px;
/* move centre point off viewport horizontally */
left: -105px;
}
</style>
<div></div>"""))
self.marionette.find_element(By.TAG_NAME, "div").click()
def test_centre_outside_viewport(self):
self.marionette.navigate(inline("""
<style>
* { margin: 0; padding: 0; }
div {
display: block;
position: absolute;
background-color: blue;
width: 200px;
height: 200px;
/* move centre point off viewport */
left: -105px;
top: -105px;
}
</style>
<div></div>"""))
self.marionette.find_element(By.TAG_NAME, "div").click()
def test_css_transforms(self):
self.marionette.navigate(inline("""
<style>
* { margin: 0; padding: 0; }
div {
display: block;
background-color: blue;
width: 200px;
height: 200px;
transform: translateX(-105px);
}
</style>
<div></div>"""))
self.marionette.find_element(By.TAG_NAME, "div").click()
def test_input_file(self):
self.marionette.navigate(inline("<input type=file>"))
with self.assertRaises(errors.InvalidArgumentException):
self.marionette.find_element(By.TAG_NAME, "input").click()
def test_container_element(self):
self.marionette.navigate(inline("""
<select>
<option>foo</option>
</select>"""))
option = self.marionette.find_element(By.TAG_NAME, "option")
option.click()
self.assertTrue(option.get_property("selected"))
def test_container_element_outside_view(self):
self.marionette.navigate(inline("""
<select style="margin-top: 100vh">
<option>foo</option>
</select>"""))
option = self.marionette.find_element(By.TAG_NAME, "option")
option.click()
self.assertTrue(option.get_property("selected"))
def test_obscured_element(self):
self.marionette.navigate(obscured_overlay)
overlay = self.marionette.find_element(By.ID, "overlay")
obscured = self.marionette.find_element(By.ID, "obscured")
overlay.click()
with self.assertRaises(errors.ElementClickInterceptedException):
obscured.click()
self.assertFalse(self.marionette.execute_script("return window.clicked", sandbox=None))
|