Search in sources :

Example 76 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.

the class AbstractSeleniumTest method tryClick.

/**
 * Executes click() on the WebElement <code>el</code> and waits for the conditions.
 * If the condition is not fulfilled in <code>maxWaitTimeInS</code>, the click is executed again
 * and waits again for the condition.
 * After the number of attempts as given by the parameter an assertion error will be thrown, with
 * the given <code>message</code>.
 *
 * If the click was successful the element is returned that was created by the condition.
 *
 * @param el The element where the click is executed
 * @param conditions The conditions to wait for after the click
 * @param message The assertion messages
 * @param attempts Maximum number of click attempts
 * @param maxWaitTimeInS The time in seconds to wait that the condition is fulfilled.
 * @param <V> The return type
 * @return
 */
public <V> V tryClick(WebElement el, Function<? super WebDriver, V> conditions, String message, int attempts, int maxWaitTimeInS) {
    int count = attempts;
    WebDriverWait wait = new WebDriverWait(getWebDriver(), maxWaitTimeInS);
    V result = null;
    Exception ex = null;
    while (count > 0) {
        if (count < attempts) {
            try {
                result = conditions.apply(getWebDriver());
                return result;
            } catch (Exception e) {
            // Ignore
            }
        }
        el.click();
        try {
            result = wait.until(conditions);
            return result;
        } catch (Exception e) {
            logger.info("Error: {}, {}", count, e.getMessage());
            ex = e;
            count--;
        }
        try {
            Thread.currentThread().sleep(500);
        } catch (InterruptedException e) {
        // Ignore
        }
    }
    if (ex != null) {
        Assert.fail(message);
    }
    return result;
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Point(org.openqa.selenium.Point) IOException(java.io.IOException)

Example 77 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.

the class AbstractSeleniumTest method initializeArchiva.

public void initializeArchiva(String baseUrl, String browser, int maxWaitTimeInMs, String seleniumHost, int seleniumPort, boolean remoteSelenium) throws Exception {
    open(baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs, remoteSelenium);
    loadPage(baseUrl, 30);
    WebDriverWait wait = new WebDriverWait(getWebDriver(), 30);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("topbar-menu")));
    wait = new WebDriverWait(getWebDriver(), 20);
    Boolean found = wait.until(ExpectedConditions.or(ExpectedConditions.visibilityOfElementLocated(By.id("create-admin-link-a")), ExpectedConditions.visibilityOfElementLocated(By.id("login-link-a"))));
    if (found) {
        WebElement adminLink = getWebDriver().findElement(By.id("create-admin-link-a"));
        WebElement loginLink = getWebDriver().findElement(By.id("login-link-a"));
        // if not admin user created create one
        if (adminLink != null && adminLink.isDisplayed()) {
            Assert.assertFalse(isElementVisible("login-link-a"));
            Assert.assertFalse(isElementVisible("register-link-a"));
            // skygo need to set to true for passing is that work as expected ?
            adminLink.click();
            wait = new WebDriverWait(getWebDriver(), 10);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user-create")));
            assertCreateAdmin();
            String fullname = getProperty("ADMIN_FULLNAME");
            String username = getAdminUsername();
            String mail = getProperty("ADMIN_EMAIL");
            String password = getProperty("ADMIN_PASSWORD");
            submitAdminData(fullname, mail, password);
            assertUserLoggedIn(username);
            clickLinkWithLocator("logout-link-a", false);
        } else if (loginLink != null && loginLink.isDisplayed()) {
            Assert.assertTrue(isElementVisible("login-link-a"));
            Assert.assertTrue(isElementVisible("register-link-a"));
            login(getAdminUsername(), getAdminPassword());
        }
    }
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 78 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.

the class AbstractSeleniumTest method tryClick.

public <V> V tryClick(By clickableLocator, Function<? super WebDriver, V> conditions, String message, int attempts, int maxWaitTimeInS) {
    getWebDriver().manage().window().maximize();
    int count = attempts;
    WebDriverWait wait = new WebDriverWait(getWebDriver(), maxWaitTimeInS);
    V result = null;
    Exception ex = null;
    WebElement el = null;
    while (count > 0) {
        try {
            el = wait.until(ExpectedConditions.elementToBeClickable(clickableLocator));
            Actions actions = new Actions(getWebDriver());
            actions.moveToElement(el).click().perform();
            result = wait.until(conditions);
            return result;
        } catch (Exception e) {
            logger.info("Error: {}, {}, {}", count, e.getClass().getName(), e.getMessage());
            if (el != null) {
                // Elements may be stale and throw an exception, if the location is requested
                try {
                    Point elLoc = el.getLocation();
                    logger.info("Location: x={} y={}", elLoc.getX(), elLoc.getY());
                } catch (Throwable e2) {
                    logger.info("Could not determine location");
                }
            }
            ex = e;
            count--;
        }
        try {
            Thread.currentThread().sleep(500);
        } catch (InterruptedException e) {
        // Ignore
        }
    }
    if (ex != null) {
        Assert.fail(message);
    }
    return result;
}
Also used : Actions(org.openqa.selenium.interactions.Actions) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Point(org.openqa.selenium.Point) WebElement(org.openqa.selenium.WebElement) Point(org.openqa.selenium.Point) IOException(java.io.IOException)

Example 79 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.

the class AbstractSeleniumTest method submitLoginPage.

public void submitLoginPage(String username, String password, boolean rememberMe, boolean validUsernamePassword, String assertReturnPage) {
    logger.info("Activating login form");
    // clickLinkWithLocator( "login-link-a", false);
    WebDriverWait wait = new WebDriverWait(getWebDriver(), 5);
    WebElement usernameField = wait.until(ExpectedConditions.visibilityOf(getWebDriver().findElement(By.id("user-login-form-username"))));
    wait = new WebDriverWait(getWebDriver(), 5);
    WebElement passwordField = wait.until(ExpectedConditions.visibilityOf(getWebDriver().findElement(By.id("user-login-form-password"))));
    wait = new WebDriverWait(getWebDriver(), 5);
    WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id("modal-login-ok")));
    usernameField.sendKeys(username);
    passwordField.sendKeys(password);
    /*
        if ( rememberMe )
        {
            checkField( "rememberMe" );
        }*/
    button.click();
    if (validUsernamePassword) {
        assertUserLoggedIn(username);
    }
/*
        else
        {
            if ( "Login Page".equals( assertReturnPage ) )
            {
                assertLoginPage();
            }
            else
            {
                assertPage( assertReturnPage );
            }
        }*/
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 80 with WebDriverWait

use of org.openqa.selenium.support.ui.WebDriverWait in project archiva by apache.

the class ArchivaAdminTest method testHome.

@Test
public void testHome() {
    loadPage(baseUrl, 30);
    WebDriverWait wait = new WebDriverWait(getWebDriver(), 30);
    wait.until(ExpectedConditions.titleContains("Apache Archiva"));
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) AbstractArchivaTest(org.apache.archiva.web.test.parent.AbstractArchivaTest) Test(org.junit.Test)

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