3
3
using System . Text ;
4
4
using NUnit . Framework ;
5
5
using System . Collections . ObjectModel ;
6
+ using OpenQA . Selenium . Environment ;
6
7
7
8
namespace OpenQA . Selenium
8
9
{
9
10
[ TestFixture ]
10
11
public class CorrectEventFiringTest : DriverTestFixture
11
12
{
12
13
[ Test ]
13
- [ IgnoreBrowser ( Browser . Android ) ]
14
- [ IgnoreBrowser ( Browser . Chrome , "Webkit bug 22261" ) ]
15
14
public void ShouldFireFocusEventWhenClicking ( )
16
15
{
17
16
driver . Url = javascriptPage ;
@@ -23,7 +22,6 @@ public void ShouldFireFocusEventWhenClicking()
23
22
24
23
[ Test ]
25
24
[ Category ( "Javascript" ) ]
26
- [ IgnoreBrowser ( Browser . Android ) ]
27
25
public void ShouldFireClickEventWhenClicking ( )
28
26
{
29
27
driver . Url = javascriptPage ;
@@ -35,7 +33,6 @@ public void ShouldFireClickEventWhenClicking()
35
33
36
34
[ Test ]
37
35
[ Category ( "Javascript" ) ]
38
- [ IgnoreBrowser ( Browser . Android ) ]
39
36
public void ShouldFireMouseDownEventWhenClicking ( )
40
37
{
41
38
driver . Url = javascriptPage ;
@@ -47,7 +44,6 @@ public void ShouldFireMouseDownEventWhenClicking()
47
44
48
45
[ Test ]
49
46
[ Category ( "Javascript" ) ]
50
- [ IgnoreBrowser ( Browser . Android ) ]
51
47
public void ShouldFireMouseUpEventWhenClicking ( )
52
48
{
53
49
driver . Url = javascriptPage ;
@@ -82,7 +78,6 @@ public void ShouldFireMouseMoveEventWhenClicking()
82
78
83
79
[ Test ]
84
80
[ Category ( "Javascript" ) ]
85
- [ IgnoreBrowser ( Browser . HtmlUnit ) ]
86
81
public void ShouldNotThrowIfEventHandlerThrows ( )
87
82
{
88
83
driver . Url = javascriptPage ;
@@ -91,8 +86,6 @@ public void ShouldNotThrowIfEventHandlerThrows()
91
86
92
87
[ Test ]
93
88
[ Category ( "Javascript" ) ]
94
- [ IgnoreBrowser ( Browser . Android ) ]
95
- [ IgnoreBrowser ( Browser . Chrome , "Webkit bug 22261" ) ]
96
89
public void ShouldFireEventsInTheRightOrder ( )
97
90
{
98
91
driver . Url = javascriptPage ;
@@ -115,7 +108,6 @@ public void ShouldFireEventsInTheRightOrder()
115
108
116
109
[ Test ]
117
110
[ Category ( "Javascript" ) ]
118
- [ IgnoreBrowser ( Browser . Android ) ]
119
111
public void ShouldIssueMouseDownEvents ( )
120
112
{
121
113
driver . Url = javascriptPage ;
@@ -149,7 +141,6 @@ public void ShouldIssueMouseUpEvents()
149
141
150
142
[ Test ]
151
143
[ Category ( "Javascript" ) ]
152
- [ IgnoreBrowser ( Browser . IPhone ) ]
153
144
public void MouseEventsShouldBubbleUpToContainingElements ( )
154
145
{
155
146
driver . Url = javascriptPage ;
@@ -161,7 +152,6 @@ public void MouseEventsShouldBubbleUpToContainingElements()
161
152
162
153
[ Test ]
163
154
[ Category ( "Javascript" ) ]
164
- [ IgnoreBrowser ( Browser . IPhone ) ]
165
155
public void ShouldEmitOnChangeEventsWhenSelectingElements ( )
166
156
{
167
157
driver . Url = javascriptPage ;
@@ -179,6 +169,23 @@ public void ShouldEmitOnChangeEventsWhenSelectingElements()
179
169
Assert . AreEqual ( driver . FindElement ( By . Id ( "result" ) ) . Text , "bar" ) ;
180
170
}
181
171
172
+ [ Test ]
173
+ [ Category ( "Javascript" ) ]
174
+ public void ShouldEmitOnClickEventsWhenSelectingElements ( )
175
+ {
176
+ driver . Url = javascriptPage ;
177
+ // Intentionally not looking up the select tag. See selenium r7937 for details.
178
+ ReadOnlyCollection < IWebElement > allOptions = driver . FindElements ( By . XPath ( "//select[@id='selector2']//option" ) ) ;
179
+
180
+ IWebElement foo = allOptions [ 0 ] ;
181
+ IWebElement bar = allOptions [ 1 ] ;
182
+
183
+ foo . Click ( ) ;
184
+ Assert . AreEqual ( driver . FindElement ( By . Id ( "result" ) ) . Text , "foo" ) ;
185
+ bar . Click ( ) ;
186
+ Assert . AreEqual ( driver . FindElement ( By . Id ( "result" ) ) . Text , "bar" ) ;
187
+ }
188
+
182
189
[ Test ]
183
190
[ Category ( "Javascript" ) ]
184
191
[ IgnoreBrowser ( Browser . IE , "IE does not fire change event when clicking on checkbox" ) ]
@@ -205,7 +212,6 @@ public void ShouldEmitClickEventWhenClickingOnATextInputElement()
205
212
206
213
[ Test ]
207
214
[ Category ( "Javascript" ) ]
208
- [ IgnoreBrowser ( Browser . Android ) ]
209
215
public void ShouldFireTwoClickEventsWhenClickingOnALabel ( )
210
216
{
211
217
driver . Url = javascriptPage ;
@@ -219,7 +225,6 @@ public void ShouldFireTwoClickEventsWhenClickingOnALabel()
219
225
220
226
[ Test ]
221
227
[ Category ( "Javascript" ) ]
222
- [ IgnoreBrowser ( Browser . Android ) ]
223
228
public void ClearingAnElementShouldCauseTheOnChangeHandlerToFire ( )
224
229
{
225
230
driver . Url = javascriptPage ;
@@ -233,8 +238,6 @@ public void ClearingAnElementShouldCauseTheOnChangeHandlerToFire()
233
238
234
239
[ Test ]
235
240
[ Category ( "Javascript" ) ]
236
- [ IgnoreBrowser ( Browser . IPhone , "SendKeys implementation is incorrect." ) ]
237
- [ IgnoreBrowser ( Browser . Android ) ]
238
241
public void SendingKeysToAnotherElementShouldCauseTheBlurEventToFire ( )
239
242
{
240
243
driver . Url = javascriptPage ;
@@ -247,8 +250,6 @@ public void SendingKeysToAnotherElementShouldCauseTheBlurEventToFire()
247
250
248
251
[ Test ]
249
252
[ Category ( "Javascript" ) ]
250
- [ IgnoreBrowser ( Browser . IPhone , "SendKeys implementation is incorrect." ) ]
251
- [ IgnoreBrowser ( Browser . Android ) ]
252
253
public void SendingKeysToAnElementShouldCauseTheFocusEventToFire ( )
253
254
{
254
255
driver . Url = javascriptPage ;
@@ -259,7 +260,6 @@ public void SendingKeysToAnElementShouldCauseTheFocusEventToFire()
259
260
260
261
[ Test ]
261
262
[ Category ( "Javascript" ) ]
262
- [ IgnoreBrowser ( Browser . IPhone , "Input elements are blurred when the keyboard is closed." ) ]
263
263
public void SendingKeysToAFocusedElementShouldNotBlurThatElement ( )
264
264
{
265
265
driver . Url = javascriptPage ;
@@ -328,8 +328,6 @@ public void SubmittingFormFromFormInputTextElementShouldFireOnSubmitForThatFormA
328
328
329
329
[ Test ]
330
330
[ Category ( "Javascript" ) ]
331
- [ IgnoreBrowser ( Browser . IPhone , "Does not yet support file uploads" ) ]
332
- [ IgnoreBrowser ( Browser . Android , "Does not yet support file uploads" ) ]
333
331
[ IgnoreBrowser ( Browser . Safari , "Does not yet support file uploads" ) ]
334
332
[ IgnoreBrowser ( Browser . WindowsPhone , "Does not yet support file uploads" ) ]
335
333
public void UploadingFileShouldFireOnChangeEvent ( )
@@ -371,6 +369,106 @@ public void ShouldReportTheXAndYCoordinatesWhenClicking()
371
369
Assert . AreNotEqual ( "0" , clientY ) ;
372
370
}
373
371
372
+ [ Test ]
373
+ public void ClickEventsShouldBubble ( )
374
+ {
375
+ driver . Url = clicksPage ;
376
+ driver . FindElement ( By . Id ( "bubblesFrom" ) ) . Click ( ) ;
377
+ bool eventBubbled = ( bool ) ( ( IJavaScriptExecutor ) driver ) . ExecuteScript ( "return !!window.bubbledClick;" ) ;
378
+ Assert . IsTrue ( eventBubbled , "Event didn't bubble up" ) ;
379
+ }
380
+
381
+ [ Test ]
382
+ [ IgnoreBrowser ( Browser . IE , "IE doesn't support detecting overlapped elements" ) ]
383
+ [ IgnoreBrowser ( Browser . Safari ) ]
384
+ public void ClickOverlappingElements ( )
385
+ {
386
+ if ( TestUtilities . IsOldIE ( driver ) )
387
+ {
388
+ Assert . Ignore ( "Not supported on IE < 9" ) ;
389
+ }
390
+
391
+ driver . Url = EnvironmentManager . Instance . UrlBuilder . WhereIs ( "click_tests/overlapping_elements.html" ) ;
392
+ var ex = Assert . Throws < WebDriverException > ( ( ) => driver . FindElement ( By . Id ( "under" ) ) . Click ( ) ) ;
393
+ Assert . That ( ex . Message . Contains ( "Other element would receive the click" ) ) ;
394
+ }
395
+
396
+ [ Test ]
397
+ [ IgnoreBrowser ( Browser . IE , "IE doesn't support detecting overlapped elements" ) ]
398
+ [ IgnoreBrowser ( Browser . Chrome ) ]
399
+ [ IgnoreBrowser ( Browser . Safari ) ]
400
+ public void ClickPartiallyOverlappingElements ( )
401
+ {
402
+ if ( TestUtilities . IsOldIE ( driver ) )
403
+ {
404
+ Assert . Ignore ( "Not supported on IE < 9" ) ;
405
+ }
406
+
407
+ StringBuilder expectedLogBuilder = new StringBuilder ( ) ;
408
+ expectedLogBuilder . AppendLine ( "Log:" ) ;
409
+ expectedLogBuilder . AppendLine ( "mousedown in under (handled by under)" ) ;
410
+ expectedLogBuilder . AppendLine ( "mousedown in under (handled by body)" ) ;
411
+ expectedLogBuilder . AppendLine ( "mouseup in under (handled by under)" ) ;
412
+ expectedLogBuilder . AppendLine ( "mouseup in under (handled by body)" ) ;
413
+ expectedLogBuilder . AppendLine ( "click in under (handled by under)" ) ;
414
+ expectedLogBuilder . Append ( "click in under (handled by body)" ) ;
415
+
416
+ for ( int i = 1 ; i < 6 ; i ++ )
417
+ {
418
+ driver . Url = EnvironmentManager . Instance . UrlBuilder . WhereIs ( "click_tests/partially_overlapping_elements.html" ) ;
419
+ IWebElement over = driver . FindElement ( By . Id ( "over" + i ) ) ;
420
+ ( ( IJavaScriptExecutor ) driver ) . ExecuteScript ( "arguments[0].style.display = 'none'" , over ) ;
421
+ driver . FindElement ( By . Id ( "under" ) ) . Click ( ) ;
422
+ Assert . AreEqual ( expectedLogBuilder . ToString ( ) , driver . FindElement ( By . Id ( "log" ) ) . Text ) ;
423
+ }
424
+ }
425
+
426
+ [ Test ]
427
+ [ IgnoreBrowser ( Browser . Firefox ) ]
428
+ [ IgnoreBrowser ( Browser . Chrome ) ]
429
+ [ IgnoreBrowser ( Browser . Safari ) ]
430
+ public void NativelyClickOverlappingElements ( )
431
+ {
432
+ if ( TestUtilities . IsOldIE ( driver ) )
433
+ {
434
+ Assert . Ignore ( "Not supported on IE < 9" ) ;
435
+ }
436
+
437
+ StringBuilder expectedLogBuilder = new StringBuilder ( ) ;
438
+ expectedLogBuilder . AppendLine ( "Log:" ) ;
439
+ expectedLogBuilder . AppendLine ( "mousedown in over (handled by over)" ) ;
440
+ expectedLogBuilder . AppendLine ( "mousedown in over (handled by body)" ) ;
441
+ expectedLogBuilder . AppendLine ( "mouseup in over (handled by over)" ) ;
442
+ expectedLogBuilder . AppendLine ( "mouseup in over (handled by body)" ) ;
443
+ expectedLogBuilder . AppendLine ( "click in over (handled by over)" ) ;
444
+ expectedLogBuilder . Append ( "click in over (handled by body)" ) ;
445
+
446
+ driver . Url = EnvironmentManager . Instance . UrlBuilder . WhereIs ( "click_tests/overlapping_elements.html" ) ;
447
+ driver . FindElement ( By . Id ( "under" ) ) . Click ( ) ;
448
+ Assert . AreEqual ( expectedLogBuilder . ToString ( ) , driver . FindElement ( By . Id ( "log" ) ) . Text ) ;
449
+ }
450
+
451
+ [ Test ]
452
+ [ IgnoreBrowser ( Browser . Safari ) ]
453
+ public void ClickAnElementThatDisappear ( )
454
+ {
455
+ if ( TestUtilities . IsOldIE ( driver ) )
456
+ {
457
+ Assert . Ignore ( "Not supported on IE < 9" ) ;
458
+ }
459
+
460
+ StringBuilder expectedLogBuilder = new StringBuilder ( ) ;
461
+ expectedLogBuilder . AppendLine ( "Log:" ) ;
462
+ expectedLogBuilder . AppendLine ( "mousedown in over (handled by over)" ) ;
463
+ expectedLogBuilder . AppendLine ( "mousedown in over (handled by body)" ) ;
464
+ expectedLogBuilder . AppendLine ( "mouseup in under (handled by under)" ) ;
465
+ expectedLogBuilder . Append ( "mouseup in under (handled by body)" ) ;
466
+
467
+ driver . Url = EnvironmentManager . Instance . UrlBuilder . WhereIs ( "click_tests/disappearing_element.html" ) ;
468
+ driver . FindElement ( By . Id ( "over" ) ) . Click ( ) ;
469
+ Assert . That ( driver . FindElement ( By . Id ( "log" ) ) . Text . StartsWith ( expectedLogBuilder . ToString ( ) ) ) ;
470
+ }
471
+
374
472
private void AssertEventNotFired ( string eventName )
375
473
{
376
474
IWebElement result = driver . FindElement ( By . Id ( "result" ) ) ;
0 commit comments