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.integration.blackbox.api.OauthAuthorizationPageTest.java
License:Open Source License
/** * Test that asking for different scopes generates different tokens * //from w w w .ja v a 2s . c om * 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.PopulateOAuthSignInCodeIntegrationTest.java
License:Open Source License
@Test public void checkNoPrePop() throws JSONException, InterruptedException { webDriver.get(authorizeScreen);// w w w .j a v a 2 s .c o m // make sure we are on the page By element = By.xpath("//input[@name='email']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(By.xpath("//input[@name='email']")).getAttribute("value").equals("")); assertTrue( webDriver.findElement(By.xpath("//input[@name='familyNames']")).getAttribute("value").equals("")); assertTrue(webDriver.findElement(By.xpath("//input[@name='givenNames']")).getAttribute("value").equals("")); // verify we don't populate signin assertTrue(webDriver.findElement(By.xpath("//input[@name='userId']")).getAttribute("value").equals("")); }
From source file:org.orcid.integration.blackbox.api.PopulateOAuthSignInCodeIntegrationTest.java
License:Open Source License
@Test public void emailPrePopulate() throws JSONException, InterruptedException { // test populating form with email that doesn't exist String url = authorizeScreen/* w w w . java 2s .c o m*/ + "&email=non_existent@test.com&family_names=test_family_names&given_names=test_given_name"; webDriver.get(url); By element = By.xpath("//input[@name='email']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals("non_existent@test.com")); assertTrue(webDriver.findElement(By.xpath("//input[@name='familyNames']")).getAttribute("value") .equals("test_family_names")); assertTrue(webDriver.findElement(By.xpath("//input[@name='givenNames']")).getAttribute("value") .equals("test_given_name")); // verify we don't populate signin assertTrue(webDriver.findElement(By.xpath("//input[@name='userId']")).getAttribute("value").equals("")); // test existing email url = authorizeScreen + "&email=" + user1UserName + "&family_names=test_family_names&given_names=test_given_name"; webDriver.get(url); element = By.xpath("//input[@name='userId']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals(user1UserName)); // make sure register assertTrue(webDriver.findElement(By.xpath("//input[@name='email']")).getAttribute("value").equals("")); // populating check populating orcid url = authorizeScreen + "&email=spike@milligan.com&family_names=test_family_names&given_names=test_given_name&orcid=" + user1OrcidId; webDriver.get(url); element = By.xpath("//input[@name='userId']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals(user1OrcidId)); }
From source file:org.orcid.integration.blackbox.api.PopulateOAuthSignInCodeIntegrationTest.java
License:Open Source License
@Test public void emailPrePopulateWithHtmlEncodedEmail() throws JSONException, InterruptedException { String scapedEmail = StringEscapeUtils.escapeHtml4(user1UserName); // test populating form with email that doesn't exist String url = authorizeScreen//from w w w . java 2s.com + "&email=non_existent%40test.com&family_names=test_family_names&given_names=test_given_name"; webDriver.get(url); By element = By.xpath("//input[@name='email']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals("non_existent@test.com")); assertTrue(webDriver.findElement(By.xpath("//input[@name='familyNames']")).getAttribute("value") .equals("test_family_names")); assertTrue(webDriver.findElement(By.xpath("//input[@name='givenNames']")).getAttribute("value") .equals("test_given_name")); // verify we don't populate signin assertTrue(webDriver.findElement(By.xpath("//input[@name='userId']")).getAttribute("value").equals("")); // test existing email url = authorizeScreen + "&email=" + scapedEmail + "&family_names=test_family_names&given_names=test_given_name"; webDriver.get(url); element = By.xpath("//input[@name='userId']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals(scapedEmail)); // make sure register assertTrue(webDriver.findElement(By.xpath("//input[@name='email']")).getAttribute("value").equals("")); // populating check populating orcid url = authorizeScreen + "&email=" + scapedEmail + "&family_names=test_family_names&given_names=test_given_name&orcid=" + user1OrcidId; webDriver.get(url); element = By.xpath("//input[@name='userId']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals(user1OrcidId)); }
From source file:org.orcid.integration.blackbox.api.PopulateOAuthSignInCodeIntegrationTest.java
License:Open Source License
@Test public void orcidIdPrePopulate() throws JSONException, InterruptedException { // populating check populating orcid String url = authorizeScreen + "&orcid=" + user1OrcidId; webDriver.get(url);// www. j ava 2s . c o m By element = By.xpath("//input[@name='userId']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals(user1OrcidId)); // populating check populating orcid overwrites populating email webDriver.get(authorizeScreen + "&email=spike@milligan.com&family_names=test_family_names&given_names=test_given_name&orcid=" + user1OrcidId); element = By.xpath("//input[@name='userId']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals(user1OrcidId)); }
From source file:org.orcid.integration.blackbox.api.PopulateOAuthSignInCodeIntegrationTest.java
License:Open Source License
@Test public void orcidIdPreopulateWithHtmlEncodedOrcid() throws JSONException, InterruptedException { // populating check populating orcid String encodedOrcid = StringEscapeUtils.escapeHtml4(user1OrcidId); String url = authorizeScreen + "&orcid=" + encodedOrcid; webDriver.get(url);//from w ww . j av a2s .co m By element = By.xpath("//input[@name='userId']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals(user1OrcidId)); // populating check populating orcid overwrites populating email webDriver.get(authorizeScreen + "&email=spike@milligan.com&family_names=test_family_names&given_names=test_given_name&orcid=" + user1OrcidId); element = By.xpath("//input[@name='userId']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals(user1OrcidId)); }
From source file:org.orcid.integration.blackbox.api.PopulateOAuthSignInCodeIntegrationTest.java
License:Open Source License
@Test public void givenAndFamilyNamesPrepopulate() throws JSONException, InterruptedException { // test populating form family and given names String url = authorizeScreen + "&family_names=test_family_names&given_names=test_given_name"; webDriver.get(url);//from ww w.j av a 2 s. c o m By element = By.xpath("//input[@name='familyNames']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals("test_family_names")); element = By.xpath("//input[@name='givenNames']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals("test_given_name")); // verify we don't populate signin element = By.xpath("//input[@name='userId']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals("")); // test populating form with family name url = authorizeScreen + "&family_names=test_family_names"; webDriver.get(url); element = By.xpath("//input[@name='familyNames']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals("test_family_names")); // test populating form with given name url = authorizeScreen + "&given_names=test_given_names"; webDriver.get(url); element = By.xpath("//input[@name='givenNames']"); (new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS)) .until(ExpectedConditions.presenceOfElementLocated(element)); assertTrue(webDriver.findElement(element).getAttribute("value").equals("test_given_names")); }
From source file:org.orcid.integration.blackbox.api.v2.rc1.BlackBoxBase.java
License:Open Source License
public static void revokeApplicationsAccess(String... clientIdsParam) { // Nothing to remove if (clientIdsParam == null) { return;//w ww. j a v a2s. c om } List<String> clientIds = new ArrayList<String>(); for (String clientId : clientIdsParam) { if (!PojoUtil.isEmpty(clientId)) { clientIds.add(clientId); } } String userName = System.getProperty("org.orcid.web.testUser1.username"); String password = System.getProperty("org.orcid.web.testUser1.password"); String baseUrl = "https://localhost:8443/orcid-web"; if (!PojoUtil.isEmpty(System.getProperty("org.orcid.web.base.url"))) { baseUrl = System.getProperty("org.orcid.web.base.url"); } WebDriver webDriver = new FirefoxDriver(); int timeout = 4; webDriver.get(baseUrl + "/userStatus.json?logUserOut=true"); webDriver.get(baseUrl + "/my-orcid"); SigninTest.signIn(webDriver, userName, password); // Switch to accounts settings page By accountSettingsMenuLink = By.id("accountSettingMenuLink"); (new WebDriverWait(webDriver, timeout)) .until(ExpectedConditions.presenceOfElementLocated(accountSettingsMenuLink)); WebElement menuItem = webDriver.findElement(accountSettingsMenuLink); menuItem.click(); try { boolean lookAgain = false; do { // Look for each revoke app button By revokeAppBtn = By.id("revokeAppBtn"); (new WebDriverWait(webDriver, timeout)) .until(ExpectedConditions.presenceOfElementLocated(revokeAppBtn)); List<WebElement> appsToRevoke = webDriver.findElements(revokeAppBtn); boolean elementFound = false; // Iterate on them and delete the ones created by the specified // client id for (WebElement appElement : appsToRevoke) { String nameAttribute = appElement.getAttribute("name"); if (clientIds.contains(nameAttribute)) { appElement.click(); Thread.sleep(1000); // Wait for the revoke button By confirmRevokeAppBtn = By.id("confirmRevokeAppBtn"); (new WebDriverWait(webDriver, timeout)) .until(ExpectedConditions.presenceOfElementLocated(confirmRevokeAppBtn)); WebElement trash = webDriver.findElement(confirmRevokeAppBtn); trash.click(); Thread.sleep(2000); elementFound = true; break; } } if (elementFound) { lookAgain = true; } else { lookAgain = false; } } while (lookAgain); } catch (Exception e) { // If it fail is because it couldnt find any other application } finally { webDriver.get(baseUrl + "/userStatus.json?logUserOut=true"); webDriver.quit(); } }
From source file:org.orcid.integration.blackbox.api.v2.rc2.BlackBoxBase.java
License:Open Source License
public static void revokeApplicationsAccess(String... clientIdsParam) { // Nothing to remove if (clientIdsParam == null) { return;//from w w w. ja v a 2 s.c o m } List<String> clientIds = new ArrayList<String>(); for (String clientId : clientIdsParam) { if (!PojoUtil.isEmpty(clientId)) { clientIds.add(clientId); } } String userName = System.getProperty("org.orcid.web.testUser1.username"); String password = System.getProperty("org.orcid.web.testUser1.password"); String baseUrl = "https://localhost:8443/orcid-web"; if (!PojoUtil.isEmpty(System.getProperty("org.orcid.web.base.url"))) { baseUrl = System.getProperty("org.orcid.web.base.url"); } WebDriver webDriver = new FirefoxDriver(); int timeout = 4; webDriver.get(baseUrl + "/userStatus.json?logUserOut=true"); webDriver.get(baseUrl + "/my-orcid"); SigninTest.signIn(webDriver, userName, password); // Switch to accounts settings page By accountSettingsMenuLink = By.id("accountSettingMenuLink"); (new WebDriverWait(webDriver, timeout)) .until(ExpectedConditions.presenceOfElementLocated(accountSettingsMenuLink)); WebElement menuItem = webDriver.findElement(accountSettingsMenuLink); menuItem.click(); try { boolean lookAgain = false; do { // Look for each revoke app button By revokeAppBtn = By.id("revokeAppBtn"); (new WebDriverWait(webDriver, timeout)) .until(ExpectedConditions.presenceOfElementLocated(revokeAppBtn)); List<WebElement> appsToRevoke = webDriver.findElements(revokeAppBtn); boolean elementFound = false; // Iterate on them and delete the ones created by the specified // client id for (WebElement appElement : appsToRevoke) { String nameAttribute = appElement.getAttribute("name"); if (clientIds.contains(nameAttribute)) { appElement.click(); Thread.sleep(1000); // Wait for the revoke button By confirmRevokeAppBtn = By.id("confirmRevokeAppBtn"); (new WebDriverWait(webDriver, timeout)) .until(ExpectedConditions.presenceOfElementLocated(confirmRevokeAppBtn)); WebElement trash = webDriver.findElement(confirmRevokeAppBtn); trash.click(); Thread.sleep(2000); elementFound = true; break; } } if (elementFound) { lookAgain = true; } else { lookAgain = false; } } while (lookAgain); } catch (Exception e) { // If it fail is because it couldnt find any other application } finally { webDriver.get(baseUrl + "/userStatus.json?logUserOut=true"); webDriver.quit(); } }
From source file:org.orcid.integration.blackbox.api.v2.rc2.BlackBoxBase.java
License:Open Source License
public void adminUnlockAccount(String adminUserName, String adminPassword, String orcidToUnlock) { // Login Admin adminSignIn(adminUserName, adminPassword); // Unlock the account WebDriverWait wait = new WebDriverWait(webDriver, 10); WebElement unLockProfileLink = webDriver.findElement(By.linkText("Unlock profile")); unLockProfileLink.click();// w w w . j a v a 2s .com WebElement unLockProfileOrcidId = webDriver.findElement(By.id("orcid_to_unlock")); unLockProfileOrcidId.sendKeys(orcidToUnlock); WebElement unLockButton = webDriver.findElement(By.id("bottom-confirm-unlock-profile")); unLockButton.click(); wait.until(ExpectedConditions.presenceOfElementLocated(By.id("btn-unlock"))); WebElement confirmUnLockButton = webDriver.findElement(By.id("btn-unlock")); confirmUnLockButton.click(); webDriver.quit(); }