Search in sources :

Example 1 with Alert

use of org.openqa.selenium.Alert in project opennms by OpenNMS.

the class UserIT method testSubmitWithWrongPassword.

@Test
public void testSubmitWithWrongPassword() throws InterruptedException {
    m_driver.findElement(By.linkText("Change Password")).click();
    enterText(By.cssSelector("input[type=password][name=oldpass]"), "12345");
    enterText(By.cssSelector("input[type=password][name=pass1]"), "23456");
    enterText(By.cssSelector("input[type=password][name=pass2]"), "34567");
    m_driver.findElement(By.cssSelector("button[type=submit]")).click();
    try {
        final Alert alert = wait.until(ExpectedConditions.alertIsPresent());
        alert.dismiss();
    } catch (final Exception e) {
        LOG.debug("Got an exception waiting for a 'wrong password' alert.", e);
        throw e;
    }
}
Also used : Alert(org.openqa.selenium.Alert) Test(org.junit.Test)

Example 2 with Alert

use of org.openqa.selenium.Alert in project opennms by OpenNMS.

the class OutagePageIT method testAllLinks.

@Test
public void testAllLinks() throws InterruptedException {
    findElementByLink("Current outages").click();
    findElementByXpath("//button[contains(@class, 'active') and contains(@onclick, 'current')]");
    findElementByXpath("//button[not(contains(@class, 'active')) and contains(@onclick, 'resolved')]");
    findElementByXpath("//button[not(contains(@class, 'active')) and contains(@onclick, 'both')]");
    findElementByLink("Interface");
    outagePage();
    findElementByLink("All outages").click();
    findElementByXpath("//button[not(contains(@class, 'active')) and contains(@onclick, 'current')]");
    findElementByXpath("//button[not(contains(@class, 'active')) and contains(@onclick, 'resolved')]");
    findElementByXpath("//button[contains(@class, 'active') and contains(@onclick, 'both')]");
    findElementByLink("Interface");
    outagePage();
    findElementByName("outageIdForm").findElement(By.xpath("//button[@type='submit']")).click();
    final Alert alert = wait.until(ExpectedConditions.alertIsPresent());
    assertNotNull(alert);
    assertEquals("Please enter a valid outage ID.", alert.getText());
    alert.dismiss();
}
Also used : Alert(org.openqa.selenium.Alert) Test(org.junit.Test)

Example 3 with Alert

use of org.openqa.selenium.Alert in project page-factory-2 by sbtqa.

the class TagWebDriver method closeAllAlerts.

private static void closeAllAlerts() {
    try {
        LOG.info("Checking any alert opened");
        WebDriverWait alertAwaiter = new WebDriverWait(webDriver, 2);
        alertAwaiter.until(ExpectedConditions.alertIsPresent());
        Alert alert = webDriver.switchTo().alert();
        LOG.info("Got an alert: '{}'. Closing it...", alert.getText());
        alert.dismiss();
    } catch (WebDriverException e) {
        LOG.debug("No alert opened. Closing webdriver...", e);
    }
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Alert(org.openqa.selenium.Alert) WebDriverException(org.openqa.selenium.WebDriverException)

Example 4 with Alert

use of org.openqa.selenium.Alert in project Payara by payara.

the class BaseSeleniumTestClass method closeAlertAndGetItsText.

public String closeAlertAndGetItsText() {
    try {
        Alert alert = driver.switchTo().alert();
        String msg = alert.getText();
        if (acceptNextAlert) {
            alert.accept();
        } else {
            alert.dismiss();
        }
        return msg;
    } finally {
        acceptNextAlert = true;
    }
}
Also used : Alert(org.openqa.selenium.Alert)

Example 5 with Alert

use of org.openqa.selenium.Alert in project keycloak by keycloak.

the class WebAuthnRegisterPage method registerWebAuthnCredential.

public void registerWebAuthnCredential(String authenticatorLabel) {
    if (!isRegisterAlertPresent(ALERT_DEFAULT_TIMEOUT)) {
        throw new TimeoutException("Cannot register Security Key due to missing prompt for registration");
    }
    Alert promptDialog = driver.switchTo().alert();
    promptDialog.sendKeys(authenticatorLabel);
    promptDialog.accept();
    waitForPageToLoad();
}
Also used : Alert(org.openqa.selenium.Alert) TimeoutException(org.openqa.selenium.TimeoutException)

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