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.

TooltipTest.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2000-2013 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.tb3;
  17. import java.util.List;
  18. import java.util.NoSuchElementException;
  19. import org.junit.Assert;
  20. import org.openqa.selenium.WebElement;
  21. import org.openqa.selenium.interactions.Actions;
  22. import org.openqa.selenium.remote.DesiredCapabilities;
  23. import com.vaadin.testbench.By;
  24. /**
  25. * Base class for TestBench 3+ tests that use tooltips. This class contains
  26. * utility methods for testing tooltip use.
  27. *
  28. * @author Vaadin Ltd
  29. */
  30. public abstract class TooltipTest extends MultiBrowserTest {
  31. protected void clearTooltip() throws Exception {
  32. moveToRoot();
  33. Thread.sleep(500);
  34. checkTooltipNotPresent();
  35. }
  36. protected void checkTooltip(String locator, String value) throws Exception {
  37. checkTooltip(By.vaadin(locator), value);
  38. }
  39. protected void checkTooltip(org.openqa.selenium.By by, String value)
  40. throws Exception {
  41. checkTooltip(getDriver().findElement(by), value);
  42. }
  43. protected void checkTooltip(WebElement element, String value)
  44. throws Exception {
  45. testBenchElement(element).showTooltip();
  46. if (null != value) {
  47. checkTooltip(value);
  48. } else {
  49. checkTooltipNotPresent();
  50. }
  51. }
  52. protected void checkTooltip(String value) throws Exception {
  53. WebElement body = findElement(By.cssSelector("body"));
  54. WebElement tooltip = getTooltip();
  55. Assert.assertEquals(value, tooltip.getText());
  56. Assert.assertTrue("Tooltip overflowed to the left", tooltip
  57. .getLocation().getX() >= 0);
  58. Assert.assertTrue("Tooltip overflowed up",
  59. tooltip.getLocation().getY() >= 0);
  60. Assert.assertTrue("Tooltip overflowed to the right", tooltip
  61. .getLocation().getX() + tooltip.getSize().getWidth() < body
  62. .getSize().getWidth());
  63. Assert.assertTrue("Tooltip overflowed down", tooltip.getLocation()
  64. .getY() + tooltip.getSize().getHeight() < body.getSize()
  65. .getHeight());
  66. }
  67. protected void moveToRoot() {
  68. WebElement uiRoot = getDriver().findElement(By.vaadin("Root"));
  69. moveMouseToTopLeft(uiRoot);
  70. }
  71. protected WebElement getTooltip() throws InterruptedException {
  72. org.openqa.selenium.By tooltipBy = By.vaadin("Root/VTooltip[0]");
  73. return getDriver().findElement(tooltipBy);
  74. }
  75. protected void checkTooltipNotPresent() throws Exception {
  76. try {
  77. WebElement tooltip = getTooltip();
  78. if (!"".equals(tooltip.getText())
  79. || tooltip.getLocation().getX() > -999) {
  80. Assert.fail("Found tooltip that shouldn't be visible: "
  81. + tooltip.getText() + " at " + tooltip.getLocation());
  82. }
  83. } catch (NoSuchElementException e) {
  84. Assert.fail("Tooltip element was removed completely, causing extra events to accessibility tools");
  85. }
  86. }
  87. protected void moveMouseToTopLeft(WebElement element) {
  88. moveMouseTo(element, 0, 0);
  89. }
  90. protected void moveMouseTo(WebElement element, int offsetX, int offsetY) {
  91. new Actions(getDriver()).moveToElement(element, offsetX, offsetY)
  92. .perform();
  93. }
  94. @Override
  95. public List<DesiredCapabilities> getBrowsersToTest() {
  96. // TODO Once we figure out how to get mouse hovering work with the IE
  97. // webdriver, exclude them from these tests (#13854)
  98. return getBrowsersExcludingIE();
  99. }
  100. }