Example usage for org.openqa.selenium WebDriver getTitle

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

Introduction

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

Prototype

String getTitle();

Source Link

Document

Get the title of the current page.

Usage

From source file:org.orcid.api.t2.integration.T2OrcidOAuthApiAuthorizationCodeIntegrationTest.java

License:Open Source License

private String obtainAuthorizationCode(String orcid, String scopes, String redirectUri)
        throws InterruptedException {
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, orcid, scopes, redirectUri));
    WebElement userId = webDriver.findElement(By.id("userId"));
    userId.sendKeys("michael@bentine.com");
    WebElement password = webDriver.findElement(By.id("password"));
    password.sendKeys("password");
    password.submit();//from  w ww . ja v a  2 s.  c om
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            if (d.getCurrentUrl().contains("authorize")) {
                WebElement authorizeButton = d.findElement(By.name("authorize"));
                if (authorizeButton != null) {
                    return true;
                }
            }
            return false;
        }
    });
    WebElement authorizeButton = webDriver.findElement(By.name("authorize"));
    Thread.sleep(3000);
    authorizeButton.submit();
    (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 = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertNotNull(authorizationCode);
    return authorizationCode;
}

From source file:org.orcid.integration.api.test.OauthInvalidRedirectUriTest.java

License:Open Source License

@Test
public void invalidRedirectUriAllowsLoginThenShowErrorTest() throws InterruptedException {
    webDriver.get(String.format(//ww w . j  a va  2  s  .  com
            "%s/oauth/authorize?client_id=9999-9999-9999-9994&response_type=code&scope=/orcid-profile/read-limited&redirect_uri=%s&state=MyState&made_up_param_not_passed=true&other=present",
            webBaseUrl, BAD_REDIRECT_URI));
    // Switch to the login form
    By switchFromLinkLocator = By.id("in-register-switch-form");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator));
    WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator);
    switchFromLink.click();

    // Fill the form
    By userIdElementLocator = By.id("userId");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement userIdElement = webDriver.findElement(userIdElementLocator);
    userIdElement.sendKeys("user_to_test@user.com");
    WebElement passwordElement = webDriver.findElement(By.id("password"));
    passwordElement.sendKeys("password");
    WebElement submitButton = webDriver.findElement(By.id("authorize-button"));
    submitButton.click();
    Thread.sleep(1500);
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().equals("ORCID");
        }
    });
    String currentUrl = webDriver.getCurrentUrl();
    assertTrue(currentUrl.contains("/oauth/error/redirect-uri-mismatch"));
    assertTrue(currentUrl.contains("client_id=9999-9999-9999-9994"));
    assertTrue(currentUrl.contains("response_type=code"));
    assertTrue(currentUrl.contains("redirect_uri=" + BAD_REDIRECT_URI));
    assertTrue(currentUrl.contains("scope=/orcid-profile/read-limited"));
}

From source file:org.orcid.integration.api.test.OauthSignInPersistentParametersTest.java

License:Open Source License

@Test
public void stateParamIsPersistentAndReturnedTest() throws InterruptedException {
    webDriver.get(String.format(/* w  ww .ja  va2 s.  com*/
            "%s/oauth/authorize?client_id=9999-9999-9999-9994&response_type=code&scope=/orcid-profile/read-limited&redirect_uri=%s&state=MyState&made_up_param_not_passed=true&other=present",
            webBaseUrl, redirectUri));
    // Switch to the login form
    By switchFromLinkLocator = By.id("in-register-switch-form");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator));
    WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator);
    switchFromLink.click();

    // Fill the form
    By userIdElementLocator = By.id("userId");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement userIdElement = webDriver.findElement(userIdElementLocator);
    userIdElement.sendKeys("user_to_test@user.com");
    WebElement passwordElement = webDriver.findElement(By.id("password"));
    passwordElement.sendKeys("password");
    WebElement submitButton = webDriver.findElement(By.id("authorize-button"));
    submitButton.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 = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    // Check the auth code is present
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertNotNull(authorizationCode);
    // Check the state param is present
    matcher = STATE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String stateParam = matcher.group(1);
    assertNotNull(stateParam);
    assertEquals("MyState", stateParam);

    matcher = OTHER_PATTERN.matcher(currentUrl);
    assertFalse(matcher.find());
    matcher = MADE_UP_PATTERN.matcher(currentUrl);
    assertFalse(matcher.find());
}

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

License:Open Source License

