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:org.glowroot.agent.webdriver.tests.config.AdvancedConfigPage.java

License:Apache License

public void clickSaveButton() {
    WebElement saveButton = withWait(xpath("//button[normalize-space()='Save changes']"));
    saveButton.click();//from w  w  w.  jav a2 s.  c  o  m
    // wait for save to complete
    new WebDriverWait(driver, 30)
            .until(ExpectedConditions.not(ExpectedConditions.elementToBeClickable(saveButton)));
}

From source file:org.opennms.smoketest.BSMAdminIT.java

License:Open Source License

private ExpectedCondition<Boolean> getElementNotPresentCondition(final By by) {
    return ExpectedConditions.not(new ExpectedCondition<Boolean>() {
        @Nullable//from  w w  w.ja  v  a 2 s. co  m
        @Override
        public Boolean apply(@Nullable WebDriver input) {
            try {
                // the default implicit wait timeout is too long, make it shorter
                input.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
                WebElement elementFound = input.findElement(by);
                return elementFound != null;
            } catch (NoSuchElementException | StaleElementReferenceException ex) {
                return false;
            } finally {
                // set the implicit wait timeout back to the value it has been before
                input.manage().timeouts().implicitlyWait(LOAD_TIMEOUT, TimeUnit.MILLISECONDS);
            }
        }
    });
}

From source file:org.opennms.smoketest.ProvisioningNewUIIT.java

License:Open Source License

/**
 * Test requisition UI.//  w w w. ja va  2s  .  co m
 *
 * @throws Exception the exception
 */
