Example usage for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated

Introduction

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

Prototype

public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator) 

Source Link

Document

An expectation for checking that an element is present on the DOM of a page.

Usage

From source file:com.example.getstarted.basicactions.UserJourneyTestIT.java

License:Apache License

@Test
public void userJourney() throws Exception {
    // Do selenium tests on the deployed version, if applicable
    String endpoint = "http://localhost:8080";
    if (!LOCAL_TEST) {
        endpoint = String.format("https://%s-dot-%s.appspot.com", APP_VERSION, APP_ID);
    }/*from  w w  w  .j  a v a2  s  .c o m*/
    System.out.println("Testing endpoint: " + endpoint);
    driver.get(endpoint);

    try {
        WebElement button = checkLandingPage();

        if (LOCAL_TEST) {
            WebElement loginButton = driver.findElement(By.linkText("Login"));
            loginButton.click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches("login"));

            login(EMAIL);
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches("/books"));

            button = checkLandingPage(EMAIL);

            button.click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/create$"));

            checkAddBookPage();

            submitForm(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION);
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/read\\?id=[0-9]+$"));

            checkReadPage(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION, EMAIL);

            logout(EMAIL);
            (new WebDriverWait(driver, 10))
                    .until(ExpectedConditions.presenceOfElementLocated(By.linkText("Login")));

        } else {
            button.click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/create$"));

            checkAddBookPage();

            submitForm(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION);
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/read\\?id=[0-9]+$"));

            checkReadPage(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION, "Anonymous");

            // Now check the list of books for the one we just submitted
            driver.findElement(By.linkText("Books")).click();
            (new WebDriverWait(driver, 10)).until(ExpectedConditions.urlMatches(".*/$"));

            checkBookList(TITLE, AUTHOR, PUBLISHED_DATE, DESCRIPTION);
        }
    } catch (Exception e) {
        System.err.println(driver.getPageSource());
        throw e;
    }
}

From source file:com.formkiq.web.SeleniumTestBase.java

License:Apache License

/**
 * @param by {@link By}/*from www.  j av  a 2 s. co m*/
 * @return {@link WebElement}
 */
public List<WebElement> findElements(final By by) {
    getWait().until(ExpectedConditions.presenceOfElementLocated(by));
    getWait().until(ExpectedConditions.visibilityOfElementLocated(by));
    return getDriver().findElements(by);
}

From source file:com.fpt.datht.iap.AutoIAP.java

public static void loginGoogle(String user, String pass) {
    System.setProperty("webdriver.chrome.driver", "/chromedriver.exe");

    driver = new ChromeDriver();

    //  driver = new HtmlUnitDriver(true);
    driver.navigate().to("http://iap.fpt.edu.vn/hlogin.php?provider=Google");

    new WebDriverWait(driver, 360).until(ExpectedConditions.titleIs("Sign in - Google Accounts"));
    el = driver.findElement(By.id("Email"));
    el.sendKeys(user);/*from   ww  w .j a v a 2s .co  m*/
    el = driver.findElement(By.id("next"));
    el.click();

    new WebDriverWait(driver, 360).until(ExpectedConditions.presenceOfElementLocated(By.id("Passwd")));

    el = driver.findElement(By.id("Passwd"));
    el.sendKeys(pass);
    el = driver.findElement(By.id("signIn"));
    el.click();

}

From source file:com.fpt.datht.iap.AutoIAP.java

public static void getDataFromServer(String className) {
    int c = 0;/*  w ww.  jav a2 s  . co m*/
    slots = new String[10];
    students = new LinkedList<>();
    new WebDriverWait(driver, 360).until(ExpectedConditions.titleIs("IAP"));
    driver.get("http://iap.fpt.edu.vn/activity");

    new WebDriverWait(driver, 360).until(ExpectedConditions.urlToBe("http://iap.fpt.edu.vn/activity/"));

    List<WebElement> els = driver.findElements(By.tagName("a"));
    System.out.println("Size a:" + els.size());
    for (WebElement e : els) {
        //  System.out.println(e.getText());
        if (e.getText().contains(className)) {

            slots[c] = e.getAttribute("href").replaceAll("http://iap.fpt.edu.vn/activity/index.php",
                    "http://iap.fpt.edu.vn/attendance/add.php");
            c++;
            count = c;
            // System.out.println(main);

        }
    }
    if (slots.length == 0)
        return;
    driver.get(slots[0]);

    try {
        new WebDriverWait(driver, 5)
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));

    } catch (TimeoutException ex) {
        driver.get(slots[0].replaceAll("add.php", "edit.php"));

    }
    //Auto Check Slot 1
    if (autoCheckSlot1) {
        List<WebElement> elsInput = driver.findElements(By.xpath(".//input[@type='radio' and @value='1' ]"));
        autoCheckAll(elsInput);
    }

    //Wating for submit
    new WebDriverWait(driver, 5000)
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//font[@color='green']")));
    driver.get(slots[0].replaceAll("add.php", "edit.php"));
    //GET All checked
    List<WebElement> elsInputChecked = driver
            .findElements(By.xpath(".//input[@type='radio' and @value='1' and @checked]"));

    System.out.println("Size input checked:" + elsInputChecked.size());

    elsInputChecked.stream().map((e) -> {
        Student student = new Student();
        student.name = e.getAttribute("name");
        return student;
    }).forEach(students::add);

}