@Test
public void stateParamIsPersistentAndReturnedOnLoginTest()
        throws JSONException, InterruptedException, URISyntaxException {
    webDriver.get(String.format(//from  w  ww.  j  a va  2  s  .com
            "%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s&state=%s", webBaseUrl,
            client1ClientId, SCOPES, client1RedirectUri, STATE_PARAM));
    By switchFromLinkLocator = By.id("in-register-switch-form");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator));
    WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator);
    switchFromLink.click();

    // Fill the form
    By userIdElementLocator = By.id("userId");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement userIdElement = webDriver.findElement(userIdElementLocator);
    userIdElement.sendKeys(user1UserName);
    WebElement passwordElement = webDriver.findElement(By.id("password"));
    passwordElement.sendKeys(user1Password);
    WebElement submitButton = webDriver.findElement(By.id("authorize-button"));
    submitButton.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);
}

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/* w ww.  j a v 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.orcid.integration.blackbox.api.OauthAuthorizationPageTest.java

License:Open Source License

@Test
public void useAuthorizationCodeWithInalidScopesTest() throws InterruptedException, JSONException {
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, client1ClientId, ScopePathType.ORCID_WORKS_CREATE.getContent(), client1RedirectUri));
    By switchFromLinkLocator = By.id("in-register-switch-form");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator));
    WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator);
    switchFromLink.click();/*from   w w  w  .  j  av a2 s . c  om*/

    // Fill the form
    By userIdElementLocator = By.id("userId");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement userIdElement = webDriver.findElement(userIdElementLocator);
    userIdElement.sendKeys(user1UserName);
    WebElement passwordElement = webDriver.findElement(By.id("password"));
    passwordElement.sendKeys(user1Password);
    WebElement submitButton = webDriver.findElement(By.id("authorize-button"));
    submitButton.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 = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(authorizationCode));

    ClientResponse tokenResponse = getClientResponse(client1ClientId, client1ClientSecret,
            ScopePathType.ORCID_WORKS_UPDATE.getContent(), client1RedirectUri, authorizationCode);

    assertEquals(401, tokenResponse.getStatus());
    OrcidMessage result = tokenResponse.getEntity(OrcidMessage.class);
    assertNotNull(result);
    assertNotNull(result.getErrorDesc());
    assertEquals(
            "OAuth2 problem : Invalid scopes: /orcid-works/update available scopes for this code are: [/orcid-works/create]",
            result.getErrorDesc().getContent());
}

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

License:Open Source License

@Test
public void useAuthorizationCodeWithoutScopesTest() throws InterruptedException, JSONException {
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, client1ClientId, ScopePathType.ORCID_WORKS_CREATE.getContent(), client1RedirectUri));
    By switchFromLinkLocator = By.id("in-register-switch-form");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator));
    WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator);
    switchFromLink.click();//from   w  w  w .  j a v  a 2s. c  o m

    // Fill the form
    By userIdElementLocator = By.id("userId");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement userIdElement = webDriver.findElement(userIdElementLocator);
    userIdElement.sendKeys(user1UserName);
    WebElement passwordElement = webDriver.findElement(By.id("password"));
    passwordElement.sendKeys(user1Password);
    WebElement submitButton = webDriver.findElement(By.id("authorize-button"));
    submitButton.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 = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(authorizationCode));

    ClientResponse tokenResponse = getClientResponse(client1ClientId, client1ClientSecret, null,
            client1RedirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    String body = tokenResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    assertFalse(PojoUtil.isEmpty(accessToken));
}

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

License:Open Source License

@Test
public void skipAuthorizationScreenIfTokenAlreadyExists() throws InterruptedException, JSONException {
    // First get the authorization code
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, client1ClientId, ScopePathType.ORCID_BIO_UPDATE.getContent(), client1RedirectUri));
    By switchFromLinkLocator = By.id("in-register-switch-form");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator));
    WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator);
    switchFromLink.click();/*from  ww w.j  ava  2 s  . c o  m*/

    // Fill the form
    By userIdElementLocator = By.id("userId");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement userIdElement = webDriver.findElement(userIdElementLocator);
    userIdElement.sendKeys(user1UserName);
    WebElement passwordElement = webDriver.findElement(By.id("password"));
    passwordElement.sendKeys(user1Password);
    WebElement submitButton = webDriver.findElement(By.id("authorize-button"));
    submitButton.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 = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(authorizationCode));

    ClientResponse tokenResponse = getClientResponse(client1ClientId, client1ClientSecret,
            ScopePathType.ORCID_BIO_UPDATE.getContent(), client1RedirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    String body = tokenResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    assertFalse(PojoUtil.isEmpty(accessToken));

    // Then, ask again for the same permissions. Note that the user is
    // already logged in
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, client1ClientId, ScopePathType.ORCID_BIO_UPDATE.getContent(), client1RedirectUri));

    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().equals("ORCID Playground");
        }
    });

    currentUrl = webDriver.getCurrentUrl();
    matcher = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    authorizationCode = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(authorizationCode));

    tokenResponse = getClientResponse(client1ClientId, client1ClientSecret,
            ScopePathType.ORCID_BIO_UPDATE.getContent(), client1RedirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    body = tokenResponse.getEntity(String.class);
    jsonObject = new JSONObject(body);
    String otherAccessToken = (String) jsonObject.get("access_token");
    assertNotNull(otherAccessToken);
    assertFalse(PojoUtil.isEmpty(otherAccessToken));
}

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

