Search in sources :

Example 61 with WebDriver

use of org.openqa.selenium.WebDriver 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 formattedAuthorizationScreen = String.format(authorizationScreenUrl, baseUrl, clientId, scopes, redirectUri);
    if (!PojoUtil.isEmpty(stateParam)) {
        formattedAuthorizationScreen += "&state=" + stateParam;
    }
    if (params != null) {
        for (String key : params.keySet()) {
            formattedAuthorizationScreen += "&" + key + "=" + params.get(key);
        }
    }
    formattedAuthorizationScreen += "#show_login";
    webDriver.get(formattedAuthorizationScreen);
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.documentReady());
    BBBUtil.extremeWaitFor(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@name='userId']")), webDriver);
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
    By userIdElementLocator = By.id("userId");
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.presenceOfElementLocated(userIdElementLocator));
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.documentReady());
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
    WebElement userIdElement = webDriver.findElement(userIdElementLocator);
    userIdElement.sendKeys(userId);
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
    WebElement passwordElement = webDriver.findElement(By.id("password"));
    passwordElement.sendKeys(password);
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
    if (!longLife) {
        //     disablePersistentToken
        WebElement persistentElement = webDriver.findElement(By.id("enablePersistentToken"));
        if (persistentElement.isDisplayed()) {
            if (persistentElement.isSelected()) {
                BBBUtil.ngAwareClick(persistentElement, webDriver);
            }
            (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS, BBBUtil.SLEEP_MILLISECONDS)).until(BBBUtil.angularHasFinishedProcessing());
        }
    }
    (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(ExpectedConditions.visibilityOfElementLocated(By.id("login-authorize-button")));
    try {
        BBBUtil.ngAwareClick(webDriver.findElement(By.id("login-authorize-button")), webDriver);
        (new WebDriverWait(webDriver, BBBUtil.TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {

            public Boolean apply(WebDriver d) {
                return d.getTitle().equals("ORCID Playground");
            }
        });
    } 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");
            }
        });
    }
    return webDriver.getCurrentUrl();
}
Also used : WebDriver(org.openqa.selenium.WebDriver) By(org.openqa.selenium.By) 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 62 with WebDriver

use of org.openqa.selenium.WebDriver in project opennms by OpenNMS.

the class JmxConfigurationGeneratorIT method configureJMXConnection.

