Search in sources :

Example 71 with WebDriver

use of org.openqa.selenium.WebDriver in project rstudio by rstudio.

the class MenuNavigator method getMenuItem.

public static WebElement getMenuItem(final WebDriver driver, String level1, String level2, String level3) {
    WebElement popupItem = getMenuItem(driver, level1, level2);
    Actions action = new Actions(driver);
    action.moveToElement(popupItem).build().perform();
    // Wait for there to be two popups open (the level1 and level2 menus)
    (new WebDriverWait(driver, 1)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {
            List<WebElement> elements = driver.findElements(By.className("gwt-MenuBarPopup"));
            return elements.size() > 1;
        }
    });
    // Get the second popup menu
    List<WebElement> elements = driver.findElements(By.className("gwt-MenuBarPopup"));
    WebElement menu2popup = elements.get(1);
    return findMenuItemByName(menu2popup, level3);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Actions(org.openqa.selenium.interactions.Actions) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) List(java.util.List) WebElement(org.openqa.selenium.WebElement)

Example 72 with WebDriver

use of org.openqa.selenium.WebDriver in project ats-framework by Axway.

the class AbstractRealBrowserDriver method waitForPageLoaded.

public void waitForPageLoaded(WebDriver driver, int timeoutInSeconds) {
    /*InternetExplorer is unable to wait for document's readyState to be complete.*/
    if (this instanceof com.axway.ats.uiengine.InternetExplorerDriver) {
        return;
    }
    ExpectedCondition<Boolean> expectation = new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver driver) {
            return "complete".equals(((JavascriptExecutor) driver).executeScript("return document.readyState"));
        }
    };
    Wait<WebDriver> wait = new WebDriverWait(driver, timeoutInSeconds);
    try {
        wait.until(expectation);
    } catch (Exception e) {
        throw new SeleniumOperationException("Timeout waiting for Page Load Request to complete.", e);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException)

Example 73 with WebDriver

use of org.openqa.selenium.WebDriver in project ats-framework by Axway.

the class HiddenHtmlElementLocator method findElement.

public static HtmlUnitWebElement findElement(UiElement uiElement, String xpathSuffix, boolean verbose) {
    HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiElement.getUiDriver();
    WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
    HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement);
    String xpath = uiElement.getElementProperties().getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);
    String css = uiElement.getElementProperty("_css");
    if (xpathSuffix != null) {
        xpath += xpathSuffix;
    }
    List<WebElement> elements = null;
    if (!StringUtils.isNullOrEmpty(css)) {
        elements = webDriver.findElements(By.cssSelector(css));
    } else {
        elements = webDriver.findElements(By.xpath(xpath));
    }
    if (elements.size() == 0) {
        throw new ElementNotFoundException(uiElement.toString() + " not found.");
    } else if (elements.size() > 1) {
        if (verbose) {
            log.warn("More than one HTML elements were found having properties " + uiElement.toString() + ".Only the first HTML element will be used.");
        }
    }
    HtmlUnitWebElement element = (HtmlUnitWebElement) elements.get(0);
    if (verbose) {
        log.info("Found element: " + element.toString());
    }
    return element;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HiddenBrowserDriver(com.axway.ats.uiengine.HiddenBrowserDriver) HtmlUnitWebElement(org.openqa.selenium.htmlunit.HtmlUnitWebElement) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) WebElement(org.openqa.selenium.WebElement) HtmlUnitWebElement(org.openqa.selenium.htmlunit.HtmlUnitWebElement)

Example 74 with WebDriver

use of org.openqa.selenium.WebDriver in project ats-framework by Axway.

the class RealHtmlElementLocator method findElement.

public static WebElement findElement(UiElement uiElement, String xpathSuffix, boolean verbose) {
    AbstractRealBrowserDriver browserDriver = (AbstractRealBrowserDriver) uiElement.getUiDriver();
    WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
    HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement);
    String xpath = uiElement.getElementProperties().getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);
    String css = uiElement.getElementProperty("_css");
    if (xpathSuffix != null) {
        xpath += xpathSuffix;
    }
    List<WebElement> elements = null;
    if (!StringUtils.isNullOrEmpty(css)) {
        elements = webDriver.findElements(By.cssSelector(css));
    } else {
        elements = webDriver.findElements(By.xpath(xpath));
    }
    if (elements.size() == 0) {
        throw new ElementNotFoundException(uiElement.toString() + " not found.");
    } else if (elements.size() > 1) {
        if (verbose) {
            log.warn("More than one HTML elements were found having properties " + uiElement.toString() + ".Only the first HTML element will be used.");
        }
    }
    WebElement element = (WebElement) elements.get(0);
    if (verbose) {
        log.debug("Found element: " + element.toString());
    }
    return element;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) AbstractRealBrowserDriver(com.axway.ats.uiengine.AbstractRealBrowserDriver) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) WebElement(org.openqa.selenium.WebElement)

Example 75 with WebDriver

use of org.openqa.selenium.WebDriver in project geode by apache.

the class ScreenshotOnFailureRule method takeScreenshot.

private void takeScreenshot(String screenshotName) {
    WebDriver driver = this.webDriverSupplier.get();
    if (driver instanceof TakesScreenshot) {
        File tempFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        try {
            File screenshot = new File("build/screenshots/" + screenshotName + ".png");
            FileUtils.copyFile(tempFile, screenshot);
            System.err.println("Screenshot saved to: " + screenshot.getCanonicalPath());
        } catch (IOException e) {
            throw new Error(e);
        }
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) IOException(java.io.IOException) File(java.io.File) TakesScreenshot(org.openqa.selenium.TakesScreenshot)

Aggregations

WebDriver (org.openqa.selenium.WebDriver)167 WebElement (org.openqa.selenium.WebElement)87 Test (org.junit.Test)61 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)59 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)40 Actions (org.openqa.selenium.interactions.Actions)25 IOException (java.io.IOException)12 Cookie (org.openqa.selenium.Cookie)11 List (java.util.List)10 File (java.io.File)9 HttpRequestCallback (ghostdriver.server.HttpRequestCallback)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)8 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)7 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)7 By (org.openqa.selenium.By)5 Dimension (org.openqa.selenium.Dimension)5 Predicate (com.google.common.base.Predicate)4 TimeoutException (org.openqa.selenium.TimeoutException)4