Search in sources :

Example 11 with Alert

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

the class ListenableObjectTest method listenableObjectSample.

@Test
public void listenableObjectSample() {
    try {
        ContextAware listenableContextAware = getEventFiringObject(contextAware, emptyWebDriver, contextListener, alertListener);
        WebDriver webDriver = listenableContextAware.context("NATIVE_APP");
        assertTrue(contextAwarePredicate.test(listenableContextAware));
        Alert alert = webDriver.switchTo().alert();
        assertTrue(alertPredicate.test(alert));
        assertTrue(webDriverPredicate.test(getEventFiringWebDriver(webDriver, searchingListener)));
    } finally {
        listeners.get(ContextListener.class).messages.clear();
        listeners.get(AlertListener.class).messages.clear();
        listeners.get(SearchingListener.class).messages.clear();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriverFactory.getEventFiringWebDriver(io.appium.java_client.events.EventFiringWebDriverFactory.getEventFiringWebDriver) ContextAware(org.openqa.selenium.ContextAware) Alert(org.openqa.selenium.Alert) Test(org.junit.Test)

Example 12 with Alert

use of org.openqa.selenium.Alert in project openolat by klemens.

the class QTI12Page method endTest.

public QTI12Page endTest() {
    By endBy = By.cssSelector("div.o_button_group_right a");
    OOGraphene.waitElement(endBy, 5, browser);
    browser.findElement(endBy).click();
    // accept and go further
    Alert alert = browser.switchTo().alert();
    alert.accept();
    OOGraphene.waitAndCloseBlueMessageWindow(browser);
    return this;
}
Also used : By(org.openqa.selenium.By) Alert(org.openqa.selenium.Alert)

Example 13 with Alert

use of org.openqa.selenium.Alert in project ats-framework by Axway.

the class AbstractRealBrowserDriver method handleExpectedPopups.

/**
 * <b>Note:</b> For internal use only
 */
public void handleExpectedPopups() {
    while (!expectedPopupsQueue.isEmpty()) {
        IExpectedPopup expectedPopup = expectedPopupsQueue.poll();
        if (expectedPopup instanceof ExpectedAlert) {
            ExpectedAlert expectedAlert = (ExpectedAlert) expectedPopup;
            new RealHtmlElementState(new RealHtmlAlert(this)).waitToBecomeExisting();
            Alert alert = getAlert();
            if (expectedAlert.expectedText != null && !expectedAlert.expectedText.equals(alert.getText())) {
                throw new VerificationException("The expected alert message was: '" + expectedAlert.expectedText + "', but actually it is: '" + alert.getText() + "'");
            }
            alert.accept();
        } else if (expectedPopup instanceof ExpectedPrompt) {
            ExpectedPrompt expectedPrompt = (ExpectedPrompt) expectedPopup;
            new RealHtmlElementState(new RealHtmlPrompt(this)).waitToBecomeExisting();
            Alert prompt = getAlert();
            if (expectedPrompt.expectedText != null && !expectedPrompt.expectedText.equals(prompt.getText())) {
                throw new VerificationException("The expected prompt text was: '" + expectedPrompt.expectedText + "', but actually it is: '" + prompt.getText() + "'");
            }
            if (expectedPrompt.clickOk) {
                prompt.sendKeys(expectedPrompt.promptValueToSet);
                prompt.accept();
            } else {
                prompt.dismiss();
            }
        } else if (expectedPopup instanceof ExpectedConfirm) {
            ExpectedConfirm expectedConfirm = (ExpectedConfirm) expectedPopup;
            new RealHtmlElementState(new RealHtmlConfirm(this)).waitToBecomeExisting();
            Alert confirm = getAlert();
            if (expectedConfirm.expectedText != null && !expectedConfirm.expectedText.equals(confirm.getText())) {
                throw new VerificationException("The expected confirmation message was: '" + expectedConfirm.expectedText + "', but actually it is: '" + confirm.getText() + "'");
            }
            if (expectedConfirm.clickOk) {
                confirm.accept();
            } else {
                confirm.dismiss();
            }
        }
        UiEngineUtilities.sleep();
    }
}
Also used : RealHtmlElementState(com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState) RealHtmlAlert(com.axway.ats.uiengine.elements.html.realbrowser.RealHtmlAlert) ExpectedConfirm(com.axway.ats.uiengine.internal.realbrowser.ExpectedConfirm) RealHtmlConfirm(com.axway.ats.uiengine.elements.html.realbrowser.RealHtmlConfirm) ExpectedAlert(com.axway.ats.uiengine.internal.realbrowser.ExpectedAlert) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) IExpectedPopup(com.axway.ats.uiengine.internal.realbrowser.IExpectedPopup) ExpectedAlert(com.axway.ats.uiengine.internal.realbrowser.ExpectedAlert) Alert(org.openqa.selenium.Alert) RealHtmlAlert(com.axway.ats.uiengine.elements.html.realbrowser.RealHtmlAlert) RealHtmlPrompt(com.axway.ats.uiengine.elements.html.realbrowser.RealHtmlPrompt) ExpectedPrompt(com.axway.ats.uiengine.internal.realbrowser.ExpectedPrompt)

Example 14 with Alert

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

the class AssetsPageForNodeIT method testAssetPage.

/**
 * Test asset page.
 *
 * @throws Exception the exception
 */
@Test
public void testAssetPage() throws Exception {
    findElementByLink("Asset Info").click();
    Alert alert = m_driver.switchTo().alert();
    alert.accept();
    final String descriptionXpath = "(//input[@ng-model='asset[field.model]'])[1]";
    waitForElement(By.xpath(descriptionXpath));
    WebElement description = findElementByXpath(descriptionXpath);
    Assert.assertNotNull(description);
    Assert.assertEquals("Right here, Right now", description.getAttribute("value"));
}
Also used : Alert(org.openqa.selenium.Alert) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 15 with Alert

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

the class Step method getAlertMessage.

/**
 * @return a String with the message of Alert, return null if no alert message.
 */
protected String getAlertMessage() {
    String msg = null;
    Alert alert = getDriver().switchTo().alert();
    if (alert != null) {
        msg = alert.getText();
        alert.accept();
    }
    return msg;
}
Also used : Alert(org.openqa.selenium.Alert)

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