Example usage for org.openqa.selenium.support.ui ExpectedConditions alertIsPresent

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions alertIsPresent

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions alertIsPresent.

Prototype

public static ExpectedCondition<Alert> alertIsPresent() 

Source Link

Usage

From source file:cuenen.raymond.svgplot.SVGPlotterTest.java

License:CDDL license

/**
 * Test for an error when there is no 'function' attribute specified.
 *
 * @param driver The WebDriver executing the test.
 *///w  w  w .  ja va2s .  c  o  m
@Test(dataProvider = "driver", groups = { "all", "alert" })
public void handleNoFunctionTest(WebDriver driver) {
    Wait wait = load(driver, MODULE_LOADER, 1);
    StringBuilder elem = new StringBuilder(CREATE_ELEMENT);
    addAttribute(elem, "samples", "100");
    String callback = String.format(CALLBACK, elem.toString());
    require(driver, callback, MODULE_NAME);
    wait.until(ExpectedConditions.alertIsPresent());
    String alert = getAlert(driver);
    String msg = getMessage(driver);
    assertTrue(alert.startsWith("NotFoundError: Function not set: <plot samples=\"100\" />"),
            msg + " --> " + alert);
}

From source file:io.appium.java_client.ios.iOSGestureTest.java

License:Apache License

@Test
public void TouchActionChainTest() throws InterruptedException {
    WebDriverWait wait = new WebDriverWait(driver, 2);

    WebElement button = driver.findElementsByClassName("UIAButton").get(5);
    TouchAction action = new TouchAction(driver);
    action.press(button).perform();/*ww  w . j  a v  a2s  .c  om*/

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    alert.accept();

    WebElement mapview = driver.findElementByXPath("//UIAWindow[1]/UIAMapView[1]");
    action = new TouchAction(driver);
    action.press(mapview).moveTo(mapview, 0, 100).release().perform();
    Thread.sleep(2000);
}

From source file:io.appium.java_client.ios.iOSGestureTest.java

License:Apache License

@Test
public void MultiGestureTest() throws InterruptedException {
    WebDriverWait wait = new WebDriverWait(driver, 2);

    WebElement button = driver.findElementsByClassName("UIAButton").get(5);
    TouchAction action = new TouchAction(driver);
    action.press(button).perform();/*from  ww w  .j  a v a  2 s.com*/

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    alert.accept();

    WebElement mapview = driver.findElementByXPath("//UIAWindow[1]/UIAMapView[1]");

    MultiTouchAction multiTouch = new MultiTouchAction(driver);
    TouchAction action0 = new TouchAction(driver).press(mapview, 100, 0).moveTo(mapview, 0, -80).release();
    TouchAction action1 = new TouchAction(driver).press(mapview, 100, 50).moveTo(mapview, 0, 80).release();
    multiTouch.add(action0).add(action1).perform();
    Thread.sleep(2000);
}

From source file:io.appium.java_client.ios.iOSGestureTest.java

License:Apache License

@Test
public void ZoomTest() throws InterruptedException {
    WebDriverWait wait = new WebDriverWait(driver, 2);

    WebElement button = driver.findElementsByClassName("UIAButton").get(5);
    TouchAction action = new TouchAction(driver);
    action.press(button).perform();/* ww w  . j av  a 2 s .  c  o m*/

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    alert.accept();

    WebElement mapview = driver.findElementByXPath("//UIAWindow[1]/UIAMapView[1]");

    driver.zoom(mapview);
    Thread.sleep(2000);
}

From source file:io.federecio.dropwizard.swagger.selenium.DefaultServerWithAuthSeleniumTest.java

License:Apache License

private void authenticate(String username) {
    WebDriverWait wait = new WebDriverWait(driver, WAIT_IN_SECONDS);
    Alert alert = wait.until(ExpectedConditions.alertIsPresent());
    alert.sendKeys(username);//from  w ww.  j  a va2s.c om
    alert.accept();
    driver.switchTo().defaultContent();
}

From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java

License:Apache License

