123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package com.vaadin.tests.tb3;
-
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertTrue;
- import static org.junit.Assert.fail;
-
- import java.util.List;
- import java.util.NoSuchElementException;
-
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.interactions.Actions;
- import org.openqa.selenium.remote.DesiredCapabilities;
-
- import com.vaadin.testbench.By;
-
- /**
- * Base class for TestBench 3+ tests that use tooltips. This class contains
- * utility methods for testing tooltip use.
- *
- * @author Vaadin Ltd
- */
- public abstract class TooltipTest extends MultiBrowserTest {
-
- protected void clearTooltip() throws Exception {
- moveToRoot();
- Thread.sleep(500);
- checkTooltipNotPresent();
- }
-
- protected void checkTooltip(String locator, String value) throws Exception {
- checkTooltip(By.vaadin(locator), value);
- }
-
- protected void checkTooltip(org.openqa.selenium.By by, String value)
- throws Exception {
- checkTooltip(getDriver().findElement(by), value);
- }
-
- protected void checkTooltip(WebElement element, String value)
- throws Exception {
- testBenchElement(element).showTooltip();
- if (null != value) {
- checkTooltip(value);
- } else {
- checkTooltipNotPresent();
- }
- }
-
- protected void checkTooltip(String value) throws Exception {
- WebElement body = findElement(By.cssSelector("body"));
- WebElement tooltip = getTooltip();
- assertEquals(value, tooltip.getText());
- assertTrue("Tooltip overflowed to the left",
- tooltip.getLocation().getX() >= 0);
- assertTrue("Tooltip overflowed up", tooltip.getLocation().getY() >= 0);
- assertTrue("Tooltip overflowed to the right",
- tooltip.getLocation().getX()
- + tooltip.getSize().getWidth() < body.getSize()
- .getWidth());
- assertTrue("Tooltip overflowed down", tooltip.getLocation().getY()
- + tooltip.getSize().getHeight() < body.getSize().getHeight());
-
- }
-
- protected void moveToRoot() {
- WebElement uiRoot = getDriver().findElement(By.vaadin("Root"));
- moveMouseToTopLeft(uiRoot);
- }
-
- protected WebElement getTooltip() throws InterruptedException {
- org.openqa.selenium.By tooltipBy = By.vaadin("Root/VTooltip[0]");
- return getDriver().findElement(tooltipBy);
- }
-
- protected void checkTooltipNotPresent() throws Exception {
- try {
- WebElement tooltip = getTooltip();
- if (!tooltip.getText().isEmpty()
- || tooltip.getLocation().getX() > -999) {
- fail("Found tooltip that shouldn't be visible: "
- + tooltip.getText() + " at " + tooltip.getLocation());
- }
- } catch (NoSuchElementException e) {
- fail("Tooltip element was removed completely, causing extra events to accessibility tools");
- }
- }
-
- protected void moveMouseToTopLeft(WebElement element) {
- moveMouseTo(element, 0, 0);
- }
-
- protected void moveMouseTo(WebElement element, int offsetX, int offsetY) {
- new Actions(getDriver()).moveToElement(element,
- getXOffset(element, offsetX), getYOffset(element, offsetY))
- .perform();
- }
-
- @Override
- public List<DesiredCapabilities> getBrowsersToTest() {
- return getBrowsersSupportingTooltip();
- }
- }
|