Example usage for org.openqa.selenium WebDriver navigate

List of usage examples for org.openqa.selenium WebDriver navigate

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver navigate.

Prototype

Navigation navigate();

Source Link

Document

An abstraction allowing the driver to access the browser's history and to navigate to a given URL.

Usage

From source file:org.alfresco.po.share.ShareUtil.java

License:Open Source License

public HtmlPage loginWithPost(WebDriver driver, String shareUrl, String userName, String password) {
    HttpClient client = new HttpClient();

    //login/*from   ww w .  ja  va2 s .c  om*/
    PostMethod post = new PostMethod((new StringBuilder()).append(shareUrl).append("/page/dologin").toString());
    NameValuePair[] formParams = (new NameValuePair[] {
            new org.apache.commons.httpclient.NameValuePair("username", userName),
            new org.apache.commons.httpclient.NameValuePair("password", password),
            new org.apache.commons.httpclient.NameValuePair("success", "/share/page/site-index"),
            new org.apache.commons.httpclient.NameValuePair("failure", "/share/page/type/login?error=true") });
    post.setRequestBody(formParams);
    post.addRequestHeader("Accept-Language", "en-us,en;q=0.5");
    try {
        client.executeMethod(post);
        HttpState state = client.getState();
        //Navigate to login page to obtain a session cookie.
        driver.navigate().to(shareUrl);
        //add authenticated token to cookie and navigate to user dashboard
        String url = shareUrl + "/page/user/" + userName + "/dashboard";
        driver.manage()
                .addCookie(new Cookie(state.getCookies()[0].getName(), state.getCookies()[0].getValue()));
        driver.navigate().to(url);
    } catch (IOException e) {
        e.printStackTrace();
        logger.error("Login error ", e);
    } finally {
        post.releaseConnection();
    }

    return factoryPage.getPage(driver);

}

From source file:org.alfresco.po.share.ShareUtil.java

License:Open Source License

/**
 * @param driver/*  w  w  w . j  av  a 2s.  c  om*/
 * @param userInfo
 * @return
 */
public HtmlPage navigateToSystemSummary(final WebDriver driver, String url, final String... userInfo) {
    String protocolVar = PageUtils.getProtocol(url);
    String consoleUrlVar = PageUtils.getAddress(url);
    String systemUrl = String.format("%s%s:%s@%s/" + ADMIN_SYSTEMSUMMARY_PAGE, protocolVar, userInfo[0],
            userInfo[1], consoleUrlVar);
    try {
        driver.navigate().to(systemUrl);
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Following exception was occurred" + e + ". Param systemUrl was " + systemUrl);
        }
    }
    return factoryPage.getPage(driver).render();
}

From source file:org.alfresco.po.share.ShareUtil.java

License:Open Source License

/**
 * Methods for navigation bulk import page
 *
 * @param driver//from w w  w . ja  v  a 2 s  .  co m
 * @param inPlace
 * @param userInfo
 * @return
 */
public HtmlPage navigateToBulkImport(final WebDriver driver, boolean inPlace, final String... userInfo) {
    String currentUrl = driver.getCurrentUrl();
    String protocolVar = PageUtils.getProtocol(currentUrl);
    String consoleUrlVar = PageUtils.getAddress(currentUrl);
    if (inPlace) {
        currentUrl = String.format("%s%s:%s@%s/" + BULK_IMPORT_IN_PLACE_PAGE, protocolVar, userInfo[0],
                userInfo[1], consoleUrlVar);
        logger.info("Property 'currentUrl' is: " + currentUrl);
    } else {
        currentUrl = String.format("%s%s:%s@%s/" + BULK_IMPORT_PAGE, protocolVar, userInfo[0], userInfo[1],
                consoleUrlVar);
        logger.info("Property 'currentUrl' is: " + currentUrl);
    }

    try {
        logger.info("Navigate to 'currentUrl': " + currentUrl);
        driver.navigate().to(currentUrl);
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Following exception was occurred" + e + ". Param systemUrl was " + currentUrl);
        }
    }
    return factoryPage.getPage(driver).render();
}

From source file:org.alfresco.po.share.ShareUtil.java

License:Open Source License

/**
 * Base helper method that extracts the url to required alfresco admin location.
 * Once extracted it formats it with the username and password to allow access to the page.
 * @param driver//  www. jav  a2  s  .c om
 * @param path
 * @param userInfo
 * @return
 * @throws Exception
 */
public HtmlPage navigateToAlfresco(final WebDriver driver, final String path, final String... userInfo)
        throws Exception {
    PageUtils.checkMandatoryParam("WebDriver", driver);
    PageUtils.checkMandatoryParam("Path", path);
    PageUtils.checkMandatoryParam("Username and password", userInfo);
    String currentUrl = driver.getCurrentUrl();
    String protocolVar = PageUtils.getProtocol(currentUrl);
    String consoleUrlVar = PageUtils.getAddress(currentUrl);
    currentUrl = String.format("%s%s:%s@%s/" + path, protocolVar, userInfo[0], userInfo[1], consoleUrlVar);
    driver.navigate().to(currentUrl);
    return factoryPage.getPage(driver).render();
}

From source file:org.alfresco.po.share.steps.CommonActions.java

License:Open Source License

