Example usage for org.openqa.selenium WebDriver close

List of usage examples for org.openqa.selenium WebDriver close

Introduction

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

Prototype

void close();

Source Link

Document

Close the current window, quitting the browser if it's the last window currently open.

Usage

From source file:org.jboss.arquillian.graphene.context.TestGrapheneProxyHandler.java

License:Open Source License

@Test
public void test_webDriver_methods_which_should_not_return_proxy() {
    IsNotProxyable isNotProxyable = new IsNotProxyable();

    // when//w  w w  .ja v a 2  s  .com
    WebDriver driver = Mockito.mock(WebDriver.class, isNotProxyable);
    Options options = mock(Options.class, isNotProxyable);
    Navigation navigation = mock(Navigation.class, isNotProxyable);
    ImeHandler ime = mock(ImeHandler.class, isNotProxyable);
    Logs logs = mock(Logs.class, isNotProxyable);

    // then
    try {
        driver.toString();
        driver.close();
        driver.equals(new Object());
        driver.get("");
        driver.getClass();
        driver.getCurrentUrl();
        driver.getPageSource();
        driver.getTitle();
        driver.getWindowHandle();
        driver.hashCode();
        driver.quit();
        driver.toString();

        options.addCookie(mock(Cookie.class));
        options.deleteAllCookies();
        options.deleteCookie(mock(Cookie.class));
        options.deleteCookieNamed("");
        options.getCookieNamed("");

        navigation.back();
        navigation.forward();
        navigation.to("");
        navigation.to(new URL("http://localhost/"));

        ime.activateEngine("");
        ime.deactivate();
        ime.getActiveEngine();
        ime.isActivated();

        logs.get("");

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    assertEquals(Arrays.asList(), isNotProxyable.getViolations());
}

From source file:org.jitsi.meet.test.FilmstripOnlyTest.java

License:Apache License

/**
 * Checks if device selection popup can load.
 */// www .j av a  2s .  co m
@Test(dependsOnMethods = { "testLoadsOnlyTheFilmstrip" })
public void testDisplaysDeviceSelection() {
    getParticipant1().getToolbar().clickFilmstripOnlySettingsButton();

    // give some time for the window to open and load
    TestUtils.waitMillis(2000);

    WebDriver driver1 = getParticipant1().getDriver();

    Set<String> windowHandles = driver1.getWindowHandles();
    Iterator<String> handleIterator = windowHandles.iterator();
    String mainWindowHandle = handleIterator.next();
    String deviceSelectionHandle = handleIterator.next();

    driver1.switchTo().window(deviceSelectionHandle);

    // Ensure the device selection modal content is displayed.
    TestUtils.waitForDisplayedElementByXPath(driver1, "//div[contains(@class, 'device-selection')]", 5);

    driver1.close();
    driver1.switchTo().window(mainWindowHandle);
}

From source file:org.jitsi.meet.test.InviteTest.java

License:Apache License

/**
 * Checks if clicking to view more numbers shows the appropriate static
 * page./*from  w w  w  .  j  av  a  2 s.co  m*/
 */
@Test(dependsOnMethods = { "testDialInDisplays" })
public void testViewMoreNumbers() {
    InfoDialog infoDialog = participant.getInfoDialog();
    infoDialog.open();

    String displayedNumber = infoDialog.getDialInNumber();
    String displayedPin = infoDialog.getPinNumber();

    infoDialog.openDialInNumbersPage();

    // give some time for the window to open and load
    TestUtils.waitMillis(2000);

    WebDriver driver = participant.getDriver();

    ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
    driver.switchTo().window(tabs.get(1));

    DialInNumbersPage dialInNumbersPage = participant.getDialInNumbersPage();
    dialInNumbersPage.waitForLoad();

    String conferenceIDMessage = dialInNumbersPage.getConferenceIdMessage();

    assert (conferenceIDMessage.contains(displayedPin));
    assert (dialInNumbersPage.includesNumber(displayedNumber));

    driver.close();

    driver.switchTo().window(tabs.get(0));
}

From source file:org.keycloak.testsuite.forms.SSOTest.java

License:Open Source License

@Test
public void multipleSessions() {
    loginPage.open();/*from   w  w w  . j ava 2  s.  c  o  m*/
    loginPage.login("test-user@localhost", "password");

    Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
    Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE));

    Event login1 = events.expectLogin().assertEvent();

    WebDriver driver2 = WebRule.createWebDriver();
    try {
        OAuthClient oauth2 = new OAuthClient(driver2);
        oauth2.state("mystate");
        oauth2.doLogin("test-user@localhost", "password");

        Event login2 = events.expectLogin().assertEvent();

        Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
        Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));

        assertNotEquals(login1.getSessionId(), login2.getSessionId());

        oauth.openLogout();
        events.expectLogout(login1.getSessionId()).assertEvent();

        oauth.openLoginForm();

        assertTrue(loginPage.isCurrent());

        oauth2.openLoginForm();

        events.expectLogin().session(login2.getSessionId()).removeDetail(Details.USERNAME).assertEvent();
        Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
        Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));

        oauth2.openLogout();
        events.expectLogout(login2.getSessionId()).assertEvent();

        oauth2.openLoginForm();

        assertTrue(driver2.getTitle().equals("Log in to test"));
    } finally {
        driver2.close();
    }
}

