Example usage for org.openqa.selenium WebDriver get

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

Introduction

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

Prototype

void get(String url);

Source Link

Document

Load a new web page in the current browser window.

Usage

From source file:org.springframework.security.samples.pages.HomePage.java

License:Apache License

public static HomePage to(WebDriver driver, int port) {
    driver.get("http://localhost:" + port + "/");
    return PageFactory.initElements(driver, HomePage.class);
}

From source file:org.springframework.security.samples.pages.SecurePage.java

License:Apache License

public static LoginPage to(WebDriver driver, int port) {
    driver.get("http://localhost:" + port + "/secure");
    return PageFactory.initElements(driver, LoginPage.class);
}

From source file:org.springframework.springfaces.integrationtest.selenium.rule.Pages.java

License:Apache License

private <P extends Page> P getPage(Class<P> pageClass, String url) {
    Assert.notNull(pageClass, "PageClass must not be null");
    if (url == null) {
        url = getUrlFromPageClass(pageClass);
    }//w ww  .  j  a v  a2s  .  com
    Assert.state(url != null, "No URL specified for page and unable to deduce a URL from @PageURL annotation");
    url = prefixUrlIfRequired(url);
    WebDriver webDriver = getWebDriver();
    webDriver.get(url);
    return WebDriverUtils.newPage(webDriver, pageClass);
}

From source file:org.structr.web.frontend.selenium.SeleniumTest.java

License:Open Source License

/**
 * Login into the backend UI as admin/admin using the given web driver and switch to the given menu entry.
 *
 * @param menuEntry//  w  w  w.  j av a  2s. com
 * @param driver
 * @param waitForSeconds
 */
protected static void loginAsAdmin(final String menuEntry, final WebDriver driver, final int waitForSeconds) {

    driver.get("http://localhost:8875/structr/#" + menuEntry.toLowerCase());

    final WebDriverWait wait = new WebDriverWait(driver, waitForSeconds);
    //wait.until((ExpectedCondition<Boolean>) (final WebDriver f) -> (Boolean) ((JavascriptExecutor) f).executeScript("LSWrapper.isLoaded()"));

    assertEquals("Username field not found", 1, driver.findElements(By.id("usernameField")).size());
    assertEquals("Password field not found", 1, driver.findElements(By.id("passwordField")).size());
    assertEquals("Login button not found", 1, driver.findElements(By.id("loginButton")).size());

    final WebElement usernameField = wait
            .until(ExpectedConditions.visibilityOfElementLocated(By.id("usernameField")));
    final WebElement passwordField = wait
            .until(ExpectedConditions.visibilityOfElementLocated(By.id("passwordField")));
    final WebElement loginButton = wait
            .until(ExpectedConditions.visibilityOfElementLocated(By.id("loginButton")));

    usernameField.sendKeys("admin");
    passwordField.sendKeys("admin");
    loginButton.click();

    try {

        wait.until(ExpectedConditions.titleIs("Structr " + menuEntry));

    } catch (WebDriverException wex) {

        try {
            Runtime.getRuntime().exec(
                    "/usr/bin/jstack -l $(ps xa|grep structr|grep java|tail -n1|awk '{print $1}') > /tmp/jstack.out."
                            + new Date().getTime());

        } catch (IOException ex1) {
            throw new RuntimeException(ex1);
        }

    } catch (RuntimeException ex) {

        throw ex;
    }

    assertEquals("Structr " + menuEntry, driver.getTitle());
}

From source file:org.suren.autotest.web.framework.driver.DriverTest.java

License:Apache License

@Test
public void htmlUnit() {
    WebDriver driver = new HtmlUnitDriver();
    driver.get("http://surenpi.com");
    driver.quit();//  w  w w.  j av a 2s.  c  o m
}

From source file:org.surfnet.oaaas.selenium.AuthorizationCodeTestIT.java

License:Apache License

@Test
public void authCode() throws Exception {
    String accessTokenRedirectUri = startAuthorizationCallbackServer(clientId, secret);

    WebDriver webdriver = getWebDriver();
    String responseType = "code";
    String scopes = "read,write";
    String url = String.format("%s/oauth2/authorize?response_type=%s&scope=%s&client_id=%s&redirect_uri=%s",
            baseUrl(), responseType, scopes, clientId, accessTokenRedirectUri);
    webdriver.get(url);

    login(webdriver, false);/*from  ww  w  .  j a va  2s .  c  om*/

    // get token response
    String tokenResponse = getAuthorizationCodeRequestHandler().getTokenResponseBlocking();

    AccessTokenResponse accessTokenResponse = getMapper().readValue(tokenResponse, AccessTokenResponse.class);

    assertTrue(StringUtils.isNotBlank(accessTokenResponse.getAccessToken()));
    assertTrue(StringUtils.isBlank(accessTokenResponse.getRefreshToken()));
    assertTrue(StringUtils.isNotBlank(accessTokenResponse.getScope()));
    assertTrue(StringUtils.isNotBlank(accessTokenResponse.getTokenType()));
    assertEquals(accessTokenResponse.getExpiresIn(), 0L);
}

From source file:org.surfnet.oaaas.selenium.AuthorizationCodeTestIT.java

License:Apache License

@Test
public void invalidParams() {
    final WebDriver webdriver = getWebDriver();
    webdriver.get(baseUrlWith("/oauth2/authorize"));

    String pageSource = webdriver.getPageSource();
    assertThat(pageSource, containsString("The supported response_type values are 'token' and 'code'"));
}

From source file:org.surfnet.oaaas.selenium.AuthorizationCodeTestIT.java

License:Apache License

