You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EmbeddedClickListenerRelativeCoordinatesTest.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.vaadin.tests.components.embedded;
  2. import org.junit.Before;
  3. import org.junit.Test;
  4. import org.openqa.selenium.By;
  5. import com.vaadin.testbench.elements.EmbeddedElement;
  6. import com.vaadin.testbench.elements.LabelElement;
  7. import com.vaadin.testbench.parallel.BrowserUtil;
  8. import com.vaadin.tests.tb3.MultiBrowserTest;
  9. import static org.junit.Assert.assertEquals;
  10. public class EmbeddedClickListenerRelativeCoordinatesTest
  11. extends MultiBrowserTest {
  12. @Before
  13. @Override
  14. public void setup() throws Exception {
  15. super.setup();
  16. openTestURL();
  17. waitForElementPresent(By.className("v-embedded"));
  18. }
  19. @Test
  20. public void testRelativeClick() {
  21. clickAt(41, 22);
  22. checkLocation(41, 22);
  23. clickAt(1, 1);
  24. checkLocation(1, 1);
  25. }
  26. private void clickAt(int x, int y) {
  27. EmbeddedElement embedded = $(EmbeddedElement.class).first();
  28. embedded.click(getXOffset(embedded, x), getYOffset(embedded, y));
  29. }
  30. private void checkLocation(int expectedX, int expectedY) {
  31. LabelElement xLabel = $(LabelElement.class).id("x");
  32. LabelElement yLabel = $(LabelElement.class).id("y");
  33. int x = Integer.parseInt(xLabel.getText());
  34. int y = Integer.parseInt(yLabel.getText());
  35. assertEquals(
  36. "Reported X-coordinate from Embedded does not match click location",
  37. expectedX, x);
  38. // IE10 and IE11 sometimes click one pixel below the given position,
  39. // so does the Chrome(since 75)
  40. int tolerance;
  41. if (isIE() || isChrome()) {
  42. tolerance = 1;
  43. } else {
  44. tolerance = 0;
  45. }
  46. assertEquals(
  47. "Reported Y-coordinate from Embedded does not match click location",
  48. expectedY, y, tolerance);
  49. }
  50. private boolean isIE() {
  51. return BrowserUtil.isIE(getDesiredCapabilities());
  52. }
  53. private boolean isChrome() {
  54. return BrowserUtil.isChrome(getDesiredCapabilities());
  55. }
  56. }