Search in sources :

Example 66 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project ORCID-Source by ORCID.

the class BlackBoxBase method changeNamesVisibility.

public static void changeNamesVisibility(String changeTo) throws Exception {
    int privacyIndex = getPrivacyIndex(changeTo);
    try {
        By openEditNames = By.xpath("//div[@id = 'names-section']//div[@id = 'open-edit-names']");
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.presenceOfElementLocated(openEditNames));
        WebElement openEditNamesElement = webDriver.findElement(openEditNames);
        openEditNamesElement.click();
        By namesVisibility = By.xpath("//div[@id = 'names-section']//ul[@class='privacyToggle']/li[" + privacyIndex + "]/a");
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.presenceOfElementLocated(namesVisibility));
        WebElement namesVisibilityElement = webDriver.findElement(namesVisibility);
        namesVisibilityElement.click();
        By saveButton = By.xpath("//div[@id = 'names-section']//ul[@class='workspace-section-toolbar clearfix']//li[1]//button");
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.presenceOfElementLocated(saveButton));
        WebElement button = webDriver.findElement(saveButton);
        button.click();
        Thread.sleep(1000);
    } catch (Exception e) {
        System.out.println("Unable to find names-visibility-limited element");
        e.printStackTrace();
        throw e;
    }
}
Also used : By(org.openqa.selenium.By) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement) TimeoutException(org.openqa.selenium.TimeoutException) JSONException(org.codehaus.jettison.json.JSONException)

Example 67 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project ORCID-Source by ORCID.

the class OauthAuthorizationPageTest method skipAuthorizationScreenIfTokenLongLifeAlreadyExists.

@Test
public void skipAuthorizationScreenIfTokenLongLifeAlreadyExists() throws InterruptedException, JSONException {
    // First get the authorization code
    signout();
    String currentUrl = OauthAuthorizationPageHelper.loginAndAuthorize(this.getWebBaseUrl(), this.getClient1ClientId(), this.getClient1RedirectUri(), ScopePathType.ORCID_BIO_UPDATE.value(), null, this.getUser1UserName(), this.getUser1Password(), true, webDriver);
    Matcher matcher = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    String authorizationCode = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(authorizationCode));
    ClientResponse tokenResponse = getClientResponse(this.getClient1ClientId(), this.getClient1ClientSecret(), ScopePathType.ORCID_BIO_UPDATE.getContent(), this.getClient1RedirectUri(), 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.
    // First login
    webDriver.get(this.getWebBaseUrl() + "/userStatus.json?logUserOut=true");
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.documentReady());
    webDriver.get(this.getWebBaseUrl() + "/my-orcid");
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.documentReady());
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
    signIn(webDriver, this.getUser1UserName(), this.getUser1Password());
    // Then ask for the same permission
    String url = String.format("%s/oauth/authorize?client_id=%s&response_type=code&scope=%s&redirect_uri=%s", this.getWebBaseUrl(), this.getClient1ClientId(), ScopePathType.ORCID_BIO_UPDATE.getContent(), this.getClient1RedirectUri());
    webDriver.get(url);
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.documentReady());
    BBBUtil.extremeWaitFor(ExpectedConditions.presenceOfElementLocated(By.xpath("//title[contains(text(),'ORCID Playground')]")), webDriver);
    currentUrl = webDriver.getCurrentUrl();
    matcher = AUTHORIZATION_CODE_PATTERN.matcher(currentUrl);
    assertTrue(matcher.find());
    authorizationCode = matcher.group(1);
    assertFalse(PojoUtil.isEmpty(authorizationCode));
    tokenResponse = getClientResponse(this.getClient1ClientId(), this.getClient1ClientSecret(), ScopePathType.ORCID_BIO_UPDATE.getContent(), this.getClient1RedirectUri(), 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));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) Matcher(java.util.regex.Matcher) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Test(org.junit.Test)

Example 68 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project ORCID-Source by ORCID.

the class OauthAuthorizationPageHelper method loginAndAuthorize.