/**
 * Refreshes and returns the current page: throws PageException if not a share page.
 * //from w w w. j  a  v a 2  s  .c o  m
 * @param driver WebDriver Instance
 * @return HtmlPage
 */
public HtmlPage refreshSharePage(WebDriver driver) {
    checkIfDriverIsNull(driver);
    driver.navigate().refresh();
    return getSharePage(driver);
}

From source file:org.alfresco.po.share.steps.LoginActions.java

License:Open Source License

/**
 * User Log-in followed by deletion of session cookies Assumes User is *NOT* logged in.
 * //from  w ww .  j av  a 2 s.c o  m
 * @param driver WebDriver Instance
 * @param userInfo String username, password
 * @return boolean true: if log in succeeds
 */
public SharePage loginToShare(WebDriver driver, String[] userInfo, String shareUrl) {
    LoginPage loginPage;
    SharePage sharePage;
    try {
        if ((userInfo.length < 2)) {
            throw new Exception("Invalid login details");
        }
        checkIfDriverIsNull(driver);
        driver.navigate().to(shareUrl);
        sharePage = getSharePage(driver);
        // Logout if already logged in
        try {
            loginPage = sharePage.render();
        } catch (ClassCastException e) {
            loginPage = logout(driver).render();
        }

        logger.info("Start: Login: " + userInfo[0] + " Password: " + userInfo[1]);

        loginPage.loginAs(userInfo[0], userInfo[1]);
        sharePage = factoryPage.getPage(driver).render();

        if (!sharePage.isLoggedIn()) {
            throw new ShareException("Method isLoggedIn return false");
        }
    } catch (Exception e) {
        String errorMessage = "Failed: Login: " + userInfo[0] + " Password: " + userInfo[1];
        logger.info(errorMessage, e);
        throw new ShareException(errorMessage, e);
    }

    return sharePage;
}

From source file:org.alfresco.po.share.steps.SiteActions.java

License:Open Source License

/**
 * Method to navigate to site dashboard url, based on siteshorturl, rather than sitename
 * This is to be used to navigate only as a util, not to test getting to the site dashboard
 * //from  w w  w .  j  a  v a 2  s . co  m
 * @param driver
 * @param siteShortURL
 * @return {@link org.alfresco.po.share.site.SiteDashboardPage}
 */
public SiteDashboardPage openSiteURL(WebDriver driver, String siteShortURL) {
    String url = driver.getCurrentUrl();
    String target = url.substring(0, url.indexOf("/page/")) + SITE_DASH_LOCATION_SUFFIX
            + getSiteShortname(siteShortURL) + "/dashboard";
    driver.navigate().to(target);
    SiteDashboardPage siteDashboardPage = getSharePage(driver).render();

    return siteDashboardPage.render();
}

From source file:org.alfresco.po.share.steps.SiteActions.java

License:Open Source License

/**
 * Utility to navigate to specified link
 * @param {@link WebDriver} driver//from w ww .j a va 2  s.c om
 * @param {String} link
 * @return HtmlPage
 */
public HtmlPage viewSharedLink(WebDriver driver, String link) {
    driver.navigate().to(link);

    return factoryPage.getPage(driver).render();

}

From source file:org.alfresco.po.share.user.UserContentsPageTest.java

License:Open Source License

/**
 * Searching with retry for content/*from   w w  w.  java2  s .  c  o  m*/
 * 
 * @param drone WebDrone
 * @param contentPage UserContentPage
 * @param contentName String
 * @return contentPage
 */
public UserContentPage contentRefreshRetry(WebDriver driver, UserContentPage contentPage, String contentName) {
    int counter = 0;
    int waitInMilliSeconds = 2000;
    int retryRefreshCount = 5;
    while (counter < retryRefreshCount) {
        List<UserContentItems> contentSearchResults = contentPage.getContentAdded();
        for (UserContentItems userContentItems : contentSearchResults) {
            if (userContentItems.getContentName().equalsIgnoreCase(contentName)) {
                return contentPage;
            }
        }
        counter++;
        driver.navigate().refresh();
        contentPage = resolvePage(driver).render();
        // double wait time to not over do solr search
        waitInMilliSeconds = (waitInMilliSeconds * 2);
        synchronized (SiteUtil.class) {
            try {
                SiteUtil.class.wait(waitInMilliSeconds);
            } catch (InterruptedException e) {
            }
        }
    }
    throw new PageException("Content search failed");
}

From source file:org.alfresco.po.share.util.SiteUtil.java

License:Open Source License

/**
 * Create site using share/*from   w ww  .  j av  a  2 s  . c  om*/
 * 
 * @param String username
 * @param String password
 * @param siteName String site name
 * @param desc String
 * @param siteVisibility SiteVisiblity
 * @return true if site created
 */
public void createSite(final WebDriver driver, final String username, final String password,
        final String siteName, String desc, String siteVisibility) {
    if (siteName == null || siteName.isEmpty())
        throw new UnsupportedOperationException("site name is required");
    try {
        siteService.create(username, password, "testdomain", siteName, desc,
                Visibility.valueOf(siteVisibility.toUpperCase()));
    } catch (Exception e) {
        throw new RuntimeException("Unable to create site " + siteName, e);
    }
    driver.navigate().to(shareUrl + "/page/site/" + siteName + "/dashboard");
}