Example usage for org.openqa.selenium Alert accept

List of usage examples for org.openqa.selenium Alert accept

Introduction

In this page you can find the example usage for org.openqa.selenium Alert accept.

Prototype

void accept();

Source Link

Usage

From source file:Testregdb1.java

private String closeAlertAndGetItsText() {
    try {//from   ww w .  j  a v a  2  s. c  o  m
        Alert alert = driver.switchTo().alert();
        String alertText = alert.getText();
        if (acceptNextAlert) {
            alert.accept();
        } else {
            alert.dismiss();
        }
        return alertText;
    } finally {
        acceptNextAlert = true;
    }
}

From source file:app.Stepdefs.java

private void popup(Boolean accept) {
    long timeout = 5000;
    long waitForAlert = System.currentTimeMillis() + timeout;
    boolean boolFound = false;
    do {//  w  ww .  j  av  a  2 s . c om
        try {
            Alert alert = this.driver.switchTo().alert();
            if (alert != null) {
                if (accept) {
                    alert.accept();
                } // OK is accepted from the popup
                else {
                    alert.dismiss();
                } // Cancel is accepted from the popup
                boolFound = true;
            }
        } catch (NoAlertPresentException ex) {
        }
    } while ((System.currentTimeMillis() < waitForAlert) && (!boolFound));

}

From source file:at.tugraz.ist.catroweb.catroid.ProfileTests.java

License:Open Source License

@Test(dataProvider = "emailTest", groups = { "functionality",
        "visibility" }, description = "check add/delete email")
