Skip to content

Commit 7638bbb

Browse files
committed
Click after move with offset should use last mouse position
1 parent 147ca73 commit 7638bbb

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.openqa.selenium.JavascriptExecutor;
4646
import org.openqa.selenium.Keys;
4747
import org.openqa.selenium.Platform;
48+
import org.openqa.selenium.Point;
4849
import org.openqa.selenium.WaitingConditions;
4950
import org.openqa.selenium.WebElement;
5051
import org.openqa.selenium.support.ui.ExpectedConditions;
@@ -218,6 +219,36 @@ public void testCanClickOnLinksWithAnOffset() {
218219
wait.until(titleIs("XHTML Test Page"));
219220
}
220221

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+
221252
/**
222253
* This test demonstrates the following problem: When the representation of
223254
* the mouse in the driver keeps the wrong state, mouse movement will end

javascript/firefox-driver/js/syntheticMouse.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ SyntheticMouse.prototype.click = function(target) {
182182
keyboardState.setPressed(bot.Device.Modifier.META, this.modifierKeys.isMetaPressed());
183183
}
184184

185-
bot.action.click(element, undefined /* coords */, new bot.Mouse(null, keyboardState));
185+
bot.action.click(element, this.lastMousePosition, new bot.Mouse(null, keyboardState));
186186

187187
this.lastElement = element;
188188

@@ -201,7 +201,7 @@ SyntheticMouse.prototype.contextClick = function(target) {
201201
}
202202

203203
fxdriver.logging.info('About to do a bot.action.rightClick on ' + element);
204-
bot.action.rightClick(element, undefined /* coords */);
204+
bot.action.rightClick(element, this.lastMousePosition);
205205

206206
this.lastElement = element;
207207

@@ -218,7 +218,7 @@ SyntheticMouse.prototype.doubleClick = function(target) {
218218
}
219219

220220
fxdriver.logging.info('About to do a bot.action.doubleClick on ' + element);
221-
bot.action.doubleClick(element, undefined /* coords */);
221+
bot.action.doubleClick(element, this.lastMousePosition);
222222

223223
this.lastElement = element;
224224

0 commit comments

Comments
 (0)