@Test
@DisplayName("Kurento reconnect test")
void kurentoReconnectTest() throws Exception {
    isRecordingTest = true;/* www .j a va 2s. c o  m*/
    isKurentoRestartTest = true;

    log.info("Kurento reconnect test");

    List<Session> sessions = OV.getActiveSessions();
    Assert.assertEquals("Expected no active sessions but found " + sessions.size(), 0, sessions.size());

    this.stopKms();

    OV.fetch();

    setupBrowser("chromeAsRoot");

    // Connect one publisher with no connection to KMS

    user.getDriver().findElement(By.id("add-user-btn")).click();
    user.getDriver().findElement(By.className("subscribe-remote-check")).click();
    user.getDriver().findElement(By.className("join-btn")).click();

    user.getWaiter().until(ExpectedConditions.alertIsPresent());
    Alert alert = user.getDriver().switchTo().alert();

    final String alertMessage = "Exception connecting to WebSocket server ws://localhost:8888/kurento";
    Assert.assertTrue("Alert message wrong. Expected to contain: \"" + alertMessage + "\". Actual message: \""
            + alert.getText() + "\"", alert.getText().contains(alertMessage));
    alert.accept();

    user.getDriver().findElement(By.id("remove-user-btn")).sendKeys(Keys.ENTER);

    this.startKms();
    Thread.sleep(3000);

    // Connect one subscriber with connection to KMS -> restart KMS -> connect a
    // publisher -> restart KMS -> check streamDestroyed events

    user.getDriver().findElement(By.id("add-user-btn")).click();
    user.getDriver().findElements(By.className("publish-checkbox")).forEach(el -> el.click());
    user.getDriver().findElement(By.className("join-btn")).click();

    user.getEventManager().waitUntilEventReaches("connectionCreated", 1);

    OV.fetch();
    sessions = OV.getActiveSessions();
    Assert.assertEquals("Expected 1 active sessions but found " + sessions.size(), 1, sessions.size());

    this.restartKms();
    Thread.sleep(3000);

    OV.fetch();
    sessions = OV.getActiveSessions();
    Assert.assertEquals("Expected 1 active sessions but found " + sessions.size(), 1, sessions.size());

    user.getDriver().findElement(By.id("add-user-btn")).click();
    user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .join-btn")).click();

    user.getEventManager().waitUntilEventReaches("connectionCreated", 4);
    user.getEventManager().waitUntilEventReaches("accessAllowed", 1);
    user.getEventManager().waitUntilEventReaches("streamCreated", 2);
    user.getEventManager().waitUntilEventReaches("streamPlaying", 2);

    final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
    Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos);
    Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager()
            .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true));

    OV.fetch();
    Session session = OV.getActiveSessions().get(0);
    Assert.assertEquals("Expected 2 active connections but found " + session.getActiveConnections(), 2,
            session.getActiveConnections().size());
    int pubs = session.getActiveConnections().stream().mapToInt(con -> con.getPublishers().size()).sum();
    int subs = session.getActiveConnections().stream().mapToInt(con -> con.getSubscribers().size()).sum();
    Assert.assertEquals("Expected 1 active publisher but found " + pubs, 1, pubs);
    Assert.assertEquals("Expected 1 active subscriber but found " + subs, 1, subs);

    OV.startRecording(session.getSessionId(),
            new RecordingProperties.Builder().outputMode(OutputMode.INDIVIDUAL).build());
    user.getEventManager().waitUntilEventReaches("recordingStarted", 2);

    long recStartTime = System.currentTimeMillis();

    final CountDownLatch latch = new CountDownLatch(4);

    user.getEventManager().on("recordingStopped", (event) -> {
        String reason = event.get("reason").getAsString();
        Assert.assertEquals("Expected 'recordingStopped' reason 'mediaServerDisconnect'",
                "mediaServerDisconnect", reason);
        latch.countDown();
    });
    user.getEventManager().on("streamDestroyed", (event) -> {
        String reason = event.get("reason").getAsString();
        Assert.assertEquals("Expected 'streamDestroyed' reason 'mediaServerDisconnect'",
                "mediaServerDisconnect", reason);
        latch.countDown();
    });
    this.restartKms();
    long recEndTime = System.currentTimeMillis();
    user.getEventManager().waitUntilEventReaches("recordingStopped", 2);
    user.getEventManager().waitUntilEventReaches("streamDestroyed", 2);
    if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
        gracefullyLeaveParticipants(2);
        fail("Waiting for 2 streamDestroyed events with reason 'mediaServerDisconnect' to happen in total");
        return;
    }
    user.getEventManager().off("streamDestroyed");

    session.fetch();
    Assert.assertEquals("Expected 2 active connections but found " + session.getActiveConnections(), 2,
            session.getActiveConnections().size());
    pubs = session.getActiveConnections().stream().mapToInt(con -> con.getPublishers().size()).sum();
    subs = session.getActiveConnections().stream().mapToInt(con -> con.getSubscribers().size()).sum();
    Assert.assertEquals("Expected no active publishers but found " + pubs, 0, pubs);
    Assert.assertEquals("Expected no active subscribers but found " + subs, 0, subs);

    Recording rec = OV.getRecording("TestSession");
    double differenceInDuration = Math.abs(rec.getDuration() - ((recEndTime - recStartTime) / 1000));
    Assert.assertTrue("Recording duration exceeds valid value. Expected no more than 0.2 seconds, got "
            + differenceInDuration, differenceInDuration < 0.2);

    this.checkIndividualRecording("/opt/openvidu/recordings/TestSession/", rec, 1, "opus", "vp8", true);

    WebElement pubBtn = user.getDriver().findElements(By.cssSelector("#openvidu-instance-1 .pub-btn")).get(0);
    pubBtn.click();
    user.getEventManager().waitUntilEventReaches("streamDestroyed", 3); // This is not real, only in testapp
    pubBtn.click();
    user.getEventManager().waitUntilEventReaches("streamCreated", 4);
    user.getEventManager().waitUntilEventReaches("streamPlaying", 4);

    session.fetch();
    Assert.assertEquals("Expected 2 active connections but found " + session.getActiveConnections(), 2,
            session.getActiveConnections().size());
    pubs = session.getActiveConnections().stream().mapToInt(con -> con.getPublishers().size()).sum();
    subs = session.getActiveConnections().stream().mapToInt(con -> con.getSubscribers().size()).sum();
    Assert.assertEquals("Expected 1 active publisher but found " + pubs, 1, pubs);
    Assert.assertEquals("Expected 1 active subscriber but found " + subs, 1, subs);

    gracefullyLeaveParticipants(2);
}

