Search in sources :

Example 21 with Alert

use of org.openqa.selenium.Alert in project acceptance-test-harness by jenkinsci.

the class CapybaraPortingLayerImpl method confirmAlert.

@Override
public void confirmAlert(int timeout) {
    WebDriverWait wait = new WebDriverWait(driver, timeout);
    Alert promptAlert = wait.until(ExpectedConditions.alertIsPresent());
    promptAlert.accept();
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Alert(org.openqa.selenium.Alert)

Example 22 with Alert

use of org.openqa.selenium.Alert in project selenium_java by sergueik.

the class AngularAndWebDriverTest method find_by_angular_partialButtonText.

@Test(enabled = false)
public void find_by_angular_partialButtonText() {
    driver.get("http://localhost:8080/#/form");
    ngWebDriver.waitForAngularRequestsToFinish();
    driver.findElement(ByAngular.partialButtonText("Ale")).click();
    Alert alert = driver.switchTo().alert();
    assertThat(alert.getText(), containsString("Hello"));
    alert.accept();
}
Also used : Alert(org.openqa.selenium.Alert) Test(org.testng.annotations.Test)

Example 23 with Alert

use of org.openqa.selenium.Alert in project selenium_java by sergueik.

the class AngularAndWebDriverTest method find_by_angular_buttonText.

@Test(enabled = false)
public void find_by_angular_buttonText() {
    driver.get("http://localhost:8080/#/form");
    ngWebDriver.waitForAngularRequestsToFinish();
    driver.findElement(ByAngular.buttonText("Open Alert")).click();
    Alert alert = driver.switchTo().alert();
    assertThat(alert.getText(), containsString("Hello"));
    alert.accept();
}
Also used : Alert(org.openqa.selenium.Alert) Test(org.testng.annotations.Test)

Example 24 with Alert

use of org.openqa.selenium.Alert in project selenium_java by sergueik.

the class SeleniumEasyTest method alertConfirmTest.

@Test(enabled = true)
public void alertConfirmTest() {
    // wrong selector
    String buttonSelector = String.format("//*[@id='easycont']//div[@class='panel-heading'][contains(normalize-space(.), '%s')]/..//button", "Java Script Confirm Box");
    try {
        WebElement buttonElement = wait.until(new ExpectedCondition<WebElement>() {

            Predicate<WebElement> textCheck = _element -> {
                String _text = _element.getText();
                System.err.println("in filter: Text = " + _text);
                return (Boolean) (_text.contains("Click me!"));
            };

            @Override
            public WebElement apply(WebDriver d) {
                System.err.println("Locating " + buttonSelector);
                Optional<WebElement> e = d.findElements(By.xpath(buttonSelector)).stream().filter(textCheck).findFirst();
                return (e.isPresent()) ? e.get() : (WebElement) null;
            }
        });
        System.err.println("Acting on: " + buttonElement.getAttribute("outerHTML"));
        highlight(buttonElement);
        flash(buttonElement);
        buttonElement.click();
        sleep(1000);
    } catch (Exception e) {
        System.err.println("Exception: " + e.toString());
        verificationErrors.append("Exception: " + e.toString());
    }
    try {
        // dismiss alert
        driver.switchTo().alert().dismiss();
    } catch (NoAlertPresentException ex) {
    // Alert not present - ignore
    } catch (WebDriverException ex) {
        System.err.println("Alert was not handled : " + ex.getStackTrace().toString());
        return;
    }
    assertThat(driver.findElement(By.id("confirm-demo")).getText(), is(equalTo("You pressed Cancel!")));
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) CoreMatchers(org.hamcrest.CoreMatchers) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) Predicate(java.util.function.Predicate) By(org.openqa.selenium.By) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) BeforeMethod(org.testng.annotations.BeforeMethod) WebElement(org.openqa.selenium.WebElement) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) ITestResult(org.testng.ITestResult) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Optional(java.util.Optional) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Alert(org.openqa.selenium.Alert) Method(java.lang.reflect.Method) WebDriver(org.openqa.selenium.WebDriver) Optional(java.util.Optional) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) WebElement(org.openqa.selenium.WebElement) WebDriverException(org.openqa.selenium.WebDriverException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) WebDriverException(org.openqa.selenium.WebDriverException) Test(org.testng.annotations.Test)

Example 25 with Alert

use of org.openqa.selenium.Alert in project selenium_java by sergueik.

the class AppTest method test13_1.

// NOTE: this test is hanging the jbrowserdriver
// after the test is run orphaned java processess require a taskkill
@Ignore
@Test
public void test13_1() {
    // Arrange
    driver.get("http://suvian.in/selenium/2.3frame.html");
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector(".container .row .intro-message iframe")));
    // Act
    WebElement buttonElement = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector("h3 button"))));
    assertThat(buttonElement, notNullValue());
    buttonElement.click();
    // Assert
    try {
        // confirm alert
        Alert alert = driver.switchTo().alert();
        String alert_text = alert.getText();
        assertThat(alert_text, containsString("You clicked on Green"));
    } catch (NoAlertPresentException e) {
    // Alert not present - ignore
    } catch (WebDriverException e) {
        System.err.println("Alert was not handled : " + e.getStackTrace().toString());
        return;
    }
}
Also used : NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) Alert(org.openqa.selenium.Alert) WebElement(org.openqa.selenium.WebElement) WebDriverException(org.openqa.selenium.WebDriverException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Alert (org.openqa.selenium.Alert)29 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)10 Test (org.junit.Test)7 NoAlertPresentException (org.openqa.selenium.NoAlertPresentException)5 WebDriver (org.openqa.selenium.WebDriver)5 WebElement (org.openqa.selenium.WebElement)5 By (org.openqa.selenium.By)4 WebDriverException (org.openqa.selenium.WebDriverException)4 Test (org.testng.annotations.Test)4 Method (java.lang.reflect.Method)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2 CoreMatchers (org.hamcrest.CoreMatchers)2 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 TimeoutException (org.openqa.selenium.TimeoutException)2 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)2 ExpectedConditions (org.openqa.selenium.support.ui.ExpectedConditions)2 ITestResult (org.testng.ITestResult)2 AfterMethod (org.testng.annotations.AfterMethod)2