From source file:org.kurento.room.test.RoomTest.java

License:Open Source License

protected void closeBrowsers() {
    if (!browsersClosed && browsers != null && !browsers.isEmpty()) {
        for (WebDriver browser : browsers)
            if (browser != null)
                try {
                    browser.close();
                    browser.quit();//from   ww  w  . j av a2s  . co  m
                } catch (Exception e) {
                    log.warn("Error closing browser", e);
                    fail("Unable to close browser: " + e.getMessage());
                }
        browsersClosed = true;
    }
}

From source file:org.mozilla.zest.core.v1.ZestClientWindowClose.java

License:Mozilla Public License

@Override
public String invoke(ZestRuntime runtime) throws ZestClientFailException {
    WebDriver wd = runtime.getWebDriver(this.getWindowHandle());

    if (wd == null) {
        // No point throwing an exception as we were going to close it anyway
        return null;
    }//from   ww w.j a v a 2s  .  c om

    // Wait for the specified number of seconds, unless the window closes by itself
    if (this.sleepInSeconds > 0) {
        int sleepInMs = this.sleepInSeconds * 1000;
        while (sleepInMs > 0) {
            wd = runtime.getWebDriver(this.getWindowHandle());
            if (wd == null) {
                break;
            }
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                // Ignore
            }
            sleepInMs -= 200;
        }
    }

    if (wd != null) {
        try {
            wd.close();
        } catch (Exception e) {
            // Ignore, it might have already closed
        }
        runtime.removeWebDriver(getWindowHandle());

        if (runtime.getWebDrivers().size() == 0 && this.getNext() == null) {
            // We've closed all of the windows and this is the last statement
            // Explicitly quit - currently needed for the phantomjs driver, otherwise it never returns :/
            wd.quit();
        }
    }

    return null;
}

From source file:org.orcid.integration.blackbox.api.OauthAuthorizationPageTest.java

License:Open Source License

@Test
public void stateParamIsPersistentAndReurnedWhenAlreadyLoggedInTest()
        throws JSONException, InterruptedException, URISyntaxException {
    WebDriver webDriver = new FirefoxDriver();
    webDriver.get(webBaseUrl + "/userStatus.json?logUserOut=true");
    webDriver.get(webBaseUrl + "/my-orcid");
    // Sign in//from  w  w  w.j av  a  2  s. c o m
    SigninTest.signIn(webDriver, user1UserName, user1Password);
    // Go to the authroization page
    webDriver.get(String.format(
            "%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s&state=%s", webBaseUrl,
            client1ClientId, SCOPES, client1RedirectUri, STATE_PARAM));
    By userIdElementLocator = By.id("authorize");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement authorizeButton = webDriver.findElement(By.id("authorize"));
    authorizeButton.click();
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().equals("ORCID Playground");
        }
    });

    String currentUrl = webDriver.getCurrentUrl();
    Matcher matcher = STATE_PARAM_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String stateParam = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(stateParam));
    assertEquals(STATE_PARAM, stateParam);
    webDriver.close();
}

From source file:org.paxml.selenium.webdriver.WebDriverTag.java

License:Open Source License

public static void unregisterSession(WebDriver wd, boolean forceClose) {
    if (wd == null) {
        throw new RuntimeException("WebDriver cannot be null!");
    }//from   w w  w .  j a v a2 s .c  om
    WebDriverWrapper wp = getSessionWrapper(wd);

    if (forceClose || !wp.keepOnError) {
        wd.close();
    }
    getWebDrivers().remove(wp.index);
}

From source file:org.specrunner.webdriver.actions.PluginClose.java

License:Open Source License

@Override
protected void doEnd(IContext context, IResultSet result, WebDriver client) throws PluginException {
    client.close();
    result.addResult(Success.INSTANCE, context.peek());
}

From source file:org.springframework.springfaces.integrationtest.selenium.PooledWebDriverManager.java

License:Apache License

protected void fullyReleasePool() {
    synchronized (pool) {
        for (WebDriver webDriver : pool) {
            webDriver.close();
        }/*from w w  w  . j  av a 2 s .co m*/
    }
}