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:testTheClient.java

@Test
public void removeFilterTest() throws Exception {
    WebElement element = driver.findElement(By.id("filter"));
    element.sendKeys(Keys.BACK_SPACE);// w ww .j ava  2 s. c  o m
    WebElement tableBody = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            });
    List<WebElement> rows = tableBody.findElements(By.tagName("tr"));
    Assert.assertThat(rows.size(), is(5));
}

From source file:testTheClient.java

@Test
public void sortByYear() {
    WebElement sort = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return driver.findElement(By.xpath("//*[@id=\"h_year\"]"));
            });/*  w  w  w  .  j  a v a2 s  . c o m*/
    sort.click();
    WebElement table = driver.findElement(By.tagName("tbody"));
    List<WebElement> sortedRows = table.findElements(By.tagName("tr"));
    Assert.assertThat(sortedRows.get(0).findElements(By.tagName("td")).get(0).getText(), is("938"));
    Assert.assertThat(sortedRows.get(4).findElements(By.tagName("td")).get(0).getText(), is("940"));
}

From source file:testTheClient.java

@Test
public void verifyAlterations() throws Exception {

    WebElement editButton = null;/*w  ww  . j a  v a 2  s. co  m*/
    List<WebElement> rows = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));
    ;
    for (int i = 0; i < rows.size(); i++) {
        if (rows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            editButton = rows.get(i);
            break;
        }
    }
    editButton = editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0);
    //click the edit button
    editButton.click();
    //clear description field and type coolscars 
    WebElement element = driver.findElement(By.id("description"));
    element.clear();
    element.sendKeys("cool cars");
    driver.findElement(By.xpath("//*[@id=\"save\"]")).click();
    List<WebElement> updatedRows = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));
    ;
    String newDescr = null;
    for (int i = 0; i < updatedRows.size(); i++) {
        if (updatedRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            newDescr = updatedRows.get(i).findElements(By.tagName("td")).get(5).getText();
            break;
        }
    }
    assertThat(newDescr, is("cool cars"));
}

From source file:testTheClient.java

@Test
public void testFieldErrorPrompt() {
    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("save")).click();

    String errorMessage = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<String>) (WebDriver d) -> {
                return d.findElement(By.xpath("//*[@id=\"submiterr\"]")).getText();
            });// w ww .  j  av  a 2  s . c  o m
    Assert.assertThat(errorMessage, is("All fields are required"));
}

From source file:testTheClient.java

@Test
public void zCreateNewCarEntry() throws Exception {
    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<String>) (WebDriver d) -> {
        return d.findElement(By.xpath("//*[@id=\"new\"]")).getText();
    });/*from ww  w. j a va 2  s .  co  m*/
    //populate fields
    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("year")).sendKeys("2008");
    driver.findElement(By.id("registered")).sendKeys("2002-5-5");
    driver.findElement(By.id("make")).sendKeys("Kia");
    driver.findElement(By.id("model")).sendKeys("Rio");
    driver.findElement(By.id("description")).sendKeys("As new");
    driver.findElement(By.id("price")).sendKeys("31000");
    //save
    driver.findElement(By.id("save")).click();
    List<WebElement> updatedRows = (new WebDriverWait(driver, WAIT_MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));
    assertThat(updatedRows.size(), is(6));
    assertThat(updatedRows.get(5).findElements(By.tagName("td")).get(1).getText(), is("2008"));
    assertThat(updatedRows.get(5).findElements(By.tagName("td")).get(4).getText(), is("Rio"));

}

From source file:NewCarTest.java

public void shouldWaitForPageToLoad() {
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("tbodycars")));
}

From source file:IntegracaoIT.java

