|
47 | 47 | import org.openqa.selenium.NoDriverAfterTest;
|
48 | 48 | import org.openqa.selenium.NoSuchElementException;
|
49 | 49 | import org.openqa.selenium.Platform;
|
| 50 | +import org.openqa.selenium.Point; |
50 | 51 | import org.openqa.selenium.WebDriver;
|
51 | 52 | import org.openqa.selenium.WebElement;
|
52 | 53 | import org.openqa.selenium.support.Color;
|
@@ -311,43 +312,6 @@ private int getFieldValue(Map<String, Object> sizeRect, String fieldName) {
|
311 | 312 | return (int) Double.parseDouble(sizeRect.get(fieldName).toString());
|
312 | 313 | }
|
313 | 314 |
|
314 |
| - @Ignore(value = {IE, CHROME}, |
315 |
| - reason = "Not implemented yet.") |
316 |
| - @NotYetImplemented(HTMLUNIT) |
317 |
| - @Test |
318 |
| - public void testMovingMousePastViewPort() { |
319 |
| - assumeTrue(isNativeEventsEnabled(driver)); |
320 |
| - |
321 |
| - driver.get(pages.javascriptPage); |
322 |
| - |
323 |
| - WebElement keyUpArea = driver.findElement(By.id("keyPressArea")); |
324 |
| - new Actions(driver).moveToElement(keyUpArea).click().perform(); |
325 |
| - |
326 |
| - Map<String, Object> keyUpSize = getElementSize(keyUpArea); |
327 |
| - |
328 |
| - // When moving to an element using the interactions API, the element is not scrolled |
329 |
| - // using scrollElementIntoView so the top of the element may not end at 0. |
330 |
| - // Estimate the mouse position based on the distance of the element from the top plus |
331 |
| - // half its size (the mouse is moved to the middle of the element by default). |
332 |
| - int assumedMouseY = getHeight(keyUpSize) / 2 + getFieldValue(keyUpSize, "top"); |
333 |
| - |
334 |
| - // Calculate the scroll offset by figuring out the distance of the 'parent' element from |
335 |
| - // the top (adding half it's height), then substracting the current mouse position. |
336 |
| - // Regarding width, the event attached to this element will only be triggered if the mouse |
337 |
| - // hovers over the text in this element. Use a simple negative offset for this. |
338 |
| - Map<String, Object> parentSize = getElementSize(driver.findElement(By.id("parent"))); |
339 |
| - |
340 |
| - int verticalMove = getFieldValue(parentSize, "top") + getHeight(parentSize) / 2 - |
341 |
| - assumedMouseY; |
342 |
| - |
343 |
| - // Move by verticalMove pixels down and -50 pixels left: |
344 |
| - // we should be hitting the element with id 'parent' |
345 |
| - new Actions(driver).moveByOffset(-50, verticalMove).perform(); |
346 |
| - |
347 |
| - WebElement resultArea = driver.findElement(By.id("result")); |
348 |
| - wait.until(elementTextToContain(resultArea, "parent matches")); |
349 |
| - } |
350 |
| - |
351 | 315 | @Ignore(value = {IE, CHROME}, reason = "Not implemented yet.")
|
352 | 316 | @NotYetImplemented(HTMLUNIT)
|
353 | 317 | @Test
|
@@ -523,14 +487,49 @@ public void testMoveRelativeToBody() {
|
523 | 487 | }
|
524 | 488 | }
|
525 | 489 |
|
| 490 | + @JavascriptEnabled |
| 491 | + @Test |
| 492 | + @Ignore(value = {SAFARI, MARIONETTE}, |
| 493 | + reason = "Advanced mouse actions only implemented in rendered browsers", |
| 494 | + issues = {4136}) |
| 495 | + @NotYetImplemented(HTMLUNIT) |
| 496 | + //@NoDriverAfterTest |
| 497 | + public void testMoveMouseByOffsetOverAndOutOfAnElement() { |
| 498 | + driver.get(pages.mouseOverPage); |
| 499 | + |
| 500 | + WebElement greenbox = driver.findElement(By.id("greenbox")); |
| 501 | + WebElement redbox = driver.findElement(By.id("redbox")); |
| 502 | + Dimension size = redbox.getSize(); |
| 503 | + Point greenboxPosition = greenbox.getLocation(); |
| 504 | + Point redboxPosition = redbox.getLocation(); |
| 505 | + int shiftX = redboxPosition.getX() - greenboxPosition.getX(); |
| 506 | + int shiftY = redboxPosition.getY() - greenboxPosition.getY(); |
| 507 | + |
| 508 | + new Actions(driver).moveToElement(greenbox, 2, 2).perform(); |
| 509 | + |
| 510 | + assertEquals( |
| 511 | + Colors.GREEN.getColorValue(), Color.fromString(redbox.getCssValue("background-color"))); |
| 512 | + |
| 513 | + new Actions(driver).moveToElement(greenbox, 2, 2) |
| 514 | + .moveByOffset(shiftX, shiftY).perform(); |
| 515 | + assertEquals( |
| 516 | + Colors.RED.getColorValue(), Color.fromString(redbox.getCssValue("background-color"))); |
| 517 | + |
| 518 | + new Actions(driver).moveToElement(greenbox, 2, 2) |
| 519 | + .moveByOffset(shiftX, shiftY) |
| 520 | + .moveByOffset(-shiftX, -shiftY).perform(); |
| 521 | + assertEquals( |
| 522 | + Colors.GREEN.getColorValue(), Color.fromString(redbox.getCssValue("background-color"))); |
| 523 | + } |
| 524 | + |
526 | 525 | @JavascriptEnabled
|
527 | 526 | @Test
|
528 | 527 | @Ignore(value = {SAFARI, MARIONETTE},
|
529 | 528 | reason = "Advanced mouse actions only implemented in rendered browsers",
|
530 | 529 | issues = {4136})
|
531 | 530 | @NotYetImplemented(HTMLUNIT)
|
532 | 531 | @NoDriverAfterTest
|
533 |
| - public void canMouseOverAndOutOfAnElement() { |
| 532 | + public void testCanMoveOverAndOutOfAnElement() { |
534 | 533 | driver.get(pages.mouseOverPage);
|
535 | 534 |
|
536 | 535 | WebElement greenbox = driver.findElement(By.id("greenbox"));
|
|
0 commit comments