@Test
public void testRequisitionUI() throws Exception {
    setImplicitWait(2, TimeUnit.SECONDS);

    // Add a new requisition
    clickId("add-requisition", false);
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.cssSelector("form.bootbox-form > input.bootbox-input")));
    enterText(By.cssSelector("form.bootbox-form > input.bootbox-input"), REQUISITION_NAME);
    findElementByXpath("//div/button[text()='OK']").click();
    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//td[text()='" + REQUISITION_NAME + "']")));

    // Edit the foreign source
    final String editForeignSourceButton = "button.btn[uib-tooltip='Edit detectors and policies of the "
            + REQUISITION_NAME + " Requisition']";
    wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(editForeignSourceButton))).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("ul.nav-tabs > li > a.nav-link")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//h4[text()='Foreign Source Definition for Requisition " + REQUISITION_NAME + "']")));

    // Add a detector
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("add-detector")));
    clickId("add-detector", false);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("form[name='detectorForm']")));
    enterText(By.xpath("//form[@name='detectorForm']//input[@ng-model='detector.name']"), NODE_SERVICE);
    enterText(By.xpath("//form[@name='detectorForm']//input[@ng-model='detector.class']"), "HTTP");
    findElementByXpath(
            "//form[@name='detectorForm']//ul[contains(@class, 'dropdown-menu')]/li/a/strong[text()='HTTP']")
                    .click();
    waitForDropdownClose();

    // Add a parameter to the detector
    clickId("add-detector-parameter", false);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name='paramName']")));
    enterText(By.cssSelector("input[name='paramName']"), "po");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@title='port']"))).click();
    enterText(By.cssSelector("input[name='paramValue']"), "8980");
    //enterText(By.cssSelector("input[name='paramValue']"), Keys.ENTER);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("save-detector"))).click();
    waitForModalClose();
    enterText(By.cssSelector("input[placeholder='Search/Filter Detectors'][ng-model='filters.detector']"),
            "HTTP-8980");
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//td[text()='" + NODE_SERVICE + "']")));

    // Add a policy to the detector
    findElementByCss("#tab-policies .ng-binding").click();
    clickId("add-policy", false);
    findElementByCss("form[name='policyForm']");
    enterText(By.cssSelector("input#name"), "No IPs");
    enterText(By.cssSelector("input#clazz"), "Match IP Interface");
    enterText(By.cssSelector("input#clazz"), Keys.ENTER);
    enterText(By.xpath("(//input[@name='paramValue'])[1]"), "DO_NOT_PERSIST");
    enterText(By.xpath("(//input[@name='paramValue'])[1]"), Keys.ENTER);
    enterText(By.xpath("(//input[@name='paramValue'])[2]"), "NO_PARAMETERS");
    enterText(By.xpath("(//input[@name='paramValue'])[2]"), Keys.ENTER);
    clickId("save-policy", false);
    waitForModalClose();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//td[text()='No IPs']")));

    // Save foreign source definition
    clickId("save-foreign-source", false);
    wait.until(ExpectedConditions
            .not(ExpectedConditions.visibilityOfElementLocated(By.id("save-foreign-source"))));

    // Go to the Requisition page
    clickId("go-back", false);
    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//h4[text()='Requisition " + REQUISITION_NAME + " (0 defined, 0 deployed)']")));

    // Add node to a requisition
    clickId("add-node", false);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("nodeLabel"))).clear();
    enterText(By.id("nodeLabel"), NODE_LABEL);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("foreignId"))).clear();
    enterText(By.id("foreignId"), NODE_FOREIGNID);
    saveNode();

    // Add an IP Interface
    clickId("tab-interfaces", false);
    findElementById("add-interface").click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("form[name='intfForm']")));
    final By ipaddrBy = By.cssSelector("input#ipAddress");
    wait.until(ExpectedConditions.visibilityOfElementLocated(ipaddrBy));
    enterText(ipaddrBy, NODE_IPADDR);

    // Add a service to the IP Interface
    findElementById("add-service").click();
    final By xpath = By.cssSelector("input[name='serviceName']");
    wait.until(ExpectedConditions.visibilityOfElementLocated(xpath));
    Thread.sleep(100);
    enterText(xpath, "HTTP-89");
    findElementByXpath("//a[@title='HTTP-8980']/strong").click();

    // Save the IP interface
    clickId("save-interface", false);
    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//td[contains(@class,'ng-binding') and text()='" + NODE_IPADDR + "']")));

    // Add an asset to the node
    clickId("tab-assets", false);
    clickId("add-asset", false);
    findElementByCss("form[name='assetForm']");
    enterText(By.id("asset-name"), "countr");
    findElementByXpath("//a[@title='country']/strong").click();
    enterText(By.id("asset-value"), "USA");
    clickId("save-asset", false);
    waitForModalClose();

    // Add a category to the node
    clickId("tab-categories", false);
    clickId("add-category", false);
    Thread.sleep(100);
    enterText(By.cssSelector("input[name='categoryName']"), NODE_CATEGORY);
    findElementByXpath("//a[@title='" + NODE_CATEGORY + "']/strong").click();

    saveNode();

    // Go to the requisition page
    clickId("go-back", false);
    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//td[contains(@class,'ng-binding') and text()='" + NODE_LABEL + "']")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//td[contains(@class,'ng-binding') and text()='" + NODE_FOREIGNID + "']")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//p[contains(@class,'ng-binding') and text()='" + NODE_IPADDR + " (P)']")));

    // Synchronize the requisition
    clickId("synchronize", false);
    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.cssSelector(".modal-dialog button.btn.btn-success")));
    WebElement modal = findModal();
    modal.findElement(By.xpath("//div/button[text()='Yes']")).click();
    waitForModalClose();
    wait.until(new WaitForNodesInRequisition(REQUISITION_NAME, 1));
    wait.until(new WaitForNodesInDatabase(REQUISITION_NAME, 1));
    clickId("refresh", false);
    clickId("refreshDeployedStats", false);
    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//h4[text()='Requisition " + REQUISITION_NAME + " (1 defined, 1 deployed)']")));

    // Go to the requisitions page
    clickId("go-back", false);

    // Wait until the node has been added to the database, using the ReST API
    m_driver.get(getBaseUrl() + "opennms/rest/nodes/" + REQUISITION_NAME + ":" + NODE_FOREIGNID
            + "/ipinterfaces/" + NODE_IPADDR + "/services/ICMP");
    m_driver.manage().timeouts().implicitlyWait(2000, TimeUnit.MILLISECONDS);
    try {
        for (int i = 0; i < 30; i++) {
            try {
                final WebElement e = m_driver
                        .findElement(By.xpath("//service/serviceType/name[text()='ICMP']"));
                if (e != null) {
                    break;
                }
            } catch (Exception e) {
            }
            m_driver.navigate().refresh();
        }
    } finally {
        m_driver.manage().timeouts().implicitlyWait(LOAD_TIMEOUT, TimeUnit.MILLISECONDS);
    }

    // Open the nodes list page
    m_driver.get(getBaseUrl() + "opennms/");
    clickMenuItem("Info", "Nodes", "element/nodeList.htm");

    try {
        // Disable implicitlyWait
        m_driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
        // If this is the only node on the system, we'll be sent directly to its node details page.
        findElementByXpath("//h3[text()='Availability']");
    } catch (NoSuchElementException e) {
        // If there are multiple nodes, we will be on the node list page, click through to the node
        findElementByLink(NODE_LABEL).click();
    } finally {
        // Restore the implicitlyWait timeout
        m_driver.manage().timeouts().implicitlyWait(LOAD_TIMEOUT, TimeUnit.MILLISECONDS);
    }

    wait.until(ExpectedConditions.elementToBeClickable(By.linkText("ICMP")));
    findElementByXpath("//a[contains(@href, 'element/interface.jsp') and text()='" + NODE_IPADDR + "']");
    findElementByLink("HTTP-8980");
}

