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

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

Introduction

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

Prototype

public static ExpectedCondition<Boolean> not(final ExpectedCondition<?> condition) 

Source Link

Document

An expectation with the logical opposite condition of the given condition.

Usage

From source file:be.rubus.web.testing.AbstractWidget.java

License:Apache License

protected void waitUntilHiddenOf(WebElement checkElement) {
    new WebDriverWait(driver, 5).until(ExpectedConditions.not(ExpectedConditions.visibilityOf(checkElement)));

}

From source file:com.cognifide.bdd.demo.po.login.ProjectsScreen.java

License:Apache License

public boolean projectScreenIsNotDisplayed() {
    try {/*from   w  ww .j  a v  a 2s .  c  o  m*/
        wait.withTimeout(pageTitleTimeout)
                .until(ExpectedConditions.not(ExpectedConditions.titleIs(PAGE_TITLE)));
    } catch (TimeoutException te) {
        LOG.error("Timeout while waiting for page title to be different than '{}'", PAGE_TITLE, te);
        return false;
    }
    return true;
}

From source file:com.ecofactor.qa.automation.platform.util.Pageutil.java

License:Open Source License

/**
 * Checks if the given element is not displayed.
 * @param driver the driver//from  w  w w .j  a va 2 s.  c o  m
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is not displayed
 */
public static boolean isNotDisplayed(final WebDriver driver, final By locator, final CustomTimeout timeout) {

    boolean notDisplayed = true;
    try {
        final WebDriverWait wait = new WebDriverWait(driver, timeout.getValue());
        wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(locator)));
    } catch (final WebDriverException te) {
        notDisplayed = false;
    }
    return notDisplayed;
}

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 a  va  2 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.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Wait until element is changed text.//from  w ww  .  j  a  v a  2 s  . c  o m
 *
 * @param text           before change
 * @param timeoutSec     seconds to wait until element is changed text
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForTextChanged(final String text, final int timeoutSec, final boolean checkCondition) {
    boolean isChanged;
    logAction(this, getParentClassName(), format("waitForTextChanged[%s]: %s", text, locator));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        isChanged = wait.until(ExpectedConditions
                .not(ExpectedConditions.textToBePresentInElementLocated(avatar.byLocator, text)));
    } catch (TimeoutException e) {
        logTechnical(format("waitForTextChanged: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isChanged = false;
    }
    if (checkCondition) {
        logAssertTrue(BUSINESS_LEVEL, isChanged,
                format("waitForTextChanged - '%s' text '%s' should be changed", getName(), text),
                takePassedScreenshot);
    }
    return parent;
}

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

License:Open Source License

/**
 * Wait until all elements is invisible/* ww w  . j ava  2 s. c  o  m*/
 *
 * @param timeoutSec     seconds to wait until all elements become Not Visible
 * @param checkCondition log assert for expected conditions.
 * @return Parent instance
 */
public ParentPanel waitForAllElementsNotVisible(final int timeoutSec, final boolean checkCondition) {
    logAction(this, getParentClassName(), format("waitForAllElementsNotVisible: %s", locator));
    boolean isNotVisible;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(1);
    try {
        wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfAllElements(getWebElements())));
        isNotVisible = true;
    } catch (TimeoutException e) {
        logTechnical(format("waitForAllElementsNotVisible: [ %s ] during: [ %d ] sec ", locator,
                System.currentTimeMillis() / 1000 - start));
        isNotVisible = false;
    } catch (NoSuchElementException elementException) {
        isNotVisible = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isNotVisible,
                format("waitForAllElementsNotVisible - all element of '%s' should be not visible", name),
                TestBaseWebDriver.takePassedScreenshot);
    }
    return parent;
}

From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * Wait until windows title not contains text.
 *
 * @param timeoutSec     to wait until windows title not contains text.
 * @param title          - Expected window title not contains text.
 * @param checkCondition log assert for expected conditions.
 *//*  www  .  ja  v a2 s.  co  m*/
