|
45 | 45 | import org.openqa.selenium.JavascriptExecutor;
|
46 | 46 | import org.openqa.selenium.Keys;
|
47 | 47 | import org.openqa.selenium.Platform;
|
| 48 | +import org.openqa.selenium.Point; |
48 | 49 | import org.openqa.selenium.WaitingConditions;
|
49 | 50 | import org.openqa.selenium.WebElement;
|
50 | 51 | import org.openqa.selenium.support.ui.ExpectedConditions;
|
@@ -218,6 +219,36 @@ public void testCanClickOnLinksWithAnOffset() {
|
218 | 219 | wait.until(titleIs("XHTML Test Page"));
|
219 | 220 | }
|
220 | 221 |
|
| 222 | + @Ignore( |
| 223 | + value = {HTMLUNIT, IPHONE}, |
| 224 | + reason = "HtmlUnit: Advanced mouse actions only implemented in rendered browsers") |
| 225 | + @Test |
| 226 | + public void testClickAfterMoveToAnElementWithAnOffsetShouldUseLastMousePosition() { |
| 227 | + assumeFalse(isFirefox(driver) && isNativeEventsEnabled(driver)); |
| 228 | + |
| 229 | + driver.get(pages.clickEventPage); |
| 230 | + |
| 231 | + WebElement element = driver.findElement(By.id("eventish")); |
| 232 | + Point location = element.getLocation(); |
| 233 | + |
| 234 | + new Actions(driver) |
| 235 | + .moveToElement(element, 10, 20) |
| 236 | + .click() |
| 237 | + .perform(); |
| 238 | + |
| 239 | + int x = Integer.parseInt(driver.findElement(By.id("pageX")).getText()); |
| 240 | + int y = Integer.parseInt(driver.findElement(By.id("pageY")).getText()); |
| 241 | + |
| 242 | + assertTrue(fuzzyPositionMatching(location.getX() + 10, location.getY() + 20, x, y)); |
| 243 | + } |
| 244 | + |
| 245 | + private boolean fuzzyPositionMatching(int expectedX, int expectedY, int actualX, int actualY) { |
| 246 | + // Everything within 5 pixels range is OK |
| 247 | + final int ALLOWED_DEVIATION = 5; |
| 248 | + return Math.abs(expectedX - actualX) < ALLOWED_DEVIATION && |
| 249 | + Math.abs(expectedY - actualY) < ALLOWED_DEVIATION; |
| 250 | + } |
| 251 | + |
221 | 252 | /**
|
222 | 253 | * This test demonstrates the following problem: When the representation of
|
223 | 254 | * the mouse in the driver keeps the wrong state, mouse movement will end
|
|
0 commit comments