License:Open Source License

/**
 * Test that asking for different scopes generates different tokens
 * /*from  ww w  . j  a  v a 2 s . co m*/
 * IMPORTANT NOTE: For this test to run, the user should not have tokens for
 * any of the following scopes: - FUNDING_CREATE - AFFILIATIONS_CREATE -
 * ORCID_WORKS_UPDATE
 * */
@Test
public void testDifferentScopesGeneratesDifferentAccessTokens() throws InterruptedException, JSONException {
    revokeApplicationsAccess(client1ClientId);
    // First get the authorization code
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, client1ClientId, ScopePathType.FUNDING_CREATE.getContent(), client1RedirectUri));
    By switchFromLinkLocator = By.id("in-register-switch-form");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(switchFromLinkLocator));
    WebElement switchFromLink = webDriver.findElement(switchFromLinkLocator);
    switchFromLink.click();

    // Fill the form
    By userIdElementLocator = By.id("userId");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    WebElement userIdElement = webDriver.findElement(userIdElementLocator);
    userIdElement.sendKeys(user1UserName);
    WebElement passwordElement = webDriver.findElement(By.id("password"));
    passwordElement.sendKeys(user1Password);
    WebElement submitButton = webDriver.findElement(By.id("authorize-button"));
    submitButton.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 = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(authorizationCode));

    ClientResponse tokenResponse = getClientResponse(client1ClientId, client1ClientSecret,
            ScopePathType.FUNDING_CREATE.getContent(), client1RedirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    String body = tokenResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    assertFalse(PojoUtil.isEmpty(accessToken));

    // Then, ask again for permissions over other scopes. Note that the user
    // is already logged in
    String url = String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, client1ClientId, ScopePathType.AFFILIATIONS_CREATE.getContent(), client1RedirectUri);
    webDriver.get(url);

    By authorizeElementLocator = By.id("authorize");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(authorizeElementLocator));
    WebElement authorizeButton = webDriver.findElement(authorizeElementLocator);
    authorizeButton.click();

    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getCurrentUrl().contains("code=");
        }
    });

    currentUrl = webDriver.getCurrentUrl();
    matcher = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    authorizationCode = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(authorizationCode));

    tokenResponse = getClientResponse(client1ClientId, client1ClientSecret,
            ScopePathType.AFFILIATIONS_CREATE.getContent(), client1RedirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    body = tokenResponse.getEntity(String.class);
    jsonObject = new JSONObject(body);
    String otherAccessToken = (String) jsonObject.get("access_token");
    assertNotNull(otherAccessToken);
    assertFalse(PojoUtil.isEmpty(otherAccessToken));

    assertFalse(otherAccessToken.equals(accessToken));

    // Repeat the process again with other scope
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, client1ClientId, ScopePathType.ORCID_WORKS_UPDATE.getContent(), client1RedirectUri));

    authorizeElementLocator = By.id("authorize");
    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS))
            .until(ExpectedConditions.presenceOfElementLocated(authorizeElementLocator));
    authorizeButton = webDriver.findElement(authorizeElementLocator);
    authorizeButton.click();

    (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getCurrentUrl().contains("code=");
        }
    });

    currentUrl = webDriver.getCurrentUrl();
    matcher = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    authorizationCode = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(authorizationCode));

    tokenResponse = getClientResponse(client1ClientId, client1ClientSecret,
            ScopePathType.ORCID_WORKS_UPDATE.getContent(), client1RedirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    body = tokenResponse.getEntity(String.class);
    jsonObject = new JSONObject(body);
    String otherAccessToken2 = (String) jsonObject.get("access_token");
    assertNotNull(otherAccessToken2);
    assertFalse(PojoUtil.isEmpty(otherAccessToken2));

    assertFalse(otherAccessToken2.equals(accessToken));
    assertFalse(otherAccessToken2.equals(otherAccessToken));
}

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

License:Open Source License

private String getAuthorizationCode() {
    webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s",
            webBaseUrl, client1ClientId, "/activities/update", client1RedirectUri));
    List<WebElement> signInEl = webDriver.findElements(By.id("in-register-switch-form"));
    if (signInEl.size() != 0) {
        signInEl.get(0).click();//from   w  w w .  j  a va 2 s  .co m
        webDriver.findElement(By.id("userId")).sendKeys(user1UserName);
        webDriver.findElement(By.id("password")).sendKeys(user1Password);
        webDriver.findElement(By.id("authorize-button")).click();
    } else {
        webDriver.findElement(By.id("authorize-button")).click();
    }

    (new WebDriverWait(webDriver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().equals("OAuth 2.0 Playground") || d.getTitle().equals("ORCID Playground");
        }
    });
    String currentUrl = webDriver.getCurrentUrl();
    Matcher matcher = Pattern.compile("code=(.+)").matcher(currentUrl);
    assertTrue(matcher.find());
    return matcher.group(1);
}