Search in sources :

Example 16 with Alert

use of org.openqa.selenium.Alert in project java-client by appium.

the class WebDriverEventListenerCompatibilityTest method alertEventTest.

@Test
public void alertEventTest() {
    try {
        Alert alert = driver.switchTo().alert();
        alert.accept();
        alert.dismiss();
        alert.sendKeys("Keys");
        assertThat(listener.messages, hasItems(WEBDRIVER_EVENT_LISTENER + "Attempt to accept alert", WEBDRIVER_EVENT_LISTENER + "The alert was accepted", WEBDRIVER_EVENT_LISTENER + "Attempt to dismiss alert", WEBDRIVER_EVENT_LISTENER + "The alert was dismissed"));
        assertThat(listener.messages.size(), is(4));
    } finally {
        listener.messages.clear();
    }
}
Also used : Alert(org.openqa.selenium.Alert) Test(org.junit.Test)

Example 17 with Alert

use of org.openqa.selenium.Alert in project opentest by mcdcorp.

the class HandleModal method run.

@Override
public void run() {
    super.run();
    String perform = this.readStringArgument("perform");
    this.waitForAsyncCallsToFinish();
    WebDriverWait wait = new WebDriverWait(this.driver, this.explicitWaitSec);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String text;
    switch(perform.toLowerCase()) {
        case "accept":
            alert.accept();
            break;
        case "dismiss":
            alert.dismiss();
            break;
        case "gettext":
            text = alert.getText();
            this.writeOutput("text", text);
            break;
        case "sendkeys":
            text = this.readStringArgument("text", null);
            String key = this.readStringArgument("key", null);
            if (text != null) {
                alert.sendKeys(text);
            } else if (key != null) {
                String keyString = Keys.valueOf(key.toUpperCase()).toString();
                alert.sendKeys(keyString);
            } else {
                throw new RuntimeException("Neither the \"text\" argument, nor the \"key\" argument were provided.");
            }
            break;
        default:
            throw new RuntimeException("The \"perform\" argument must have one of the following values: accept, " + "authenticate, dismiss, getText, sendKeys, setCredentials.");
    }
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Alert(org.openqa.selenium.Alert)

Example 18 with Alert

use of org.openqa.selenium.Alert in project devonfw-testing by devonfw.

the class ContextMenuPage method isAlertTextValid.

public boolean isAlertTextValid() {
    WebDriverWait wait = new WebDriverWait(BasePage.getDriver(), timeoutInSec);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = BasePage.getDriver().switchTo().alert();
    return alert.getText().equals(expectedAlertText);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Alert(org.openqa.selenium.Alert)

Example 19 with Alert

use of org.openqa.selenium.Alert in project elastest-instrumentation-manager by elastest.

the class EimPluginBaseTest method deletePipelineJob.

protected void deletePipelineJob(WebDriver driver, String jobName) {
    navigateTo(driver, jenkinsCIUrl);
    if (isJobCreated(jobName)) {
        log.info("Deleting Job created for the test");
        log.info("Go inside Pipeline Job");
        getElementByXpath(driver, "//*[@id=\"job_PJob_1\"]/td[3]/a", 30, false).click();
        log.info("Click delete Pipeline Job");
        driver.findElement(By.linkText("Delete Pipeline")).click();
        log.info("Confirm delete Pipeline Job");
        WebDriverWait wait = new WebDriverWait(driver, 30);
        wait.until(ExpectedConditions.alertIsPresent());
        Alert alert = driver.switchTo().alert();
        alert.accept();
    }
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Alert(org.openqa.selenium.Alert)

Example 20 with Alert

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

the class CapybaraPortingLayerImpl method runThenHandleAlert.

public void runThenHandleAlert(Runnable runnable, Consumer<Alert> action, int timeoutSeconds) {
    String oldWindow = driver.getWindowHandle();
    if (runnable != null) {
        runnable.run();
    }
    Wait<WebDriver> wait = new Wait<>(driver, time).pollingEvery(500, TimeUnit.MILLISECONDS).withTimeout(timeoutSeconds, TimeUnit.SECONDS);
    Alert alert = wait.until(ExpectedConditions.alertIsPresent());
    try {
        action.accept(alert);
    } finally {
        driver.switchTo().window(oldWindow);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Alert(org.openqa.selenium.Alert) Wait(org.jenkinsci.test.acceptance.junit.Wait)

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