Example usage for org.openqa.selenium Alert getText

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

Introduction

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

Prototype

String getText();

Source Link

Usage

From source file:Testregdb1.java

private String closeAlertAndGetItsText() {
    try {/*from  w  ww.ja  va 2s  . 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: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 {/* w w  w  .j  a  v a 2  s .com*/
        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 {/*from w  ww.j a va  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"));
        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 {/* www  .ja  v a2  s  .  c om*/
        // 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:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebDialog.java

License:Open Source License

@Override
public String getText() {
    WebDriver driver = (WebDriver) runner.getDriver();
    Alert dialog = driver.switchTo().alert();
    return dialog.getText();
}

From source file:com.automationpractice.tests.AddTochart.java

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "D:\\selenium test lib\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://automationpractice.com");

    driver.findElement(By.xpath(".//*[@id='homefeatured']/li[1]/div/div[2]/div[2]/a[1]/span")).click();
    driver.findElement(By.xpath(".//*[@id='layer_cart']/div[1]/div[2]/div[4]/a/span")).click();

    if (driver.switchTo().alert() != null) {
        Alert alert = driver.switchTo().alert();
        String alertText = alert.getText();
        alert.dismiss(); // alert.accept();

    }/*w  w  w  . j  av  a 2s  . c  o  m*/

}

From source file:com.cengage.mtx.keywords.MTXLensActivityPageActions.java

public void acceptWarningPopUp() {
    wait.hardWait(2);/*from   ww w. j ava2 s . c  om*/
    Alert alert = driver.switchTo().alert();
    String lensText = alert.getText();
    Assert.assertTrue(lensText.contains(
            "You cannot change your lens at this time because you already submitted the corresponding activity in this unit. You may continue the assignment until completion."),
            "User is able to change lens even if corresponding lens activity is submitted");
    wait.hardWait(2);
    alert.accept();
}

From source file:com.cengage.mtx.keywords.MTXMasteryActivityPageActions.java

public void userEnterBlankAnswersandSubmit() {
    wait.hardWait(2);// w  w  w .  ja v a  2s.  c  o m
    element("submitAns_btn").click();
    Alert warning = driver.switchTo().alert();
    String warning_Msg = warning.getText();
    Assert.assertTrue(warning_Msg.contains("Please enter your response(s) before submitting the question"),
            "Pop-up is not displayed if user submits blank answer");

}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * Method that targets an open alert and selects OK to dismiss it.
 *//* w ww  .  j  a va 2s  .  c  o  m*/
@Override
public void fw_acceptAlert() {
    try {
        log.info("Accepting Alert ...");
        Alert a = webDriver.switchTo().alert();
        String text = a.getText();
        a.accept();
        log.info("Alert Text: " + text);
    } catch (Exception e) {
        log.info(("We are hiding an exception here: " + e.getMessage()));
    }
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

@Override
public void dismissAlert() {
    try {//from  www . j  a v a2s .  com
        Alert a = webDriver.switchTo().alert();
        String text = a.getText();
        a.dismiss();
        log.info("Dismissing alert: " + text);
    } catch (Exception e) {
        log.info(("We are hiding an exception here: " + e.getMessage()));
    }
}