From source file:com.fpt.datht.iap.AutoIAP.java

public static void autoCheck() {

    for (int c = 1; c < count; c++) {

        driver.get(slots[c]);/* w ww  .java2 s  .  c o  m*/
        try {
            new WebDriverWait(driver, 5)
                    .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));

        } catch (TimeoutException ex) {
            driver.get(slots[c].replaceAll("add.php", "edit.php"));

        }
        new WebDriverWait(driver, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));
        for (Student st : students) {

            List<WebElement> els = driver.findElements(By.name(st.name));
            els.stream().filter((e) -> (e.getAttribute("value").equals("1"))).forEach((e) -> {
                e.click();
            });
        }
        el = driver.findElement(By.xpath(".//input[@type='submit']"));
        el.click();
        try {
            new WebDriverWait(driver, 3).until(
                    ExpectedConditions.invisibilityOfElementLocated(By.xpath(".//input[@type='submit']")));
        } catch (TimeoutException ex) {
            break;

        }

    }

}

From source file:com.fullteaching.backend.e2e.FullTeachingTestE2E.java

License:Apache License

@Test
@DisplayName("Test video session")
void oneToOneVideoAudioSessionChrome() throws Exception {

    final String userEmail = "teacher@gmail.com";
    final String userPass = "pass";

    String brow = System.getenv("browser");

    if (brow != null && (brow.equals("chrome") || brow.equals("firefox"))) {
        setupBrowser(brow);/*  w ww  .j  a  v  a2  s .  com*/
    } else {
        setupBrowser("chrome");
    }

    log.info("Test video session");

    this.login(user, userEmail, userPass);

    user.getWaiter().until(ExpectedConditions.presenceOfElementLocated(
            By.cssSelector(("ul.collection li.collection-item:first-child div.course-title"))));
    user.getDriver()
            .findElement(By.cssSelector("ul.collection li.collection-item:first-child div.course-title"))
            .click();

    user.getWaiter().until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(("#md-tab-label-0-1"))));
    user.getDriver().findElement(By.cssSelector("#md-tab-label-0-1")).click();

    user.getDriver().findElement(By.cssSelector("ul div:first-child li.session-data div.session-ready"))
            .click();

    System.out.println("-------------------- WAITING ------------------------");

    Thread.sleep(5000);

    user.getWaiter()
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(("div.participant video"))));

    checkVideoPlaying(user, user.getDriver().findElement(By.cssSelector(("div.participant video"))),
            "div.participant");

}

From source file:com.fullteaching.backend.e2e.FullTeachingTestE2ESleep.java

License:Apache License