From source file:org.opennms.smoketest.ProvisioningNewUIIT.java

License:Open Source License

protected void saveNode() throws InterruptedException {
    clickId("save-node", false);
    wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(By.id("save-node"))));
}

From source file:org.orcid.integration.blackbox.client.Utils.java

License:Open Source License

public void colorBoxIsClosed() {
    getWait().until(ExpectedConditions
            .not(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[@id='colorbox']"))));
}

From source file:org.orcid.integration.blackbox.web.SigninTest.java

License:Open Source License

public static void colorBoxIsClosed(WebDriverWait wait) {
    wait.until(ExpectedConditions
            .not(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[@id='colorbox']"))));
}

From source file:org.orcid.integration.blackbox.web.works.AddWorksTest.java

License:Open Source License

public static void deleteAllByWorkName(String workName, WebDriver webDriver) {
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    waitWorksLoaded(wait);/* w  w  w . j  a  v a 2s .c  o m*/
    List<WebElement> wList = webDriver
            .findElements(By.xpath("//*[@orcid-put-code and descendant::span[text() = '" + workName + "']]"));
    if (wList.size() > 0)
        for (WebElement we : wList) {
            String putCode = we.getAttribute("orcid-put-code");
            putCode = "" + putCode;
            String deleteJsStr = "angular.element('*[ng-app]').injector().get('worksSrvc').deleteWork('"
                    + putCode + "');";
            ((JavascriptExecutor) webDriver).executeScript(deleteJsStr);
            waitWorksLoaded(wait);
        }
    wait.until(
            ExpectedConditions.not(ExpectedConditions.presenceOfAllElementsLocatedBy(byWorkTitle(workName))));
    assertTrue(0 == webDriver.findElements(byWorkTitle(workName)).size());
}

From source file:org.syftkog.web.test.framework.ElementConditions.java

License:Apache License

/**
 * An expectation for checking if the element is not enabled.
 *
 * @param el//from   www .  j av a 2s .co  m
 * @return
 */
public static ExpectedCondition<Boolean> isNotEnabled(final Element el) {
    return ExpectedConditions.not(isEnabled(el));
}

From source file:org.syftkog.web.test.framework.ElementConditions.java

License:Apache License

/**
 * An expectation for checking if the given text not is present in the
 * specified element nor element value attribute. (Case insensitive)
 *
 * @param el//from www  .  jav a2  s.  com
 * @param text
 * @return
 */
public static ExpectedCondition<Boolean> textDoesNotContain(final Element el, final String text) {
    return ExpectedConditions.not(textContains(el, text));
}

From source file:org.syftkog.web.test.framework.ElementConditions.java

License:Apache License

/**
 *
 * @param el/* w ww . j av  a  2  s.  c om*/
 * @param text
 * @return
 */
public static ExpectedCondition<Boolean> textDoesNotEqualIgnoreCase(final Element el, final String text) {
    return ExpectedConditions.not(textEqualsIgnoreCase(el, text));
}