Search in sources :

Example 61 with WebDriverWait

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

the class ShibbolethTest method testLinkAndSignInWithShibboleth.

@Test
public void testLinkAndSignInWithShibboleth() throws IOException {
    webDriver = createFireFoxDriverWithModifyHeaders();
    webDriver.get(baseUri + "/userStatus.json?logUserOut=true");
    webDriver.get(baseUri + "/shibboleth/signin");
    new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@name='userId']")));
    BlackBoxBase.signIn(webDriver, user1UserName, user1Password);
    new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[contains(., '" + user1OrcidId + "')]")));
    // Check can sign in again without linking
    webDriver.get(baseUri + "/userStatus.json?logUserOut=true");
    webDriver.get(baseUri + "/shibboleth/signin");
    new WebDriverWait(webDriver, DEFAULT_TIMEOUT_SECONDS).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[contains(., '" + user1OrcidId + "')]")));
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Test(org.junit.Test)

Example 62 with WebDriverWait

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

the class AddWorksTest method addSimple.

public static void addSimple(String workName, WebDriver webDriver) {
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    waitWorksLoaded(wait, webDriver);
    BBBUtil.noSpinners(webDriver);
    BBBUtil.extremeWaitFor(BBBUtil.angularHasFinishedProcessing(), webDriver);
    // Selenium is having issues finding this element, I supect do to CSS transformations
    // Run the function directly
    ((JavascriptExecutor) webDriver).executeScript("angular.element('[ng-controller=WorkCtrl]').scope().addWorkModal()");
    BBBUtil.extremeWaitFor(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//select[@ng-model='editWork.workCategory.value']")), webDriver);
    BBBUtil.ngAwareSendKeys("conference", "workCategory", webDriver);
    BBBUtil.extremeWaitFor(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//option[text()='Conference paper']")), webDriver);
    BBBUtil.ngAwareSendKeys("string:conference-abstract", "workType", webDriver);
    // Pick the identifier type from the list
    BBBUtil.extremeWaitFor(ExpectedConditions.elementToBeClickable(By.id("worksIdType0")), webDriver);
    WebElement input = findElement(By.id("worksIdType0"));
    input.sendKeys("doi");
    BBBUtil.extremeWaitFor(ExpectedConditions.elementToBeClickable(By.xpath("//a[starts-with(@title,\"doi\")]")), webDriver);
    ((JavascriptExecutor) webDriver).executeScript("$(\"a:contains('doi:')\").click()");
    // Set other identifier attributes
    BBBUtil.ngAwareSendKeys("10.10/" + System.currentTimeMillis(), "worksIdValue0", webDriver);
    BBBUtil.ngAwareSendKeys(workName, "work-title", webDriver);
    // wait for angular to register that values have been typed.
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    BBBUtil.extremeWaitFor(BBBUtil.angularHasFinishedProcessing(), webDriver);
    BBBUtil.ngAwareClick(webDriver.findElement(By.xpath("//button[@id='save-new-work']")), webDriver);
    SigninTest.colorBoxIsClosed(wait);
    waitWorksLoaded(wait, webDriver);
    BBBUtil.extremeWaitFor(ExpectedConditions.presenceOfAllElementsLocatedBy(byWorkTitle(workName)), webDriver);
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 63 with WebDriverWait

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

the class BBBUtil method revokeApplicationsAccess.

public static void revokeApplicationsAccess(WebDriver webDriver) {
    List<String> clientIds = new ArrayList<String>();
    Properties prop = SystemPropertiesHelper.getProperties();
    String clientId1 = prop.getProperty("org.orcid.web.testClient1.clientId");
    if (!PojoUtil.isEmpty(clientId1)) {
        clientIds.add(clientId1);
    }
    String clientId2 = prop.getProperty("org.orcid.web.testClient2.clientId");
    if (!PojoUtil.isEmpty(clientId2)) {
        clientIds.add(clientId2);
    }
    String userName = prop.getProperty("org.orcid.web.testUser1.username");
    String password = prop.getProperty("org.orcid.web.testUser1.password");
    String baseUrl = "https://localhost:8443/orcid-web";
    if (!PojoUtil.isEmpty(prop.getProperty("org.orcid.web.baseUri"))) {
        baseUrl = prop.getProperty("org.orcid.web.baseUri");
    }
    webDriver.get(baseUrl + "/userStatus.json?logUserOut=true");
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.documentReady());
    webDriver.get(baseUrl + "/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, userName, password);
    // Switch to accounts settings page
    By accountSettingsMenuLink = By.id("accountSettingMenuLink");
    BBBUtil.extremeWaitFor(ExpectedConditions.presenceOfElementLocated(accountSettingsMenuLink), webDriver);
    webDriver.get(baseUrl + "/account");
    BBBUtil.extremeWaitFor(BBBUtil.documentReady(), webDriver);
    BBBUtil.extremeWaitFor(BBBUtil.angularHasFinishedProcessing(), webDriver);
    try {
        boolean lookAgain = false;
        do {
            // Look for each revoke app button
            By revokeAppBtn = By.id("revokeAppBtn");
            BBBUtil.extremeWaitFor(BBBUtil.angularHasFinishedProcessing(), webDriver);
            List<WebElement> appsToRevoke = webDriver.findElements(revokeAppBtn);
            boolean elementFound = false;
            // client id
            for (WebElement appElement : appsToRevoke) {
                String nameAttribute = appElement.getAttribute("name");
                if (clientIds.contains(nameAttribute)) {
                    BBBUtil.ngAwareClick(appElement, webDriver);
                    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
                    // Wait for the revoke button
                    By confirmRevokeAppBtn = By.id("confirmRevokeAppBtn");
                    BBBUtil.extremeWaitFor(ExpectedConditions.visibilityOfAllElementsLocatedBy(confirmRevokeAppBtn), webDriver);
                    BBBUtil.ngAwareClick(webDriver.findElement(confirmRevokeAppBtn), webDriver);
                    BBBUtil.extremeWaitFor(BBBUtil.angularHasFinishedProcessing(), webDriver);
                    BBBUtil.noCboxOverlay(webDriver);
                    BBBUtil.extremeWaitFor(BBBUtil.angularHasFinishedProcessing(), webDriver);
                    // may need to put sleep back here
                    elementFound = true;
                    break;
                }
            }
            if (elementFound) {
                lookAgain = true;
            } else {
                lookAgain = false;
            }
        } while (lookAgain);
    } catch (Exception e) {
    // If it fail is because it couldn't find any other application
    } finally {
        logUserOut(baseUrl, webDriver);
    }
}
Also used : By(org.openqa.selenium.By) ArrayList(java.util.ArrayList) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Properties(java.util.Properties) WebElement(org.openqa.selenium.WebElement) IOException(java.io.IOException) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 64 with WebDriverWait

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

the class BlackBoxBase method adminUnlockAccount.

public void adminUnlockAccount(String adminUserName, String adminPassword, String orcidToUnlock) {
    // Login Admin
    adminSignIn(adminUserName, adminPassword);
    try {
        // Unlock the account
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='unlockProfileDiv']/p[1]/a[2]")));
        BBBUtil.ngAwareClick(webDriver.findElement(By.xpath("//div[@id='unlockProfileDiv']/p[1]/a[2]")), webDriver);
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
        WebElement unLockProfileOrcidId = webDriver.findElement(By.id("orcid_to_unlock"));
        unLockProfileOrcidId.sendKeys(orcidToUnlock);
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.visibilityOfElementLocated(By.id("bottom-confirm-unlock-profile")));
        BBBUtil.ngAwareClick(webDriver.findElement(By.id("bottom-confirm-unlock-profile")), webDriver);
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.visibilityOfElementLocated(By.id("btn-unlock")));
        BBBUtil.ngAwareClick(webDriver.findElement(By.id("btn-unlock")), webDriver);
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
    } catch (TimeoutException t) {
    // Account might be already unlocked
    }
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement) TimeoutException(org.openqa.selenium.TimeoutException)

