List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)
From source file:org.orcid.api.common.WebDriverHelper.java
License:Open Source License
public String obtainAuthorizationCode(String scopes, String orcid, String userId, String password, List<String> inputIdsToCheck, boolean markAsSelected) throws InterruptedException { webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s", webBaseUrl, orcid, scopes, 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();/*from w w w. ja v a 2 s . c om*/ // Check the given inputs if (inputIdsToCheck != null && !inputIdsToCheck.isEmpty()) { for (String id : inputIdsToCheck) { By input = By.id(id); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(input)); WebElement inputElement = webDriver.findElement(input); if (markAsSelected) { if (!inputElement.isSelected()) inputElement.click(); } else { if (inputElement.isSelected()) inputElement.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(userId); 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); 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(//w ww .j av a2 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(//from w w w . j a va 2s .co m "%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.api.test.PersistentTokensIntegrationTest.java
License:Open Source License
@Test public void persistentTokenCheckboxNotVisibleWhenPersistentTokensIsDisabledOnClient() { webDriver.get(String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s", webBaseUrl, NO_PERSISTENT_TOKEN_CLIENT_DETAILS_ID, "/orcid-bio/read-limited", redirectUri)); // Switch to the login form By scopesUl = By.id("scopes-ul"); By switchFromLinkLocator = By.id("enablePersistentToken"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(scopesUl)); try {/*from w ww . j a v a2s.c o m*/ webDriver.findElement(switchFromLinkLocator); fail("Element enablePersistentToken should not be displayed"); } catch (NoSuchElementException e) { } }
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(/* w w w . j a v a2s . c o m*/ "%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 w w . ja v a2 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 invalidRedirectUriAllowsLoginThenShowErrorTest() throws InterruptedException { String invalidRedirectUri = "http://www.orcid.org/worng/redirect/uri"; webDriver.get(String.format(// www . j a v a2s .co m "%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s&state=%s", webBaseUrl, client1ClientId, SCOPES, invalidRedirectUri, 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.getCurrentUrl().contains("/oauth/error/redirect-uri-mismatch"); } }); String currentUrl = webDriver.getCurrentUrl(); assertTrue("URL is:" + currentUrl, currentUrl.contains("/oauth/error/redirect-uri-mismatch")); assertTrue("URL is:" + currentUrl, currentUrl.contains("client_id=" + client1ClientId)); assertTrue("URL is:" + currentUrl, currentUrl.contains("response_type=code")); assertTrue("URL is:" + currentUrl, currentUrl.contains("redirect_uri=" + invalidRedirectUri)); assertTrue("URL is:" + currentUrl, currentUrl.contains("scope=")); }
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 ww .j av a 2 s.com // 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();//ww w. j a va 2s . 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, 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 w w w . j av a 2 s . co 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)); }