Example usage for org.openqa.selenium UnhandledAlertException UnhandledAlertException

List of usage examples for org.openqa.selenium UnhandledAlertException UnhandledAlertException

Introduction

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

Prototype

public UnhandledAlertException(String message, String alertText) 

Source Link

Usage

From source file:org.uiautomation.ios.mobileSafari.AlertDetector.java

License:Apache License

@Override
public synchronized void startSearch(int id) throws InterruptedException {
    reset();/*from  w ww  .j av a 2 s. c om*/
    try {
        Thread.sleep(timeBeforeLookingForAlert);
    } catch (InterruptedException ignore) {
        setFinished(true);
        return;
    }

    try {

        if (!stopRequested) {
            log.fine("starting to look for an alert.");
            //driver.switchTo().window(WorkingMode.Native.toString());
            alert = driver.getAlert();
            //driver.switchTo().window(WorkingMode.Web.toString());
            String alertDetails = "no details";
            alertDetails = alert.logElementTree(null, false).toString(2);
            log.fine("found an alert." + alertDetails);
            ex = new UnhandledAlertException("alert present", alertDetails);
        } else {
            throw new InterruptedException("search interrupted. Another finder got a response already.");
        }
    } catch (NoAlertPresentException ex) {
        log.fine("there was no alert.");
    } catch (Exception e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } finally {
        setFinished(true);
    }
}

From source file:org.uiautomation.ios.wkrdp.internal.AlertDetector.java

License:Apache License

@Override
public synchronized void startSearch(int id) throws InterruptedException {
    reset();/*from   w w  w .  j  a v  a2  s  . c o  m*/

    try {
        Thread.sleep(timeBeforeLookingForAlert);
    } catch (InterruptedException ignore) {
        setFinished(true);
        return;
    }

    try {
        while (!stopRequested) {
            try {
                log.fine("starting to look for an alert.");
                //driver.switchTo().window(WorkingMode.Native.toString());
                alert = driver.findElement(new TypeCriteria(UIAAlert.class));
                //driver.switchTo().window(WorkingMode.Web.toString());
                String alertDetails = alert.logElementTree(null, false).toString(2);
                log.fine("found an alert." + alertDetails);
                ex = new UnhandledAlertException("alert present", alertDetails);
                break;
            } catch (NoSuchElementException ex) {
                log.fine("there was no alert.");
            } catch (NoAlertPresentException ex) {
                log.fine("there was no alert.");
            }
        }
    } catch (Exception e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } finally {
        setFinished(true);
    }
}

From source file:ru.stqa.selenium.decorated.alerts.UnhandledAlertHandlingWebDriverTest.java

License:Apache License

@Test
void testAlertIsIgnored() {
    Fixture fixture = new Fixture();
    SimpleUnhandledAlertHandler handler = new SimpleUnhandledAlertHandler();
    fixture.alertHandlingDriver.registerAlertHandler(handler);

    when(fixture.mockedDriver.getTitle())
            .thenThrow(new UnhandledAlertException("Unhandled alert", "Alert text")).thenReturn("Page title");

    String title = fixture.driver.getTitle();
    assertThat(title, is("Page title"));
    assertThat(handler.alertText, is("Alert text"));
}

From source file:ru.stqa.selenium.decorated.alerts.UnhandledAlertHandlingWebDriverTest.java

License:Apache License

@Test
void testSecondAlertIsNotIgnored() {
    Fixture fixture = new Fixture();
    SimpleUnhandledAlertHandler handler = new SimpleUnhandledAlertHandler();
    fixture.alertHandlingDriver.registerAlertHandler(handler);

    when(fixture.mockedDriver.getTitle())
            .thenThrow(new UnhandledAlertException("Unhandled alert", "Alert text 1"))
            .thenThrow(new UnhandledAlertException("Unhandled alert", "Alert text 2"));

    Throwable exception = assertThrows(UnhandledAlertException.class, () -> fixture.driver.getTitle());
    assertThat(((UnhandledAlertException) exception).getAlertText(), is("Alert text 2"));
    assertThat(handler.alertText, is("Alert text 1"));
}