Example 65 with WebDriverWait

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

the class BlackBoxBase method changeBiography.

public static void changeBiography(String bioValue, String changeTo) throws Exception {
    int privacyIndex = getPrivacyIndex(changeTo);
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
    try {
        By editBio = By.xpath("//div[@id='bio-section']//div[@class='row']/div/ul/li[1]/div/span");
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(editBio));
        WebElement editBioButton = webDriver.findElement(editBio);
        editBioButton.click();
        By saveBio = By.xpath("//div[@id='bio-section']//button[text()='Save changes']");
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(saveBio));
        // Change the content if needed
        if (bioValue != null) {
            By bioTextArea = By.xpath("//div[@id='bio-section']//textarea");
            (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(bioTextArea));
            WebElement bioTextAreaElement = webDriver.findElement(bioTextArea);
            bioTextAreaElement.clear();
            bioTextAreaElement.sendKeys(bioValue);
        }
        // Change the visibility
        By bioOPrivacySelector = By.xpath("//div[@id = 'bio-section']//ul[@class='privacyToggle']/li[" + privacyIndex + "]/a");
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(bioOPrivacySelector));
        WebElement bioOPrivacySelectorLimitedElement = webDriver.findElement(bioOPrivacySelector);
        bioOPrivacySelectorLimitedElement.click();
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
    } catch (Exception e) {
        System.out.println("Unable to find nother-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)

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