Skip to content

Commit 4108c6f

Browse files
committed
Resorting tests for moveByOffset action
1 parent 0807842 commit 4108c6f

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

java/client/test/org/openqa/selenium/interactions/BasicMouseInterfaceTest.java

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.openqa.selenium.NoDriverAfterTest;
4848
import org.openqa.selenium.NoSuchElementException;
4949
import org.openqa.selenium.Platform;
50+
import org.openqa.selenium.Point;
5051
import org.openqa.selenium.WebDriver;
5152
import org.openqa.selenium.WebElement;
5253
import org.openqa.selenium.support.Color;
@@ -311,43 +312,6 @@ private int getFieldValue(Map<String, Object> sizeRect, String fieldName) {
311312
return (int) Double.parseDouble(sizeRect.get(fieldName).toString());
312313
}
313314

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-
351315
@Ignore(value = {IE, CHROME}, reason = "Not implemented yet.")
352316
@NotYetImplemented(HTMLUNIT)
353317
@Test
@@ -523,14 +487,49 @@ public void testMoveRelativeToBody() {
523487
}
524488
}
525489

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+
526525
@JavascriptEnabled
527526
@Test
528527
@Ignore(value = {SAFARI, MARIONETTE},
529528
reason = "Advanced mouse actions only implemented in rendered browsers",
530529
issues = {4136})
531530
@NotYetImplemented(HTMLUNIT)
532531
@NoDriverAfterTest
533-
public void canMouseOverAndOutOfAnElement() {
532+
public void testCanMoveOverAndOutOfAnElement() {
534533
driver.get(pages.mouseOverPage);
535534

536535
WebElement greenbox = driver.findElement(By.id("greenbox"));

0 commit comments

Comments
 (0)