public void profilePageEmailTest(HashMap<String, String> dataset) throws Throwable {
    try {//ww  w.jav a 2 s.  co  m
        openLocation("registration/");

        driver().findElement(By.id("registrationUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("registrationPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("registrationEmail")).sendKeys(dataset.get("registrationEmail"));
        (new Select(driver().findElement(By.id("registrationCountry"))))
                .selectByValue(dataset.get("registrationCountryID"));
        driver().findElement(By.id("registrationMonth")).sendKeys(dataset.get("registrationMonth"));
        driver().findElement(By.id("registrationYear")).sendKeys(dataset.get("registrationYear"));
        driver().findElement(By.id("registrationGender")).sendKeys(dataset.get("registrationGender"));
        driver().findElement(By.id("registrationSubmit")).click();
        ajaxWait();

        assertTrue(containsElementText(By.xpath("//*[@id='wrapper']/article/header"),
                dataset.get("registrationUsername").toUpperCase()));

        clickOkOnNextConfirmationBox();
        driver().findElement(By.xpath("//*[@id='profileEmail']/input")).clear();
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();
        assertTrue(isTextPresent(
                "Error while updating this e-mail address. You must have at least one validated e-mail address."));

        openLocation("profile/");

        driver().findElement(By.xpath("//*[@id='profileSecondEmail']/input"))
                .sendKeys(dataset.get("registrationEmail"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("This email address already exists."));

        openLocation("profile/");

        driver().findElement(By.xpath("//*[@id='profileSecondEmail']/input"))
                .sendKeys(dataset.get("secondEmail"));
        driver().findElement(By.id("profileSaveChanges")).click();

        Alert alert = driver().switchTo().alert();
        String message = alert.getText();
        alert.accept();
        assertRegExp(".*/emailvalidation.*", message);

        // get validation url and open it
        String validationUrl = getValidationUrl(message);
        openLocation(validationUrl + "_invalid");
        assertTrue(isTextPresent("Recovery hash was not found."));
        openLocation(validationUrl);
        assertTrue(isTextPresent("You have successfully validated your email address."));

        openLocation("profile/");
        ajaxWait();

        clickOkOnNextConfirmationBox();
        driver().findElement(By.xpath("//*[@id='profileEmail']/input")).clear();
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();
        assertTrue(isTextPresent("saved!"));

        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
    } catch (AssertionError e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profilePage." + dataset.get("registrationUsername"));
        throw e;
    } catch (Exception e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profilePage." + dataset.get("registrationUsername"));
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.RegistrationTests.java

License:Open Source License

@Test(dataProvider = "triggerErrorsData", groups = {
        "functionality" }, description = "trigger all error messages and check whether they present")
public void checkErrorMessages(HashMap<String, String> dataset) throws Throwable {
    try {/*w ww  . j  a v a2  s  . co m*/
        openLocation("registration/");

        driver().findElement(By.id("registrationUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("registrationPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("registrationEmail")).sendKeys(dataset.get("registrationEmail"));
        driver().findElement(By.id("registrationCountry")).sendKeys(dataset.get("registrationCountry"));
        driver().findElement(By.id("registrationMonth")).sendKeys(dataset.get("registrationMonth"));
        driver().findElement(By.id("registrationYear")).sendKeys(dataset.get("registrationYear"));
        driver().findElement(By.id("registrationGender")).sendKeys(dataset.get("registrationGender"));
        driver().findElement(By.id("registrationSubmit")).click();

        Alert alert = driver().switchTo().alert();
        String message = alert.getText().replace("<", "&lt;").replace(">", "&gt;");
        alert.accept();
        assertTrue(message.contains(dataset.get("expectedError")));
    } catch (AssertionError e) {
        captureScreen("RegistrationTests.checkElementsVisible." + CommonFunctions.getTimeStamp());
        throw e;
    } catch (Exception e) {
        captureScreen("RegistrationTests.checkElementsVisible." + CommonFunctions.getTimeStamp());
        throw e;
    }
}

From source file:at.tugraz.ist.catroweb.catroid.RegistrationTests.java

License:Open Source License

@Test(dataProvider = "invalidRegistrationData", groups = { "functionality",
        "popupwindows" }, description = "check registration with invalid data")
public void invalidRegistration(HashMap<String, String> dataset) throws Throwable {
    try {//from w w  w  .  j a  v  a 2  s . co  m
        // wiki username creation
        String wikiUsername = dataset.get("registrationUsername").substring(0, 1).toUpperCase()
                + dataset.get("registrationUsername").substring(1).toLowerCase();

        openLocation("registration/");

        driver().findElement(By.id("registrationUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("registrationPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("registrationEmail")).sendKeys(dataset.get("registrationEmail"));
        driver().findElement(By.id("registrationMonth")).sendKeys(dataset.get("registrationMonth"));
        driver().findElement(By.id("registrationYear")).sendKeys(dataset.get("registrationYear"));
        driver().findElement(By.id("registrationGender")).sendKeys(dataset.get("registrationGender"));
        driver().findElement(By.id("registrationCountry")).sendKeys(dataset.get("registrationCountry"));
        driver().findElement(By.id("registrationCity")).sendKeys(dataset.get("registrationCity"));
        driver().findElement(By.id("registrationSubmit")).click();

        Alert alert = driver().switchTo().alert();
        String message = alert.getText().replace("<", "&lt;").replace(">", "&gt;");
        alert.accept();
        assertTrue(message.contains(dataset.get("expectedError")));
    } catch (AssertionError e) {
        captureScreen("RegistrationTests.invalidRegistration." + dataset.get("registrationUsername"));
        throw e;
    } catch (Exception e) {
        captureScreen("RegistrationTests.invalidRegistration." + dataset.get("registrationUsername"));
        throw e;
    }
}

From source file:cc.kune.selenium.KuneSeleniumDefaults.java

License:GNU Affero Public License

/**
 * Answer on next prompt./*from w  w  w  .j  a v  a2  s  . c  o m*/
 * 
 * @param answer
 *          the answer
 */
public void answerOnNextPrompt(final String answer) {
    final Alert alert = webdriver.switchTo().alert();
    alert.sendKeys(answer);
    sleep(2000);
    alert.accept();
}

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

License:Apache License

/**
 * {@inheritDoc}/*from ww  w  .j  a  va  2 s  . 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.autocognite.appium.lib.base.AbstractAppiumUiDriver.java

License:Apache License

public void confirmAlertIfPresent() {
    AppiumDriver<MobileElement> d = getDriver();
    try {/*  ww w. j  a va2s . co  m*/
        Alert alert = d.switchTo().alert();
        alert.accept();
        d.switchTo().defaultContent();
    } catch (Exception e) { // ignore
    }
}

From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

public void confirmAlertIfPresent() {
    WebDriver d = getDriver();// w  w w.java  2s. co  m
    try {
        Alert alert = d.switchTo().alert();
        alert.accept();
        d.switchTo().defaultContent();
    } catch (Exception e) { // ignore
    }
}

From source file:com.cengage.mindtap.keywords.BasePageActions.java

/**
* Accept alert window.//from   www .  j  a va  2  s . c o  m
*/
void acceptAlertWindow() {
    try {
        Alert alert = driver.switchTo().alert();
        alert.accept();
    } catch (Exception e) {
    }
}