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

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

Introduction

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

Prototype

public static ExpectedCondition<Alert> alertIsPresent() 

Source Link

Usage

From source file:be.rubus.web.testing.widget.AlertHandling.java

License:Apache License

public AlertHandling checkForAlert() {
    WebDriverWait wait = new WebDriverWait(driver, 5);
    if (wait.until(ExpectedConditions.alertIsPresent()) == null) {

        fail("Alert not showing as feedback for user");
    }/* w ww.j a v  a  2s.c  om*/
    return this;
}

From source file:be.rubus.web.testing.widget.AlertHandling.java

License:Apache License

public void checkForNoAlert() {
    WebDriverWait wait = new WebDriverWait(driver, 5);
    try {//from  w  w w  . jav  a 2  s.  c  o  m
        wait.until(ExpectedConditions.alertIsPresent());
        fail("Alert is showing and not expected to popup");
    } catch (TimeoutException te) {

        ; // OK we don't want to see the alert
    }

}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Interact.java

License:Apache License

/**
 * {@inheritDoc}/*from  ww  w .  j  a v a 2s  . c o  m*/
 */
@Override
public Interact handleAlert(boolean accept) {
    try {
        new WebDriverWait(((SeleniumContext<WebDriver>) context().getCurrentContext()).getDriver(),
                DriverConfig.DEFAULT_IMPL_WAIT).until(ExpectedConditions.alertIsPresent());
        Alert alert = ((SeleniumContext<WebDriver>) context().getCurrentContext()).getDriver().switchTo()
                .alert();
        if (accept)
            alert.accept();
        else
            alert.dismiss();

    } catch (NoAlertPresentException e) {

    }

    return this;
}

From source file:com.cisco.dbds.utils.selenium.SeleniumUtilities.java

License:Open Source License

/**
 * waits for the alert./*from w ww.  j  av  a  2  s .c  o m*/
 */
public static void waitForAlert() {
    WebDriverWait wait = new WebDriverWait(getDriver(), Integer.parseInt(System.getProperty("explicit.wait")));
    wait.until(ExpectedConditions.alertIsPresent());

}

From source file:com.cisco.dbds.utils.selenium.SeleniumUtilities.java

License:Open Source License

/**
 * Returns true if alert is present else false.
 * /*from   ww  w.  ja v  a  2  s  .  c  om*/
 * @return true, if is alert present
 */
public static boolean isAlertPresent() {
    boolean isPresent = false;
    if (ExpectedConditions.alertIsPresent().apply(getDriver()) != null) {
        isPresent = true;
        LogHandler.info("Alert Message is:" + getDriver().switchTo().alert().getText().trim());
    }

    return isPresent;
}

From source file:com.comcast.dawg.selenium.SeleniumWaiter.java

License:Apache License

/**
 * Wait for the presence of alert./*from   w  w  w .jav  a  2s. com*/
 *
 * @param  timeoutInSec  timeout in seconds.
 */
public void waitForAlertPresence(int timeoutInSec) {
    WebDriverWait wait = new WebDriverWait(driver, timeoutInSec);
    wait.until(ExpectedConditions.alertIsPresent());
}

From source file:com.denimgroup.threadfix.selenium.pages.BasePage.java

License:Mozilla Public License

protected void handleAlert() {
    sleep(3000);/*from  w  w w  .  j  a v  a 2 s.com*/
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    alert.accept();
    sleep(200);
    //      sleep(1000);
}

From source file:com.ecofactor.qa.automation.insite.page.RoleManagementImpl.java

License:Open Source License

/**
 * <p>/*from  w  w w.j  a va 2  s  .  co m*/
 * Click on Save button and wait for alert to be popped.The verify the page is redirected
 * properly.
 * </p>
 * @param driver the driver
 * @param roleName the role name
 */