public static void waitForTitleNotContains(String title, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForTitleNotContains: %s", title));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        wait.until(ExpectedConditions.not(ExpectedConditions.titleContains(title)));
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForTitleNotContains: [ %s ] during: [ %d ] sec ", title,
                System.currentTimeMillis() / 1000 - start));
    }
    if (checkCondition) {
        ReporterNGExt.logAssertNotContains(ReporterNGExt.BUSINESS_LEVEL, getDriver().getTitle(), title,
                "waitForTitleNotContains", TestBaseWebDriver.takePassedScreenshot);
    }
}

From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * Wait until element is changed text/* w  ww. ja  v a 2 s.c  o m*/
 *
 * @param title          before change
 * @param timeoutSec     seconds to wait until element is changed text
 * @param checkCondition - log assert for expected conditions.
 */
public static void waitForTitleChanged(final String title, int timeoutSec, boolean checkCondition) {
    boolean isChanged;
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForTitleChanged: %s", title));
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    try {
        isChanged = wait.until(ExpectedConditions.not(ExpectedConditions.titleIs(title)));
    } catch (TimeoutException e) {
        ReporterNGExt.logTechnical(String.format("waitForTitleChanged: [ %s ] during: [ %d ] sec ", title,
                System.currentTimeMillis() / 1000 - start));
        isChanged = false;
    }
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isChanged,
                String.format("waitForTitleChanged: title '%s' should be changed", title),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * Wait until any element with text not presents at web page.
 *
 * @param text           - element text to not be presents.
 * @param timeoutSec     to wait until not presents.
 * @param checkCondition log assert for expected conditions.
 *///from   w  w  w  .  ja va2 s.  c  o  m
public static void waitForTextToNotBePresent(String text, int timeoutSec, boolean checkCondition) {
    ReporterNGExt.logAction(getDriver(), "", String.format("waitForTextToNotBePresent: %s", text));
    boolean isNotPresent;
    long start = System.currentTimeMillis() / 1000;
    WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec)
            .ignoring(StaleElementReferenceException.class);
    setTimeout(timeoutSec);
    try {
        isNotPresent = wait.until(ExpectedConditions
                .not(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//*"), text)));
    } catch (TimeoutException ignored) {
        ReporterNGExt.logTechnical(String.format("waitForTextToNotBePresent: [ %s ] during: [ %d ] sec ", text,
                System.currentTimeMillis() / 1000 - start));
        isNotPresent = false;
    }
    setTimeout(TIMEOUT);
    if (checkCondition) {
        ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isNotPresent,
                String.format("waitForTextToNotBePresent: element with text '%s' should not be exists", text),
                TestBaseWebDriver.takePassedScreenshot);
    }
}

From source file:com.liferay.faces.bridge.test.integration.issue.FACES_1470PortletTester.java

License:Open Source License

@Test
public void runFACES_1470PortletTest() {

    String container = TestUtil.getContainer();
    Assume.assumeTrue("The FACES-1470 test is only valid on Liferay Portal.", container.startsWith("liferay"));

    // 1. Sign in to the portal.
    BrowserDriver browserDriver = getBrowserDriver();
    browserDriver.navigateWindowTo(BridgeTestUtil.getIssuePageURL("faces-1470"));

    String navigateToView1LinkXpath = "//a[contains(text(), 'Navigate to view1.xhtml')]";
    browserDriver.waitForElementEnabled(navigateToView1LinkXpath);

    // 2. Open the *Navigate to view1.xhtml* link in a new tab.
    String as7LeakInstanceTrackerWindowId = browserDriver.getCurrentWindowId();
    Set<String> windowIds = browserDriver.getWindowIds();
    int numberOfWindows = windowIds.size();
    browserDriver.clickElement(navigateToView1LinkXpath);
    browserDriver.waitFor(new WindowOpened(numberOfWindows));
    windowIds = browserDriver.getWindowIds();

    // 3. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    Iterator<String> iterator = windowIds.iterator();
    String viewsWindowId = null;//from w w  w .  jav a 2  s.  c o  m

    while (iterator.hasNext()) {

        String windowId = iterator.next();

        if (!as7LeakInstanceTrackerWindowId.equals(windowId)) {

            viewsWindowId = windowId;

            break;
        }
    }

    if (viewsWindowId == null) {
        throw new IllegalStateException("No new tab opened when *Navigate to view1.xhtml* was clicked.");
    }

    WaitingAsserter waitingAsserter = getWaitingAsserter();
    List<WebElement> as7LeakInstanceElements = new ArrayList<WebElement>();
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 4. Switch back to the tab with view1.xhtml and click the *Click me to navigate to view2.xhtml via Ajax*
    // button.
    switchToWindow(browserDriver, viewsWindowId);

    String navToView2AjaxButtonXpath = "//input[contains(@value,'Click me to navigate to view2.xhtml via Ajax')]";
    clickButton(browserDriver, navToView2AjaxButtonXpath);

    // 5. Click the *Click me to navigate to view1.xhtml via Ajax* button.
    String navToView1AjaxButtonXpath = "//input[contains(@value,'Click me to navigate to view1.xhtml via Ajax')]";
    clickButton(browserDriver, navToView1AjaxButtonXpath);

    // 6. Switch back to the first tab (as7LeakTracker.xhtml) and click the Refresh AS7Leak List button and confirm
    // that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 7. Switch back to the tab with view1.xhtml and click the *Click me to navigate to view2.xhtml via non-Ajax
    // (full postback)* button.
    switchToWindow(browserDriver, viewsWindowId);

    String navToView2NonAjaxButtonXpath = "//input[contains(@value,'Click me to navigate to view2.xhtml via non-Ajax (full postback)')]";
    clickButton(browserDriver, navToView2NonAjaxButtonXpath);

    // 8. Click the *Click me to navigate to view1.xhtml via non-Ajax (full postback)* button.
    String navToView1NonAjaxButtonXpath = "//input[contains(@value,'Click me to navigate to view1.xhtml via non-Ajax (full postback)')]";
    clickButton(browserDriver, navToView1NonAjaxButtonXpath);

    // 9. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 10. Switch back to the tab with view1.xhtml and click the *Click me to navigate to view2.xhtml via Ajax*
    // button.
    switchToWindow(browserDriver, viewsWindowId);
    clickButton(browserDriver, navToView2AjaxButtonXpath);

    // 11. Click the *Click me to navigate to view1.xhtml via non-Ajax (full postback)* button.
    clickButton(browserDriver, navToView1NonAjaxButtonXpath);

    // 12. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 13. Switch back to the tab with view1.xhtml and click the *Click me to navigate to view2.xhtml via non-Ajax
    // (full postback)* button.
    switchToWindow(browserDriver, viewsWindowId);
    clickButton(browserDriver, navToView2NonAjaxButtonXpath);

    // 14. Click the *Click me to navigate to view1.xhtml via Ajax* button.
    clickButton(browserDriver, navToView1AjaxButtonXpath);

    // 15. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 16. Switch back to the tab with view1.xhtml, navigate to the as7LeakTracker.xhtml portlet page (to avoid
    // loading any AS7Leak instances as an unauthenticated user), and sign out of the portal.
    switchToWindow(browserDriver, viewsWindowId);
    browserDriver.navigateWindowTo(BridgeTestUtil.getIssuePageURL("faces-1470"));
    signOut(browserDriver);
    browserDriver.closeCurrentWindow();

    // 17. Switch back to the first tab (as7LeakTracker.xhtml) and click the *Refresh AS7Leak List* button and
    // confirm that several AS7Leak class instances appear.
    testAS7LeakIntancesCreated(browserDriver, waitingAsserter, as7LeakInstanceTrackerWindowId,
            as7LeakInstanceElements);

    // 18. Click the *Perform Garbage Collection* button and confirm that no AS7Leak class instances appear. Note:
    // since this portlet uses System.gc() to initiate garbage collection, it may be necessary to click the *Perform
    // Garbage Collection* multiple times before the garbage is actually collected. For more details see here:
    // http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#gc().
    ExpectedCondition<Boolean> as7LeakElementsNotPresent = ExpectedConditions
            .not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(as7LeakInstanceXpath)));

    // Attempt garbage collection 5 times before giving up.
    for (int i = 0; i < 5; i++) {

        clickButton(browserDriver, "//input[contains(@value,'Perform Garbage Collection')]");

        try {

            browserDriver.waitFor(as7LeakElementsNotPresent);

            break;
        } catch (TimeoutException e) {
            // Retry.
        }
    }

    waitingAsserter.assertElementNotPresent(as7LeakInstanceXpath);
}