From source file:io.selendroid.webviewdrivertests.AlertHandlingTest.java

License:Apache License

@Test
public void canHandleChainOfAlerts() {
    driver().executeScript(//from w  ww . ja  va  2 s  . c o  m
            "setTimeout(function(){alert(confirm('really? ' + prompt('testin alerts')));}, 100)");
    Alert a = new WebDriverWait(driver(), 2).until(ExpectedConditions.alertIsPresent());
    Assert.assertEquals("testin alerts", a.getText());
    a.sendKeys("WAT");
    a.accept();
    a = driver().switchTo().alert();
    Assert.assertEquals("really? WAT", a.getText());
    a.dismiss();
    a = driver().switchTo().alert();
    Assert.assertEquals("false", a.getText());
    a.dismiss();
}

From source file:io.selendroid.webviewdrivertests.AlertHandlingTest.java

License:Apache License

@Test
public void blocksOtherCallsWhenAlertPresent() {
    driver().executeScript("setTimeout(function(){alert('alert present');}, 100)");
    Alert a = new WebDriverWait(driver(), 2).until(ExpectedConditions.alertIsPresent());
    Assert.assertEquals("alert present", a.getText());
    try {/*  ww w. ja v a  2  s. c  o  m*/
        driver().findElement(By.linkText("Foo"));
        throw new RuntimeException("should have gotten an UnhandledAlertException");
    } catch (UnhandledAlertException uae) {
        // pass
    } finally {
        a.accept();
    }
}

From source file:modules.sd_uat.pages.CommonPage.java

public void clickOnLogoutLink() throws InterruptedException {
    logoutLink.click();/*  www  . j a  v  a 2  s .co m*/
    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    alert.accept();
    Thread.sleep(5000);
    ReportingTools.takeScreenshot("successfully logged out");
}

From source file:npg.webadmin.acceptance.test.navigation.stepdefs.WebAdminSiteAccountAdminFunctionalDefinitions.java

@When("^user searches site \"([^\"]*)\" with existing active license$")
public void functionalSearchSiteId(String siteId) {
    // to WebAdmin main page
    navigationService.toWebAdminMainPage(webDriver);

    // select 'Main Site License Search
    navigationService.toWebAdminMainSiteLicenseSearch(webDriver);

    // search for Site ID
    navigationService.toWebAdminMainSiteLicenseSearchSiteId(webDriver, siteId);
    try {/*from www  .j a v a  2 s  .c  om*/

        webDriver.findElement(By.xpath(
                "//a[text()[normalize-space(.)='active']][@href='webAdmin.do?initparam=updateSiteAccountStatus&site_account_id="
                        + siteId + "']"));

    } catch (NoSuchElementException e) {

        System.out.println("------ no such element --------");

        webDriver.findElement(By.xpath(
                "//a[contains(text(), 'inactive')][@href='webAdmin.do?initparam=updateSiteAccountStatus&site_account_id="
                        + siteId + "']"))
                .click();

        WebDriverWait wait = new WebDriverWait(webDriver, 10);
        wait.until(ExpectedConditions.alertIsPresent());

        Alert alert = webDriver.switchTo().alert();
        System.out.println("Activate alert box text --------> " + alert.getText() + " ----------");
        alert.accept();
        // go back to search and this time the site is active
        navigationService.toWebAdminMainPage(webDriver);
        navigationService.toWebAdminMainSiteLicenseSearch(webDriver);
        navigationService.toWebAdminMainSiteLicenseSearchSiteId(webDriver, siteId);
    }
}