private void saveAndVerifyRole(final WebDriver driver, final String roleName) {

    DriverConfig.setLogString(
            "Click on save link and verify the alert is popped, finally check the page is re-directed properly.",
            true);
    final WebElement saveElement = retrieveElementByLinkText(driver, "Save", SHORT_TIMEOUT);
    saveElement.click();

    (new WebDriverWait(driver, LONG_TIMEOUT + LONG_TIMEOUT)).until(ExpectedConditions.alertIsPresent());
    DriverConfig.setLogString("click ok on alert message.", true);
    logger.info("click ok on alert message.");
    DriverConfig.setLogString("Alert Message :" + driver.switchTo().alert().getText(), true);
    waitUntil(FIVE_SECS);
    driver.switchTo().alert().accept();

    /*
     * retrieveElementByLinkText(driver, "First", SHORT_TIMEOUT); Assert.assertEquals(true,
     * driver.getCurrentUrl().contains("roles.html"), "Url doesn't contains roles.html");
     */
    smallWait();
    logger.info("find role name element is displayed.");
    DriverConfig.setLogString("find role name element is displayed.", true);
    isDisplayedById(driver, roleConfig.get(ROLE_NAME), SHORT_TIMEOUT);
    DriverConfig.setLogString("Enter role name as " + roleName, true);
    driver.findElement(By.id(roleConfig.get(ROLE_NAME))).sendKeys(roleName);
    DriverConfig.setLogString("check if find button is displayed & click it.", true);
    final WebElement findButtonElement = retrieveElementByAttributeValue(driver, TAG_INPUT, ATTR_VALUE,
            roleConfig.get(FIND_BUTTON));
    findButtonElement.click();
    DriverConfig.setLogString("check if search result is displayed.", true);
    confirmSearchResultValue(driver, roleName);
}

From source file:com.ecofactor.qa.automation.insite.page.UserManagementImpl.java

License:Open Source License

/**
 * <p>//w  ww  .j  a  v  a  2  s.com
 * Click on save button and verify the required mesaage is displayed in the alert. And check the
 * page is recirected to properly.
 * </p>
 */
public void saveUsermanagement() {

    smallWait();
    DriverConfig.setLogString("Click Save and Verify the page is redirected properly.", true);
    final WebElement saveElement = retrieveElementByLinkText(DriverConfig.getDriver(), "Save", SHORT_TIMEOUT);
    saveElement.click();
    (new WebDriverWait(DriverConfig.getDriver(), LONG_TIMEOUT + LONG_TIMEOUT))
            .until(ExpectedConditions.alertIsPresent());
    DriverConfig.setLogString("check user created message displayed.", true);
    // commented to close alert.
    // assertEquals(true,
    // DriverConfig.getDriver().switchTo().alert().getText().equalsIgnoreCase(userConfig.get(USER_SAVED_ALERT_MSG)),
    // "User created message is not available");
    logger.info("click ok on alert message.", true);
    // fix to close the invalid alert message issue
    closeAlert(DriverConfig.getDriver());

    retrieveElementByLinkText(DriverConfig.getDriver(), "First", MEDIUM_TIMEOUT);
    DriverConfig.setLogString("check if user management page is displayed after user creation.", true);
    assertEquals(true, DriverConfig.getDriver().getCurrentUrl().contains("usermgmt.html"), "Url is different");
}

From source file:com.ecofactor.qa.automation.platform.action.impl.DesktopUIAction.java

License:Open Source License

/**
 * Accept alert./*from   w  w  w .ja  v  a  2s .c  om*/
 * @see com.ecofactor.qa.automation.mobile.action.UIAction#acceptAlert()
 */
@Override
public void acceptAlert() {

    try {
        final WebDriverWait wait = new WebDriverWait(driverOps.getDeviceDriver(), SHORT_TIMEOUT);
        if (wait.until(ExpectedConditions.alertIsPresent()) != null) {
            driverOps.getDeviceDriver().switchTo().alert().accept();
        }
    } catch (final Exception e) {
        LOGGER.error("Error in acceptAlert(). Cause ::: " + e);
    }
}