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 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.notification;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import org.openqa.selenium.Point;
  20. import org.openqa.selenium.WebElement;
  21. import com.vaadin.testbench.By;
  22. import com.vaadin.tests.tb3.MultiBrowserTest;
  23. /**
  24. * Unit test class for Notification with middle left and middle right positions.
  25. *
  26. * @since 7.2
  27. * @author Vaadin Ltd
  28. */
  29. public class MiddleNotificationPositionTest extends MultiBrowserTest {
  30. @Test
  31. public void testMiddleLeft() {
  32. openTestURL();
  33. WebElement webElement = driver.findElement(By
  34. .className("show-middle-left"));
  35. webElement.click();
  36. WebElement notification = driver.findElement(By
  37. .className("v-Notification"));
  38. Assert.assertNotNull(notification);
  39. String left = notification.getCssValue("left");
  40. Assert.assertEquals(
  41. "Left position of notification element should be 0px", "0px",
  42. left);
  43. Point location = notification.getLocation();
  44. Assert.assertEquals("X coordinate of notifiation element should be 0",
  45. 0, location.getX());
  46. WebElement body = driver.findElement(By.tagName("body"));
  47. int height = body.getSize().height;
  48. Assert.assertTrue("Y coordinate of notification element is too small",
  49. height / 2 - notification.getSize().height / 2 - 1 <= location
  50. .getY());
  51. Assert.assertTrue("Y coordinate of notification element is too big",
  52. height / 2 + 1 >= location.getY());
  53. }
  54. @Test
  55. public void testMiddleRight() {
  56. openTestURL();
  57. WebElement webElement = driver.findElement(By
  58. .className("show-middle-right"));
  59. webElement.click();
  60. WebElement notification = driver.findElement(By
  61. .className("v-Notification"));
  62. Assert.assertNotNull(notification);
  63. String right = notification.getCssValue("right");
  64. Assert.assertEquals(
  65. "Right position of notification element should be 0px", "0px",
  66. right);
  67. WebElement body = driver.findElement(By.tagName("body"));
  68. int height = body.getSize().height;
  69. int width = body.getSize().width;
  70. Point location = notification.getLocation();
  71. Assert.assertTrue(
  72. "Notification right border should be in the rightmost position",
  73. width - 1 <= location.getX()
  74. + notification.getSize().getWidth());
  75. Assert.assertTrue("Y coordinate of notification element is too small",
  76. height / 2 - notification.getSize().height / 2 - 1 <= location
  77. .getY());
  78. Assert.assertTrue("Y coordinate of notification element is too big",
  79. height / 2 + 1 >= location.getY());
  80. }
  81. }