@Test
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.
    WebDriver driver = new FirefoxDriver();

    // And now use this to visit NetBeans
    driver.get("http://www.netbeans.org");
    // 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//from  ww  w .jav  a2s  . c o m
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("NetBeans");
        }
    });

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

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyFirstTest() throws InterruptedException {

    //1. Go to story site
    driver.get(// w w  w.j  av a 2 s . c  o m
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //2. Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //Click on video tab
    WebElement videoTab = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[1]/div/div/div/table[1]/tbody[2]/tr[1]/td[1]/div/div/div[2]"));
    videoTab.click();
    WebElement searchText = driver.findElement(By.id("isc_30"));
    searchText.sendKeys("SSS_2477_01.mov");

    Thread.sleep(5000);
    WebElement selectVideo = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div[3]"));

    selectVideo.click();

    WebElement selectVideo1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div[3]"));
    selectVideo1.click();

    Thread.sleep(2000);
    WebElement timeLine = driver.findElement(By.cssSelector("svg[id=multimedia_ClearInOut]"));
    timeLine.click();

    Thread.sleep(2000);
    int xp1 = 0;
    WebElement testtimecode1 = driver.findElement(By.xpath("//*[contains(text(),'00:0" + xp1 + ":')]"));
    final String starttime = testtimecode1.getText();

    Actions action = new Actions(driver);
    action.sendKeys(Keys.SPACE).build().perform();
    System.out.println(testtimecode1.getText());

    int ourtime = 9000;
    Thread.sleep(ourtime);
    int xp = (ourtime - 1000) / 1000;
    action.sendKeys(Keys.SPACE).build().perform();
    Thread.sleep(2000);

    timeLine.click();
    Thread.sleep(2000);
    WebElement testtimecode = driver.findElement(By.xpath("//*[contains(text(),'00:0" + xp + ":')]"));

    System.out.println(testtimecode.getText());
    System.out.println(testtimecode1.getText());

    Assert.assertNotEquals(testtimecode.getText(), starttime);
    //Assert.assertNotEquals("111", "1");

}

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyKeyboardFrameForward() throws InterruptedException {

    //a. Launch story in firefox
    driver.get(// w  w w.  j  a v  a2s.  co m
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //From storytab double click on story named 'storytest'
    Thread.sleep(2000);
    WebElement storytest = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));
    storytest.click();
    WebElement storytest1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));

    storytest1.click();
    storytest1.click();

    Thread.sleep(3000);
    //Select the video element in timeline div[class="thumbnailStrip"]
    WebElement timelinebar = driver.findElement(By.cssSelector("div[class='thumbnailStrip']"));
    timelinebar.click();

    Thread.sleep(2000);

    WebElement timebarnumber = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue = timebarnumber.getText();

    WebElement timebarnumber1 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue1 = timebarnumber.getText();

    System.out.println(timevalue);
    Thread.sleep(2000);
    Actions action = new Actions(driver);
    action.sendKeys(Keys.DECIMAL).build().perform();

    WebElement timebarnumber2 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']//small"));
    final String timevalue2 = timebarnumber.getText();

    final String firsttime = (timevalue1.substring(timevalue2.lastIndexOf(":") + 1));
    int timer1 = Integer.parseInt(firsttime);

    final String secondtime = (timevalue2.substring(timevalue2.lastIndexOf(":") + 1));
    int timer2 = Integer.parseInt(secondtime);

    System.out.println(timer1);
    System.out.println(timer2);
    Assert.assertEquals(timer1 + 1, timer2);

}

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyKeyboardFrameBackward() throws InterruptedException {
    //a. Launch story in firefox
    driver.get(/*from   ww  w  .  j a v a  2s  . co  m*/
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //From storytab double click on story named 'storytest'
    Thread.sleep(2000);
    WebElement storytest = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));
    storytest.click();
    WebElement storytest1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));

    storytest1.click();
    storytest1.click();

    Thread.sleep(3000);
    //Select the video element in timeline div[class="thumbnailStrip"]
    WebElement timelinebar = driver.findElement(By.cssSelector("div[class='thumbnailStrip']"));
    timelinebar.click();

    Thread.sleep(2000);

    WebElement timebarnumber = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue = timebarnumber.getText();

    WebElement timebarnumber1 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue1 = timebarnumber.getText();

    System.out.println(timevalue);
    Thread.sleep(2000);
    Actions action = new Actions(driver);
    action.sendKeys(Keys.SEPARATOR).build().perform();

    WebElement timebarnumber2 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']//small"));
    final String timevalue2 = timebarnumber.getText();

    final String firsttime = (timevalue1.substring(timevalue2.lastIndexOf(":") + 1));
    int timer1 = Integer.parseInt(firsttime);

    final String secondtime = (timevalue2.substring(timevalue2.lastIndexOf(":") + 1));
    int timer2 = Integer.parseInt(secondtime);

    System.out.println(timer1);
    System.out.println(timer2);
    Assert.assertEquals(timer1 - 1, timer2);

}