|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.interactions;
|
19 | 19 |
|
| 20 | +import org.assertj.core.api.Assertions; |
20 | 21 | import org.junit.Test;
|
21 | 22 | import org.openqa.selenium.By;
|
22 | 23 | import org.openqa.selenium.Dimension;
|
23 | 24 | import org.openqa.selenium.JavascriptExecutor;
|
24 | 25 | import org.openqa.selenium.NoSuchElementException;
|
25 | 26 | import org.openqa.selenium.Point;
|
| 27 | +import org.openqa.selenium.Rectangle; |
26 | 28 | import org.openqa.selenium.WebDriver;
|
27 | 29 | import org.openqa.selenium.WebElement;
|
28 | 30 | import org.openqa.selenium.remote.RemoteWebDriver;
|
|
36 | 38 | import org.openqa.selenium.testing.SwitchToTopAfterTest;
|
37 | 39 |
|
38 | 40 | import java.time.Duration;
|
| 41 | +import java.util.Arrays; |
39 | 42 | import java.util.Collections;
|
| 43 | +import java.util.List; |
| 44 | +import java.util.Map; |
| 45 | +import java.util.stream.Collectors; |
40 | 46 |
|
41 | 47 | import static org.assertj.core.api.Assertions.assertThat;
|
42 | 48 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
@@ -371,6 +377,70 @@ public void testCanMoveOverAndOutOfAnElement() {
|
371 | 377 | wait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba()));
|
372 | 378 | }
|
373 | 379 |
|
| 380 | + @Test |
| 381 | + @Ignore(value = FIREFOX, issue = "https://github.com/mozilla/geckodriver/issues/789") |
| 382 | + public void setPointerEventProperties() { |
| 383 | + driver.get(pages.pointerActionsPage); |
| 384 | + long start = System.currentTimeMillis(); |
| 385 | + |
| 386 | + WebElement pointerArea = driver.findElement(By.id("pointerArea")); |
| 387 | + PointerInput pen = new PointerInput(PointerInput.Kind.PEN, "default pen"); |
| 388 | + PointerInput.PointerEventProperties eventProperties = PointerInput.eventProperties() |
| 389 | + .setTiltX(-72) |
| 390 | + .setTiltY(9) |
| 391 | + .setTwist(86); |
| 392 | + PointerInput.Origin origin = PointerInput.Origin.fromElement(pointerArea); |
| 393 | + |
| 394 | + Sequence actionListPen = new Sequence(pen, 0) |
| 395 | + .addAction(pen.createPointerMove(Duration.ZERO, origin, 0, 0)) |
| 396 | + .addAction(pen.createPointerDown(0)) |
| 397 | + .addAction(pen.createPointerMove(Duration.ofMillis(800), origin, 2, 2, eventProperties)) |
| 398 | + .addAction(pen.createPointerUp(0)); |
| 399 | + |
| 400 | + ((RemoteWebDriver) driver).perform(List.of(actionListPen)); |
| 401 | + |
| 402 | + long duration = System.currentTimeMillis() - start; |
| 403 | + Assertions.assertThat(duration).isGreaterThan(2); |
| 404 | + |
| 405 | + List<WebElement> moves = driver.findElements(By.className("pointermove")); |
| 406 | + Map<String, String> moveTo = properties(moves.get(0)); |
| 407 | + Map<String, String> down = properties(driver.findElement(By.className("pointerdown"))); |
| 408 | + Map<String, String> moveBy = properties(moves.get(1)); |
| 409 | + Map<String, String> up = properties(driver.findElement(By.className("pointerup"))); |
| 410 | + |
| 411 | + Rectangle rect = pointerArea.getRect(); |
| 412 | + |
| 413 | + int centerX = (int) Math.floor(rect.width / 2 + rect.getX()); |
| 414 | + int centerY = (int) Math.floor(rect.height / 2 + rect.getY()); |
| 415 | + Assertions.assertThat(moveTo.get("button")).isEqualTo("-1"); |
| 416 | + Assertions.assertThat(moveTo.get("pageX")).isEqualTo("" + centerX); |
| 417 | + Assertions.assertThat(moveTo.get("pageY")).isEqualTo("" + centerY); |
| 418 | + Assertions.assertThat(down.get("button")).isEqualTo("0"); |
| 419 | + Assertions.assertThat(down.get("pageX")).isEqualTo("" + centerX); |
| 420 | + Assertions.assertThat(down.get("pageY")).isEqualTo("" + centerY); |
| 421 | + Assertions.assertThat(moveBy.get("button")).isEqualTo("-1"); |
| 422 | + Assertions.assertThat(moveBy.get("pageX")).isEqualTo("" + (centerX + 2)); |
| 423 | + Assertions.assertThat(moveBy.get("pageY")).isEqualTo("" + (centerY + 2)); |
| 424 | + Assertions.assertThat(moveBy.get("tiltX")).isEqualTo("-72"); |
| 425 | + Assertions.assertThat(moveBy.get("tiltY")).isEqualTo("9"); |
| 426 | + Assertions.assertThat(moveBy.get("twist")).isEqualTo("86"); |
| 427 | + Assertions.assertThat(up.get("button")).isEqualTo("0"); |
| 428 | + Assertions.assertThat(up.get("pageX")).isEqualTo("" + (centerX + 2)); |
| 429 | + Assertions.assertThat(up.get("pageY")).isEqualTo("" + (centerY + 2)); |
| 430 | + } |
| 431 | + |
| 432 | + private Map<String, String> properties(WebElement element) { |
| 433 | + String text = element.getText(); |
| 434 | + text = text.substring(text.indexOf(' ') + 1); |
| 435 | + |
| 436 | + return Arrays.stream(text.split(", ")) |
| 437 | + .map(s -> s.split(": ")) |
| 438 | + .collect(Collectors.toMap( |
| 439 | + a -> a[0], //key |
| 440 | + a -> a[1] //value |
| 441 | + )); |
| 442 | + } |
| 443 | + |
374 | 444 | private boolean fuzzyPositionMatching(int expectedX, int expectedY, String locationTuple) {
|
375 | 445 | String[] splitString = locationTuple.split(",");
|
376 | 446 | int gotX = Integer.parseInt(splitString[0].trim());
|
|
0 commit comments