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.

MiddleNotificationPositionTest.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.vaadin.tests.components.notification;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertNotNull;
  4. import static org.junit.Assert.assertTrue;
  5. import org.junit.Test;
  6. import org.openqa.selenium.Point;
  7. import org.openqa.selenium.WebElement;
  8. import com.vaadin.testbench.By;
  9. import com.vaadin.tests.tb3.MultiBrowserTest;
  10. /**
  11. * Unit test class for Notification with middle left and middle right positions.
  12. *
  13. * @since 7.2
  14. * @author Vaadin Ltd
  15. */
  16. public class MiddleNotificationPositionTest extends MultiBrowserTest {
  17. @Test
  18. public void testMiddleLeft() {
  19. openTestURL();
  20. WebElement webElement = driver
  21. .findElement(By.className("show-middle-left"));
  22. webElement.click();
  23. WebElement notification = driver
  24. .findElement(By.className("v-Notification"));
  25. assertNotNull(notification);
  26. String left = notification.getCssValue("left");
  27. assertEquals("Left position of notification element should be 0px",
  28. "0px", left);
  29. Point location = notification.getLocation();
  30. assertEquals("X coordinate of notifiation element should be 0", 0,
  31. location.getX());
  32. WebElement body = driver.findElement(By.tagName("body"));
  33. int height = body.getSize().height;
  34. assertTrue("Y coordinate of notification element is too small",
  35. height / 2 - notification.getSize().height / 2 - 1 <= location
  36. .getY());
  37. assertTrue("Y coordinate of notification element is too big",
  38. height / 2 + 1 >= location.getY());
  39. }
  40. @Test
  41. public void testMiddleRight() {
  42. openTestURL();
  43. WebElement webElement = driver
  44. .findElement(By.className("show-middle-right"));
  45. webElement.click();
  46. WebElement notification = driver
  47. .findElement(By.className("v-Notification"));
  48. assertNotNull(notification);
  49. String right = notification.getCssValue("right");
  50. assertEquals("Right position of notification element should be 0px",
  51. "0px", right);
  52. WebElement body = driver.findElement(By.tagName("body"));
  53. int height = body.getSize().height;
  54. int width = body.getSize().width;
  55. Point location = notification.getLocation();
  56. assertTrue(
  57. "Notification right border should be in the rightmost position",
  58. width - 1 <= location.getX()
  59. + notification.getSize().getWidth());
  60. assertTrue("Y coordinate of notification element is too small",
  61. height / 2 - notification.getSize().height / 2 - 1 <= location
  62. .getY());
  63. assertTrue("Y coordinate of notification element is too big",
  64. height / 2 + 1 >= location.getY());
  65. }
  66. }