17
17
18
18
package org .openqa .selenium .interactions ;
19
19
20
- import static org .assertj .core .api .Assertions .assertThat ;
21
- import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
22
- import static org .openqa .selenium .WaitingConditions .elementTextToEqual ;
23
- import static org .openqa .selenium .WaitingConditions .elementValueToEqual ;
24
- import static org .openqa .selenium .support .Colors .GREEN ;
25
- import static org .openqa .selenium .support .Colors .RED ;
26
- import static org .openqa .selenium .support .ui .ExpectedConditions .attributeToBe ;
27
- import static org .openqa .selenium .support .ui .ExpectedConditions .not ;
28
- import static org .openqa .selenium .support .ui .ExpectedConditions .titleIs ;
29
- import static org .openqa .selenium .testing .drivers .Browser .ALL ;
30
- import static org .openqa .selenium .testing .drivers .Browser .CHROME ;
31
- import static org .openqa .selenium .testing .drivers .Browser .EDGE ;
32
- import static org .openqa .selenium .testing .drivers .Browser .LEGACY_FIREFOX_XPI ;
33
- import static org .openqa .selenium .testing .drivers .Browser .HTMLUNIT ;
34
- import static org .openqa .selenium .testing .drivers .Browser .IE ;
35
- import static org .openqa .selenium .testing .drivers .Browser .FIREFOX ;
36
- import static org .openqa .selenium .testing .drivers .Browser .SAFARI ;
37
-
38
20
import org .junit .Test ;
39
21
import org .openqa .selenium .By ;
40
22
import org .openqa .selenium .Dimension ;
52
34
import org .openqa .selenium .testing .NotYetImplemented ;
53
35
import org .openqa .selenium .testing .SwitchToTopAfterTest ;
54
36
37
+ import static org .assertj .core .api .Assertions .assertThat ;
38
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
39
+ import static org .openqa .selenium .WaitingConditions .elementTextToEqual ;
40
+ import static org .openqa .selenium .WaitingConditions .elementValueToEqual ;
41
+ import static org .openqa .selenium .support .Colors .GREEN ;
42
+ import static org .openqa .selenium .support .Colors .RED ;
43
+ import static org .openqa .selenium .support .ui .ExpectedConditions .attributeToBe ;
44
+ import static org .openqa .selenium .support .ui .ExpectedConditions .not ;
45
+ import static org .openqa .selenium .testing .drivers .Browser .CHROME ;
46
+ import static org .openqa .selenium .testing .drivers .Browser .EDGE ;
47
+ import static org .openqa .selenium .testing .drivers .Browser .FIREFOX ;
48
+ import static org .openqa .selenium .testing .drivers .Browser .HTMLUNIT ;
49
+ import static org .openqa .selenium .testing .drivers .Browser .IE ;
50
+ import static org .openqa .selenium .testing .drivers .Browser .SAFARI ;
51
+
55
52
/**
56
53
* Tests operations that involve mouse and keyboard.
57
54
*/
58
- public class BasicMouseInterfaceTest extends JUnit4TestBase {
55
+ public class DefaultMouseTest extends JUnit4TestBase {
59
56
60
57
private Actions getBuilder (WebDriver driver ) {
61
58
return new Actions (driver );
@@ -220,77 +217,11 @@ public void testCannotMoveToANullLocator() {
220
217
}
221
218
222
219
@ Test
223
- @ Ignore (CHROME )
224
- @ Ignore (EDGE )
225
- @ Ignore (IE )
226
- @ Ignore (LEGACY_FIREFOX_XPI )
227
- @ Ignore (FIREFOX )
228
- @ NotYetImplemented (HTMLUNIT )
229
- @ NotYetImplemented (SAFARI )
230
- public void testMousePositionIsNotPreservedInActionsChain () {
231
- driver .get (pages .javascriptPage );
232
- WebElement toMoveTo = driver .findElement (By .id ("clickField" ));
233
-
234
- getBuilder (driver ).moveToElement (toMoveTo ).build ().perform ();
235
-
236
- // TODO(andreastt): Is this correct behaviour? Should the last known mouse position be
237
- // disregarded if calling click() from a an Actions chain?
238
- assertThatExceptionOfType (InvalidCoordinatesException .class )
239
- .isThrownBy (() -> getBuilder (driver ).click ().build ().perform ());
240
- }
241
-
242
- @ Test
243
- @ Ignore (value = ALL , reason = "Behaviour not finalized yet regarding linked images." )
244
- public void testMovingIntoAnImageEnclosedInALink () {
245
- driver .get (pages .linkedImage );
246
-
247
- // Note: For some reason, the Accessibility API in Firefox will not be available before we
248
- // click on something. As a work-around, click on a different element just to get going.
249
- driver .findElement (By .id ("linkToAnchorOnThisPage" )).click ();
250
-
251
- WebElement linkElement = driver .findElement (By .id ("linkWithEnclosedImage" ));
252
-
253
- // Image is 644 x 41 - move towards the end.
254
- // Note: The width of the link element itself is correct - 644 pixels. However,
255
- // the height is 17 pixels and the rectangle containing it is *below* the image.
256
- // For this reason, this action will fail.
257
- new Actions (driver ).moveToElement (linkElement , 500 , 30 ).click ().perform ();
258
-
259
- wait .until (titleIs ("We Arrive Here" ));
260
- }
261
-
262
- @ Test
263
- @ Ignore (CHROME )
264
- @ Ignore (EDGE )
265
- @ Ignore (IE )
266
- @ Ignore (LEGACY_FIREFOX_XPI )
267
- @ Ignore (FIREFOX )
268
220
@ Ignore (value = HTMLUNIT , reason ="test should enable JavaScript" )
269
221
@ NotYetImplemented (SAFARI )
270
- public void testMovingMouseBackAndForthPastViewPort () {
271
- driver .get (pages .veryLargeCanvas );
272
-
273
- WebElement firstTarget = driver .findElement (By .id ("r1" ));
274
- new Actions (driver ).moveToElement (firstTarget ).click ().perform ();
275
-
276
- WebElement resultArea = driver .findElement (By .id ("result" ));
277
- String expectedEvents = "First" ;
278
- wait .until (elementTextToEqual (resultArea , expectedEvents ));
279
-
280
- // Move to element with id 'r2', at (2500, 50) to (2580, 100)
281
- new Actions (driver ).moveByOffset (2540 - 150 , 75 - 125 ).click ().perform ();
282
- expectedEvents += " Second" ;
283
- wait .until (elementTextToEqual (resultArea , expectedEvents ));
284
-
285
- // Move to element with id 'r3' at (60, 1500) to (140, 1550)
286
- new Actions (driver ).moveByOffset (100 - 2540 , 1525 - 75 ).click ().perform ();
287
- expectedEvents += " Third" ;
288
- wait .until (elementTextToEqual (resultArea , expectedEvents ));
289
-
290
- // Move to element with id 'r4' at (220,180) to (320, 230)
291
- new Actions (driver ).moveByOffset (270 - 100 , 205 - 1525 ).click ().perform ();
292
- expectedEvents += " Fourth" ;
293
- wait .until (elementTextToEqual (resultArea , expectedEvents ));
222
+ public void testMovingPastViewPortThrowsException () {
223
+ assertThatExceptionOfType (MoveTargetOutOfBoundsException .class )
224
+ .isThrownBy (() -> getBuilder (driver ).moveByOffset (-1000 , -1000 ).perform ());
294
225
}
295
226
296
227
@ SwitchToTopAfterTest
@@ -299,7 +230,7 @@ public void testShouldClickElementInIFrame() {
299
230
driver .get (pages .clicksPage );
300
231
driver .switchTo ().frame ("source" );
301
232
WebElement element = driver .findElement (By .id ("otherframe" ));
302
- new Actions (driver ).moveToElement (element ).click ().perform ();
233
+ getBuilder (driver ).moveToElement (element ).click ().perform ();
303
234
driver .switchTo ().defaultContent ()
304
235
.switchTo ().frame ("target" );
305
236
wait .until (elementTextToEqual (By .id ("span" ), "An inline element" ));
@@ -316,7 +247,7 @@ public void testShouldAllowUsersToHoverOverElements() {
316
247
assertThat (item .getText ()).isEqualTo ("" );
317
248
318
249
((JavascriptExecutor ) driver ).executeScript ("arguments[0].style.background = 'green'" , element );
319
- new Actions (driver ).moveToElement (element ).build ().perform ();
250
+ getBuilder (driver ).moveToElement (element ).build ().perform ();
320
251
321
252
wait .until (not (elementTextToEqual (item , "" )));
322
253
assertThat (item .getText ()).isEqualTo ("Item 1" );
@@ -328,15 +259,15 @@ public void testHoverPersists() throws Exception {
328
259
driver .get (pages .javascriptPage );
329
260
// Move to a different element to make sure the mouse is not over the
330
261
// element with id 'item1' (from a previous test).
331
- new Actions (driver ).moveToElement (driver .findElement (By .id ("dynamo" ))).build ().perform ();
262
+ getBuilder (driver ).moveToElement (driver .findElement (By .id ("dynamo" ))).build ().perform ();
332
263
333
264
WebElement element = driver .findElement (By .id ("menu1" ));
334
265
335
266
final WebElement item = driver .findElement (By .id ("item1" ));
336
267
assertThat (item .getText ()).isEqualTo ("" );
337
268
338
269
((JavascriptExecutor ) driver ).executeScript ("arguments[0].style.background = 'green'" , element );
339
- new Actions (driver ).moveToElement (element ).build ().perform ();
270
+ getBuilder (driver ).moveToElement (element ).build ().perform ();
340
271
341
272
// Intentionally wait to make sure hover persists.
342
273
Thread .sleep (2000 );
@@ -352,13 +283,13 @@ public void testMovingMouseByRelativeOffset() {
352
283
driver .get (pages .mouseTrackerPage );
353
284
354
285
WebElement trackerDiv = driver .findElement (By .id ("mousetracker" ));
355
- new Actions (driver ).moveToElement (trackerDiv ).perform ();
286
+ getBuilder (driver ).moveToElement (trackerDiv ).perform ();
356
287
357
288
WebElement reporter = driver .findElement (By .id ("status" ));
358
289
359
290
wait .until (fuzzyMatchingOfCoordinates (reporter , 50 , 200 ));
360
291
361
- new Actions (driver ).moveByOffset (10 , 20 ).build ().perform ();
292
+ getBuilder (driver ).moveByOffset (10 , 20 ).build ().perform ();
362
293
363
294
wait .until (fuzzyMatchingOfCoordinates (reporter , 60 , 220 ));
364
295
}
@@ -370,7 +301,7 @@ public void testMovingMouseToRelativeElementOffset() {
370
301
371
302
WebElement trackerDiv = driver .findElement (By .id ("mousetracker" ));
372
303
Dimension size = trackerDiv .getSize ();
373
- new Actions (driver ).moveToElement (trackerDiv , 95 - size .getWidth () / 2 , 195 - size .getHeight () / 2 ).perform ();
304
+ getBuilder (driver ).moveToElement (trackerDiv , 95 - size .getWidth () / 2 , 195 - size .getHeight () / 2 ).perform ();
374
305
375
306
WebElement reporter = driver .findElement (By .id ("status" ));
376
307
@@ -383,7 +314,7 @@ public void testMovingMouseToRelativeZeroElementOffset() {
383
314
driver .get (pages .mouseTrackerPage );
384
315
385
316
WebElement trackerDiv = driver .findElement (By .id ("mousetracker" ));
386
- new Actions (driver ).moveToElement (trackerDiv , 0 , 0 ).perform ();
317
+ getBuilder (driver ).moveToElement (trackerDiv , 0 , 0 ).perform ();
387
318
388
319
WebElement reporter = driver .findElement (By .id ("status" ));
389
320
@@ -399,13 +330,13 @@ public void testMoveRelativeToBody() {
399
330
try {
400
331
driver .get (pages .mouseTrackerPage );
401
332
402
- new Actions (driver ).moveByOffset (50 , 100 ).perform ();
333
+ getBuilder (driver ).moveByOffset (50 , 100 ).perform ();
403
334
404
335
WebElement reporter = driver .findElement (By .id ("status" ));
405
336
406
337
wait .until (fuzzyMatchingOfCoordinates (reporter , 40 , 20 ));
407
338
} finally {
408
- new Actions (driver ).moveByOffset (-50 , -100 ).perform ();
339
+ getBuilder (driver ).moveByOffset (-50 , -100 ).perform ();
409
340
}
410
341
}
411
342
@@ -427,15 +358,15 @@ public void testMoveMouseByOffsetOverAndOutOfAnElement() {
427
358
int xOffset = 2 - greenBoxSize .getWidth () / 2 ;
428
359
int yOffset = 2 - greenBoxSize .getHeight () / 2 ;
429
360
430
- new Actions (driver ).moveToElement (greenbox , xOffset , yOffset ).perform ();
361
+ getBuilder (driver ).moveToElement (greenbox , xOffset , yOffset ).perform ();
431
362
432
363
shortWait .until (attributeToBe (redbox , "background-color" , Colors .GREEN .getColorValue ().asRgba ()));
433
364
434
- new Actions (driver ).moveToElement (greenbox , xOffset , yOffset )
365
+ getBuilder (driver ).moveToElement (greenbox , xOffset , yOffset )
435
366
.moveByOffset (shiftX , shiftY ).perform ();
436
367
shortWait .until (attributeToBe (redbox , "background-color" , Colors .RED .getColorValue ().asRgba ()));
437
368
438
- new Actions (driver ).moveToElement (greenbox , xOffset , yOffset )
369
+ getBuilder (driver ).moveToElement (greenbox , xOffset , yOffset )
439
370
.moveByOffset (shiftX , shiftY )
440
371
.moveByOffset (-shiftX , -shiftY ).perform ();
441
372
@@ -454,18 +385,16 @@ public void testCanMoveOverAndOutOfAnElement() {
454
385
Dimension greenSize = greenbox .getSize ();
455
386
Dimension redSize = redbox .getSize ();
456
387
457
- new Actions (driver ).moveToElement (greenbox , 1 - greenSize .getWidth () / 2 , 1 - greenSize .getHeight () / 2 ).perform ();
388
+ getBuilder (driver ).moveToElement (greenbox , 1 - greenSize .getWidth () / 2 , 1 - greenSize .getHeight () / 2 ).perform ();
458
389
459
390
assertThat (Color .fromString (redbox .getCssValue ("background-color" )))
460
391
.isEqualTo (GREEN .getColorValue ());
461
392
462
- new Actions (driver ).moveToElement (redbox ).perform ();
393
+ getBuilder (driver ).moveToElement (redbox ).perform ();
463
394
assertThat (Color .fromString (redbox .getCssValue ("background-color" )))
464
395
.isEqualTo (RED .getColorValue ());
465
396
466
- // IE8 (and *only* IE8) requires a move of 2 pixels. All other browsers
467
- // would be happy with 1.
468
- new Actions (driver ).moveToElement (redbox , redSize .getWidth () / 2 + 2 , redSize .getHeight () / 2 + 2 )
397
+ getBuilder (driver ).moveToElement (redbox , redSize .getWidth () / 1 + 1 , redSize .getHeight () / 1 + 1 )
469
398
.perform ();
470
399
471
400
wait .until (attributeToBe (redbox , "background-color" , Colors .GREEN .getColorValue ().asRgba ()));
0 commit comments