protected void configureJMXConnection(final boolean skipDefaultVM) throws Exception {
    final long end = System.currentTimeMillis() + LOAD_TIMEOUT;
    final WebDriverWait shortWait = new WebDriverWait(m_driver, 10);
    final String skipDefaultVMxpath = "//span[@id='skipDefaultVM']/input";
    final boolean selected = waitForElement(By.xpath(skipDefaultVMxpath)).isSelected();
    LOG.debug("skipDefaultVM selected: {}", selected);
    if (selected != skipDefaultVM) {
        waitForElement(By.xpath(skipDefaultVMxpath)).click();
    }
    // configure authentication
    final WebElement authenticateElement = waitForElement(By.id("authenticate"));
    if (!authenticateElement.isSelected()) {
        authenticateElement.findElement(By.tagName("input")).click();
    }
    /*
         * Sometimes, Vaadin just loses input, or focus.  Or both!  I suspect it's
         * because of the way Vaadin handles events and DOM-redraws itself, but...
         * ¯\_(ツ)_/¯
         *
         * To make sure it really really *really* works, there are multiple layers
         * of belt-and-suspenders-and-glue-and-staples:
         *
         * 1. Click first to ensure the field is focused
         * 2. Clear the current contents of the field
         * 3. Send the text to the field
         * 4. Click it *again* because sometimes this wakes up the event handler
         * 5. Do it all in a loop that checks for validation errors, because
         *    *sometimes* even with all that, it will fail to fill in a field...
         *    In that case, hit escape to clear the error message and start all
         *    over and try again.
         */
    boolean found = false;
    do {
        setVaadinValue("authenticateUser", "admin");
        setVaadinValue("authenticatePassword", "admin");
        // go to next page
        waitForElement(By.id("next")).click();
        try {
            setImplicitWait(1, TimeUnit.SECONDS);
            found = shortWait.until(new ExpectedCondition<Boolean>() {

                @Override
                public Boolean apply(final WebDriver driver) {
                    try {
                        final WebElement elem = driver.findElement(By.cssSelector("div.v-Notification-error h1"));
                        LOG.debug("Notification error element: {}", elem);
                        if (elem != null) {
                            elem.sendKeys(Keys.ESCAPE);
                            return false;
                        }
                    } catch (final NoSuchElementException | StaleElementReferenceException e) {
                        LOG.warn("Exception while checking for errors message.", e);
                    }
                    try {
                        final Boolean contains = pageContainsText(MBEANS_VIEW_TREE_WAIT_NAME).apply(driver);
                        LOG.debug("Page contains '{}'? {}", MBEANS_VIEW_TREE_WAIT_NAME, contains);
                        return contains;
                    } catch (final Exception e) {
                        LOG.warn("Exception while checking for next page.", e);
                    }
                    return false;
                }
            });
        } catch (final Exception e) {
            LOG.debug("Failed to configure authentication and port.", e);
        } finally {
            setImplicitWait();
        }
    } while (System.currentTimeMillis() < end && !found);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 63 with WebDriver

use of org.openqa.selenium.WebDriver in project opennms by OpenNMS.

the class IndexPageIT method verifyStatusMap.

@Test
public void verifyStatusMap() {
    // In order to have anything show up, we have to create a node with long/lat information first
    // A interface and service which does not exist is used, in order to provoke an alarm beeing sent by opennms
    // to have a status >= Warning
    // INITIALIZE
    LOG.info("Initializing foreign source with no detectors");
    String foreignSourceXML = "<foreign-source name=\"" + OpenNMSSeleniumTestCase.REQUISITION_NAME + "\">\n" + "<scan-interval>1d</scan-interval>\n" + "<detectors/>\n" + "<policies/>\n" + "</foreign-source>";
    createForeignSource(REQUISITION_NAME, foreignSourceXML);
    LOG.info("Initializing node with  source with no detectors");
    String requisitionXML = "<model-import foreign-source=\"" + OpenNMSSeleniumTestCase.REQUISITION_NAME + "\">" + "   <node foreign-id=\"tests\" node-label=\"192.0.2.1\">" + "       <interface ip-addr=\"192.0.2.1\" status=\"1\" snmp-primary=\"N\">" + "           <monitored-service service-name=\"ICMP\"/>" + "       </interface>" + "       <asset name=\"longitude\" value=\"-0.075949\"/>" + "       <asset name=\"latitude\" value=\"51.508112\"/>" + "   </node>" + "</model-import>";
    createRequisition(REQUISITION_NAME, requisitionXML, 1);
    // try every 5 seconds, for 120 seconds, until the service on 127.0.0.2 has been detected as "down", or fail afterwards
    try {
        setImplicitWait(5, TimeUnit.SECONDS);
        new WebDriverWait(m_driver, 120).until(new Predicate<WebDriver>() {

            @Override
            public boolean apply(@Nullable WebDriver input) {
                // refresh page
                input.get(getBaseUrl() + "opennms/index.jsp");
                // Wait until we have markers
                List<WebElement> markerElements = input.findElements(By.xpath("//*[contains(@class, 'leaflet-marker-icon')]"));
                return !markerElements.isEmpty();
            }
        });
    } finally {
        setImplicitWait();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) List(java.util.List) Test(org.junit.Test)

Example 64 with WebDriver

use of org.openqa.selenium.WebDriver in project opennms by OpenNMS.

the class BSMAdminIT method verifyElementNotPresent.

/**
     * Verifies that the provided element is not present.
     * @param by
     */
private static void verifyElementNotPresent(OpenNMSSeleniumTestCase testCase, final By by) {
    new WebDriverWait(testCase.getDriver(), 5).until(ExpectedConditions.not(new ExpectedCondition<Boolean>() {

        @Nullable
        @Override
        public Boolean apply(@Nullable WebDriver input) {
            try {
                // the default implicit wait timeout is too long, make it shorter
                input.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
                WebElement elementFound = input.findElement(by);
                return elementFound != null;
            } catch (NoSuchElementException ex) {
                return false;
            } finally {
                // set the implicit wait timeout back to the value it has been before
                input.manage().timeouts().implicitlyWait(LOAD_TIMEOUT, TimeUnit.MILLISECONDS);
            }
        }
    }));
}
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) Nullable(javax.annotation.Nullable) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 65 with WebDriver

use of org.openqa.selenium.WebDriver in project selenium-tests by Wikia.

the class FacebookSignupModalComponentObject method acceptWikiaAppPolicy.

public void acceptWikiaAppPolicy() {
    new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {

        @Nullable
        @Override
        public Boolean apply(WebDriver input) {
            return input.getWindowHandles().size() > 1;
        }
    });
    Object[] handles = driver.getWindowHandles().toArray();
    driver.switchTo().window(handles[1].toString());
    wait.forElementVisible(By.cssSelector("button[name='__CONFIRM__']"));
    appTermsConfirmButton.click();
    PageObjectLogging.log("acceptWikiaAppPolicy", "confirmed wikia apps privacy policy", true);
    driver.switchTo().window(handles[0].toString());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WikiBasePageObject(com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject) Nullable(javax.annotation.Nullable)

Aggregations

WebDriver (org.openqa.selenium.WebDriver)167 WebElement (org.openqa.selenium.WebElement)87 Test (org.junit.Test)61 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)59 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)40 Actions (org.openqa.selenium.interactions.Actions)25 IOException (java.io.IOException)12 Cookie (org.openqa.selenium.Cookie)11 List (java.util.List)10 File (java.io.File)9 HttpRequestCallback (ghostdriver.server.HttpRequestCallback)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)8 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)7 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)7 By (org.openqa.selenium.By)5 Dimension (org.openqa.selenium.Dimension)5 Predicate (com.google.common.base.Predicate)4 TimeoutException (org.openqa.selenium.TimeoutException)4