Example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait.

Prototype

public WebDriverWait(WebDriver driver, Duration timeout) 

Source Link

Document

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Usage

From source file:com.booleanworks.kryptopterus.selenium.testsuite001.BaseWelcomePageTest.java

@Test
@Ignore/*from   w w  w . ja  v a2 s  . co  m*/
public void testSimple() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("phantomjs.page.settings.userAgent",
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36");
    capabilities.setCapability("phantomjs.page.settings.localToRemoteUrlAccessEnabled", true);
    capabilities.setCapability("phantomjs.page.settings.browserConnectionEnabled", true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
            "/usr/local/bin/phantomjs");
    capabilities.setCapability("takesScreenshot", true);

    WebDriver driver = new PhantomJSDriver((Capabilities) capabilities);
    driver.manage().window().setSize(new Dimension(1200, 800));
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

    // And now use this to visit NetBeans
    driver.get("http://localhost:8084/kryptopterus/");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.netbeans.org");

    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("NetBeans");
        }
    });

    //Close the browser
    driver.quit();
}

From source file:com.capgemini.scripts.Circuit.java

public void executeTestcase(String browserName) throws Exception {
    int iNumberOfRows = 0;
    readExcel.setInputFile(System.getProperty("File"));
    readExcel1.setInputFile(System.getProperty("ObjFile"));
    readExcel.setSheetName(TestCase);/*w  w  w  .ja  v  a2 s  . c  o m*/
    readExcel1.setSheetName(TestCase);
    DataMap = readExcel.loadDataMap();
    iNumberOfRows = readExcel.getiNOfRows();

    reporter.start(reporter.calendar);
    StrExecutionStartTime = reporter.strStartTime;
    executionStartTime = reporter.startTime;

    reporter.ReportGenerator("Cafe#" + browserName);
    for (int i = 1; i <= iNumberOfRows; i++) {
        webDriver = BaseDrivers.getWebDriver();
        wait = new WebDriverWait(webDriver, 10);
        readExcel.setDataMap(DataMap);
        readExcel.readByIndex(i);
        System.out.println(capabilities.getBrowserName());
        reporter.setStrBrowser(capabilities.getBrowserName());

        reporter.addIterator(i);
        objDataMap = (Map<String, String>) readExcel.readPropertyFile();

        Login();
        testcaseMain();

        if (!BasicOperation.FailCase)
            main1.printMessage(TestCase, Integer.parseInt(DataMap.get("index")),
                    "script executed successfully!");
        else
            main1.printMessage(TestCase, Integer.parseInt(DataMap.get("index")), "script execution fail!");

        //NextFunctionCall
        //WriteMaster.updateNextURL(TestCase,webDriver.getCurrentUrl());
        reporter.closeIterator();
        System.out.println("\t \t \t \t \t Row number: " + i);
        //   webDriver.close();
    }
    String strStopTime = reporter.stop();
    reporter.strStopTime = strStopTime;
    float timeElapsed = reporter.getElapsedTime();
    reporter.timeElapsed = timeElapsed;
    reporter.CreateSummary("Cafe#" + browserName);
    main1.final_result(TestCase, reporter);

}

From source file:com.ceiwc.compugain.setup.TestBase.java

public void logout(WebDriver driver) {
    try {//from w w  w .ja v  a2  s. c o  m
        if (driver.findElement(By.xpath("//div[@id='account']/a/span")).isDisplayed()) {
            WebDriverWait driverwait = new WebDriverWait(driver, 60);
            driver.findElement(By.xpath("//div[@id='account']/a/span")).click();
            driverwait.until(
                    ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class='glyphicons power']")));
            driver.findElement(By.xpath("//*[@class='glyphicons power']")).click();
            driverwait.until(
                    ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='password']/input")));
        }
    } catch (Exception e) {
        logger.info("Logout button is not found!!!!!");
    }
}

From source file:com.cengage.mindtap.keywords.BasePageActions.java

public void waitForDomToLoad() {
    WebDriverWait wait = new WebDriverWait(driver, 80);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*")));
}

From source file:com.cengage.mindtap.keywords.BasePageActions.java

public void switchToFrame(String stf) {
    WebDriverWait wait = new WebDriverWait(driver, 120);
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(stf));
}

From source file:com.cengage.mtx.keywords.MTXGradebookScoreVerificationPageAction.java

public WebElement getWhenVisible(By locator, int timeout) {
    WebElement element;//from  w ww.  ja  v a 2  s.  co m
    WebDriverWait wait = new WebDriverWait(driver, timeout);
    element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    return element;
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

@Override
public WebElement elementToBeClickable(final String locator) {
    WebDriverWait wait = new WebDriverWait(webDriver, FIVE);
    return wait.until(ExpectedConditions.elementToBeClickable(getSelector(locator)));
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

@Override
public WebElement findElement(final String locator, int timeOut) {
    log.debug("debug: Looking for element: " + locator);
    WebElement e = (new WebDriverWait(webDriver, timeOut))
            .until(ExpectedConditions.presenceOfElementLocated(getSelector(locator)));
    return e;//w ww .j a  va 2s.  co m
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

@Override
public WebElement findClickableElement(final String locator, int timeout) {
    log.debug("debug: Looking for element: {}", locator);
    WebElement e = (new WebDriverWait(webDriver, timeout))
            .until(ExpectedConditions.elementToBeClickable(getSelector(locator)));
    return e;/*ww w  .jav  a 2s . c  om*/
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

@Override
public boolean isVisible(final String locator) {
    try {//from   ww  w  . j  av  a2 s .co  m
        (new WebDriverWait(webDriver, 1))
                .until(ExpectedConditions.visibilityOfElementLocated(getSelector(locator)));
        return true;
    } catch (Exception e1) {
        return false;
    }
}