@Test
public void stateParam() throws Exception {
    String accessTokenRedirectUri = startAuthorizationCallbackServer(clientId, secret);
    WebDriver webdriver = getWebDriver();

    /*//  www.jav  a2s.c  o m
    The RFC says (http://tools.ietf.org/html/rfc6749#appendix-A.5):
           state      = 1*VSCHAR
    Defined in http://tools.ietf.org/html/rfc6749#appendix-A:
         VSCHAR     = %x20-7E
            
    The variable 'state' below contains all chars in 0x20-0x7E
     */
    String state = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmno0070pqrstuvwxyz{|}~";
    String url = String.format(
            "%s/oauth2/authorize?response_type=%s&scope=%s&client_id=%s&redirect_uri=%s&state=%s", baseUrl(),
            "code", "read,write", clientId, URLEncoder.encode(accessTokenRedirectUri, "UTF-8"),
            URLEncoder.encode(state, "UTF-8"));
    webdriver.get(url);

    login(webdriver, false);

    // wait for token response to arrive, therefore block
    getAuthorizationCodeRequestHandler().getTokenResponseBlocking();

    String stateFromResponse = getAuthorizationCodeRequestHandler().getAuthorizationResponseState();

    assertEquals("State from response should be equal to provided state", state, stateFromResponse);
}

From source file:org.surfnet.oaaas.selenium.ImplicitGrantTestIT.java

License:Apache License

private void performImplicitGrant(boolean needConsent) {

    WebDriver webdriver = getWebDriver();

    String responseType = "token";
    String clientId = "it-test-client-grant";
    String redirectUri = "http://localhost:8080/fourOhFour";

    String url = String.format("%s/oauth2/authorize?response_type=%s&client_id=%s&redirect_uri=%s", baseUrl(),
            responseType, clientId, redirectUri);
    webdriver.get(url);

    login(webdriver, needConsent);/*from www  . ja  va 2 s  . c  om*/

    // Token response
    URI responseURI = URI.create(webdriver.getCurrentUrl());

    assertThat(responseURI.getFragment(), containsString("access_token="));
    assertThat(responseURI.getPath(), equalTo("/fourOhFour"));
    assertThat(responseURI.getHost(), equalTo("localhost"));
}

From source file:org.surfnet.oaaas.selenium.RefreshTokenTestIT.java

License:Apache License

@Test
public void refreshCode() throws Exception {
    /*/*  ww w .j a  va2  s .  com*/
     * First do a normal authorization and obtain a AccessToken (with refreshToken) 
     */
    String accessTokenRedirectUri = startAuthorizationCallbackServer(clientId, secret);

    restartBrowserSession();
    WebDriver webdriver = getWebDriver();

    String responseType = "code";
    String url = String.format("%s/oauth2/authorize?response_type=%s&client_id=%s&scope=read&redirect_uri=%s",
            baseUrl(), responseType, clientId, accessTokenRedirectUri);
    webdriver.get(url);

    /*
     * Consent is not necessary for this Client
     */
    login(webdriver, false);

    // get token response
    System.out.println("Getting response");
    String tokenResponse = getAuthorizationCodeRequestHandler().getTokenResponseBlocking();
    System.out.println("Got response");

    AccessTokenResponse accessTokenResponse = getMapper().readValue(tokenResponse, AccessTokenResponse.class);

    assertTrue(StringUtils.isNotBlank(accessTokenResponse.getAccessToken()));
    assertTrue(StringUtils.isNotBlank(accessTokenResponse.getRefreshToken()));
    assertTrue(StringUtils.isNotBlank(accessTokenResponse.getScope()));
    assertTrue(StringUtils.isNotBlank(accessTokenResponse.getTokenType()));
    assertTrue(accessTokenResponse.getExpiresIn() > 0);

    String tokenUrl = String.format("%s/oauth2/token", baseUrl());

    final HttpPost tokenRequest = new HttpPost(tokenUrl);

    /*
     * Now make a request for a new AccessToken based on the refreshToken
     */
    String postBody = String.format("grant_type=%s&refresh_token=%s&state=%s",
            OAuth2Validator.GRANT_TYPE_REFRESH_TOKEN, accessTokenResponse.getRefreshToken(), "dummy");

    tokenRequest.setEntity(new ByteArrayEntity(postBody.getBytes()));
    tokenRequest.addHeader("Authorization", AuthorizationCodeTestIT.authorizationBasic(clientId, secret));

    tokenRequest.addHeader("Content-Type", "application/x-www-form-urlencoded");

    HttpResponse tokenHttpResponse = new DefaultHttpClient().execute(tokenRequest);
    final InputStream responseContent = tokenHttpResponse.getEntity().getContent();
    String responseAsString = IOUtils.toString(responseContent);

    AccessTokenResponse refreshTokenResponse = getMapper().readValue(responseAsString,
            AccessTokenResponse.class);

    assertTrue(StringUtils.isNotBlank(refreshTokenResponse.getAccessToken()));
    assertTrue(StringUtils.isNotBlank(refreshTokenResponse.getRefreshToken()));
    assertTrue(StringUtils.isNotBlank(refreshTokenResponse.getScope()));
    assertTrue(StringUtils.isNotBlank(refreshTokenResponse.getTokenType()));
    assertTrue(accessTokenResponse.getExpiresIn() > 0);

    assertNotSame(refreshTokenResponse.getAccessToken(), accessTokenResponse.getAccessToken());
    assertNotSame(refreshTokenResponse.getRefreshToken(), accessTokenResponse.getRefreshToken());
    assertEquals(refreshTokenResponse.getScope(), accessTokenResponse.getScope());
    assertEquals(refreshTokenResponse.getExpiresIn(), accessTokenResponse.getExpiresIn());

}