@Test
@DisplayName("Test video session")
void oneToOneVideoAudioSessionChrome() throws Exception {

    // TEACHER/*from   w  ww  . j ava2 s  .  com*/

    final String userEmail = "teacher@gmail.com";
    final String userPass = "pass";

    this.user = setupBrowser("chrome");

    log.info("Test video session");

    this.login(user, userEmail, userPass);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    user.getWaiter().until(ExpectedConditions.presenceOfElementLocated(
            By.cssSelector(("ul.collection li.collection-item:first-child div.course-title"))));
    user.getDriver()
            .findElement(By.cssSelector("ul.collection li.collection-item:first-child div.course-title"))
            .click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    user.getWaiter().until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(("#md-tab-label-0-1"))));
    user.getDriver().findElement(By.cssSelector("#md-tab-label-0-1")).click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    user.getDriver().findElement(By.cssSelector("ul div:first-child li.session-data div.session-ready"))
            .click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    user.getWaiter()
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(("div.participant video"))));

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    checkVideoPlaying(user, user.getDriver().findElement(By.cssSelector(("div.participant video"))),
            "div.participant");

    // STUDENT

    BrowserUser student = setupBrowser("chrome");
    login(student, "student1@gmail.com", "pass");

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    student.getWaiter().until(ExpectedConditions.presenceOfElementLocated(
            By.cssSelector(("ul.collection li.collection-item:first-child div.course-title"))));
    student.getDriver()
            .findElement(By.cssSelector("ul.collection li.collection-item:first-child div.course-title"))
            .click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    student.getWaiter()
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(("#md-tab-label-0-1"))));
    student.getDriver().findElement(By.cssSelector("#md-tab-label-0-1")).click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    student.getDriver().findElement(By.cssSelector("ul div:first-child li.session-data div.session-ready"))
            .click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    student.getWaiter()
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(("div.participant video"))));

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    checkVideoPlaying(student, student.getDriver().findElement(By.cssSelector(("div.participant video"))),
            "div.participant");

    // Student ask for intervention
    student.getWaiter().until(ExpectedConditions.elementToBeClickable(
            By.xpath("//div[@id='div-header-buttons']//i[text() = 'record_voice_over']")));
    student.getDriver()
            .findElement(By.xpath("//div[@id='div-header-buttons']//i[text() = 'record_voice_over']")).click();

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    // Teacher accepts intervention
    user.getWaiter()
            .until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(@class, 'usr-btn')]")));
    user.getDriver().findElement(By.xpath("//a[contains(@class, 'usr-btn')]")).click();

    // Check both videos
    student.getWaiter().until(
            ExpectedConditions.presenceOfElementLocated(By.cssSelector(("div.participant-small video"))));
    checkVideoPlaying(student, student.getDriver().findElement(By.cssSelector(("div.participant-small video"))),
            "div.participant-small");
    checkVideoPlaying(student, student.getDriver().findElement(By.cssSelector(("div.participant-small video"))),
            "div.participant-small");

    user.getWaiter().until(
            ExpectedConditions.presenceOfElementLocated(By.cssSelector(("div.participant-small video"))));
    checkVideoPlaying(user, user.getDriver().findElement(By.cssSelector(("div.participant-small video"))),
            "div.participant-small");
    checkVideoPlaying(user, user.getDriver().findElement(By.cssSelector(("div.participant-small video"))),
            "div.participant-small");

    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    // Teacher removes user
    user.getWaiter()
            .until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(@class, 'usr-btn')]")));
    user.getDriver().findElement(By.xpath("//a[contains(@class, 'usr-btn')]")).click();

    // Wait until only one video
    user.getWaiter().until(ExpectedConditions.not(ExpectedConditions
            .presenceOfAllElementsLocatedBy(By.cssSelector(("div.participant-small video")))));
    student.getWaiter().until(ExpectedConditions.not(ExpectedConditions
            .presenceOfAllElementsLocatedBy(By.cssSelector(("div.participant-small video")))));

    try {
        Thread.sleep(4000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    // Logout student
    this.logut(student);
    student.dispose();

}

From source file:com.gdf.managedBean.TendererInvitationBeanTest.java

@Test
public void send() {

    email = driver.findElement(By.xpath("//input[contains(@id, 'mailForm:email')]"));
    sendButton = driver.findElement(By.xpath("//button[contains(@id, 'mailForm:send')]"));

    email.clear();//from  ww  w. j  a  v a 2 s  . c  o  m
    email.sendKeys("guendouzbachir@hotmail.com");

    sendButton.click();

    // Test
    WebElement growlTitle = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.className("ui-growl-title")));

    // Verification
    assertEquals(growlTitle.getText(), "Message envoy!");

}

From source file:com.gdf.managedBean.TendererRegistrationBeanTest.java

@Test
public void registration() {
    // Preparation
    driver.get(baseUrl);//from  w w  w . j  a v  a2  s . co  m

    inputLogin = driver.findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerLogin')]"));
    inputPassword = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerPassword')]"));
    inputConfirmPassword = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerConfirmPassword')]"));
    inputMail = driver.findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerMail')]"));
    inputFirstname = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerFirstname')]"));
    inputLastName = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerLastname')]"));
    inputPhone = driver
            .findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerPhoneNumber')]"));
    inputAvatar = driver.findElement(By.xpath("//input[contains(@id,'registerTendererForm:registerAvatar')]"));

    registerButton = driver
            .findElement(By.xpath("//button[contains(@id,'registerTendererForm:tenderRegisterButton')]"));

    inputLogin.clear();
    inputLogin.sendKeys("SuperTenderer" + new Random().nextInt(1000));
    inputPassword.clear();
    inputPassword.sendKeys("password1234");
    inputConfirmPassword.clear();
    inputConfirmPassword.sendKeys("password1234");
    inputMail.clear();
    inputMail.sendKeys("super.tenderer@mymail.com");
    inputFirstname.clear();
    inputFirstname.sendKeys("I'm the");
    inputLastName.clear();
    inputLastName.sendKeys("SuperTenderer");
    inputPhone.clear();
    inputPhone.sendKeys("2820092809");
    inputAvatar.clear();
    inputAvatar.sendKeys("http://www.batterytender.com/assets/img/logo_BTmainNav.png");

    registerButton.click();

    // Test
    WebElement growlTitle = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.className("ui-growl-title")));

    // Verification
    assertEquals(growlTitle.getText(), "Inscription russie !");
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element exists./* www.  j a  va 2s .co  m*/
 *
 * @param timeoutSec     seconds to wait until element exists.
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForExists(int timeoutSec, boolean checkCondition) {
    boolean isExists;
    logAction(this, getParentClassName(), format("waitForExists: %s", locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.presenceOfElementLocated(avatar.byLocator));
        isExists = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForExists: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isExists = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isExists, format("waitForExists - '%s' should exist", getName()),
                takePassedScreenshot);
    }
    return parent;
}