public static String loginAndAuthorize(String baseUrl, String clientId, String redirectUri, String scopes, String stateParam, String userId, String password, boolean longLife, Map<String, String> params, WebDriver webDriver, String responseType) {
    String formattedAuthorizationScreen = String.format(authorizationScreenUrlWithCode, baseUrl, clientId, responseType, scopes, redirectUri);
    if (!PojoUtil.isEmpty(stateParam)) {
        formattedAuthorizationScreen += "&state=" + stateParam;
    }
    if (params != null) {
        for (String key : params.keySet()) {
            formattedAuthorizationScreen += "&" + key + "=" + params.get(key);
        }
    }
    getUrlAndWait(formattedAuthorizationScreen);
    waitForSignin(webDriver);
    String currentUrl = webDriver.getCurrentUrl();
    if (isPlayground(currentUrl)) {
        // Probably got an error with the auth request and went straight to playground
        return currentUrl;
    }
    By userIdElementLocator = By.id("userId");
    waitForElementPresence(userIdElementLocator);
    ngAwareSendKeys(userId, "userId", webDriver);
    waitForElementPresence(By.id("password"));
    ngAwareSendKeys(password, "password", webDriver);
    waitForElementPresence((By.id("form-sign-in-button")));
    WebElement signInButton = findElementById("form-sign-in-button");
    signInButton.click();
    waitForAuth(webDriver);
    currentUrl = webDriver.getCurrentUrl();
    if (isPlayground(currentUrl)) {
        // screen was skipped
        return currentUrl;
    }
    waitForElementVisibility(By.xpath("//p[contains(text(),'has asked for the following access to your ORCID Record')]"));
    waitForAngular();
    if (longLife == false) {
        // disablePersistentToken
        WebElement persistentElement = webDriver.findElement(By.id("enablePersistentToken"));
        if (persistentElement.isDisplayed()) {
            if (persistentElement.isSelected()) {
                persistentElement.click();
            }
        }
    }
    waitForAngular();
    By authorizeElementLocator = By.id("authorize");
    waitForElementVisibility(authorizeElementLocator);
    WebElement authorizeButton = findElementById("authorize");
    authorizeButton.click();
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {
            return d.getTitle().equals("ORCID Playground");
        }
    });
    return webDriver.getCurrentUrl();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) By(org.openqa.selenium.By) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 69 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project ORCID-Source by ORCID.

the class OauthAuthorizationPageHelper method clickAuthorizeOnAuthorizeScreen.

public static void clickAuthorizeOnAuthorizeScreen(final WebDriver webDriver, boolean longLife) {
    if (webDriver.getTitle().equals("ORCID Playground")) {
        return;
    } else {
        try {
            BBBUtil.extremeWaitFor(ExpectedConditions.presenceOfElementLocated(By.xpath("//p[contains(text(),'has asked for the following access to your ORCID Record')]")), webDriver);
            if (longLife == false) {
                // disablePersistentToken
                WebElement persistentElement = webDriver.findElement(By.id("enablePersistentToken"));
                if (persistentElement.isDisplayed()) {
                    if (persistentElement.isSelected()) {
                        persistentElement.click();
                    }
                }
            }
            WebElement authorizeButton = webDriver.findElement(By.id("authorize"));
            authorizeButton.click();
        } catch (TimeoutException e) {
            // It might be the case that we are already in the ORCID Playground page, so, lets check for that case
            (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {

                public Boolean apply(WebDriver d) {
                    return d.getTitle().equals("ORCID Playground");
                }
            });
        }
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) TimeoutException(org.openqa.selenium.TimeoutException)

Example 70 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project activityinfo by bedatadriven.

the class FormList method getSelected.

public void getSelected() {
    driver.findElementByPartialLinkText("Get Selected").click();
    WebDriverWait wait = new WebDriverWait(driver, 120);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//DialogTitle[@value='Download Result']")));
    // make sure we succeeded!
    driver.findElementsByXPath("//TextView[contains(@value, 'Success')]");
    // close
    driver.findElementByPartialLinkText("OK").click();
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Aggregations

WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)527 WebElement (org.openqa.selenium.WebElement)166 WebDriver (org.openqa.selenium.WebDriver)131 Test (org.junit.Test)86 By (org.openqa.selenium.By)54 Actions (org.openqa.selenium.interactions.Actions)53 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)43 TimeoutException (org.openqa.selenium.TimeoutException)38 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)36 IOException (java.io.IOException)28 List (java.util.List)26 Wait (org.openqa.selenium.support.ui.Wait)25 BeforeClass (org.junit.BeforeClass)24 NgWebDriver (com.github.sergueik.jprotractor.NgWebDriver)21 ArrayList (java.util.ArrayList)21 WebDriverException (org.openqa.selenium.WebDriverException)21 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)21 Dimension (org.openqa.selenium.Dimension)20 File (java.io.File)16 NoSuchElementException (org.openqa.selenium.NoSuchElementException)16