Example usage for org.openqa.selenium Cookie getExpiry

List of usage examples for org.openqa.selenium Cookie getExpiry

Introduction

In this page you can find the example usage for org.openqa.selenium Cookie getExpiry.

Prototype

public Date getExpiry() 

Source Link

Usage

From source file:com.citrix.g2w.webdriver.util.FileDownloader.java

License:Open Source License

/**
 * Load in all the cookies WebDriver currently knows about so that we can
 * mimic the browser cookie state./*  w w w  .  j a va 2s  .  c o m*/
 * 
 * @param seleniumCookieSet
 * @return mimicWebDriverCookieStore
 */
private BasicCookieStore mimicCookieState(Set<Cookie> seleniumCookieSet) {
    BasicCookieStore mimicWebDriverCookieStore = new BasicCookieStore();
    for (Cookie seleniumCookie : seleniumCookieSet) {
        BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(),
                seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        mimicWebDriverCookieStore.addCookie(duplicateCookie);
    }

    return mimicWebDriverCookieStore;
}

From source file:com.dhenton9000.filedownloader.FileDownloader.java

License:Apache License

/**
 * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
 *
 * @param seleniumCookieSet Set&lt;Cookie&gt;
 *///from  ww  w . java  2  s  .  c  o  m
private BasicCookieStore mimicCookieState(Set<Cookie> seleniumCookieSet) {
    BasicCookieStore copyOfWebDriverCookieStore = new BasicCookieStore();
    for (Cookie seleniumCookie : seleniumCookieSet) {
        BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(),
                seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        copyOfWebDriverCookieStore.addCookie(duplicateCookie);
    }

    return copyOfWebDriverCookieStore;
}

From source file:com.fmb.common.BrowserEmulator.java

License:Apache License

public void getCookie() {
    Set<Cookie> cookies = browserCore.manage().getCookies();
    for (Cookie c : cookies) {
        System.out.println(c.getDomain() + ", " + c.getName() + ", " + c.getValue() + "," + c.getExpiry() + ", "
                + c.getPath());/*  w w w . ja v a 2s . c om*/
    }
    logger.info("get cookie");
}

From source file:com.ggasoftware.uitest.utils.FileUtil.java

License:Open Source License

/**
 * Get Cookie from WebDriver browser session.
 *
 * @return cookieStore from WebDriver browser session.
 *///from  www .j a  va 2 s. com
private static CookieStore seleniumCookiesToCookieStore() {

    Set<Cookie> seleniumCookies = WebDriverWrapper.getDriver().manage().getCookies();
    CookieStore cookieStore = new BasicCookieStore();

    for (Cookie seleniumCookie : seleniumCookies) {
        BasicClientCookie basicClientCookie = new BasicClientCookie(seleniumCookie.getName(),
                seleniumCookie.getValue());
        basicClientCookie.setDomain(seleniumCookie.getDomain());
        basicClientCookie.setExpiryDate(seleniumCookie.getExpiry());
        basicClientCookie.setPath(seleniumCookie.getPath());
        cookieStore.addCookie(basicClientCookie);
    }

    return cookieStore;
}

From source file:com.jaeksoft.searchlib.crawler.web.browser.BrowserDriver.java

License:Open Source License

public List<CookieItem> getCookies() {
    Set<Cookie> cookies = driver.manage().getCookies();
    if (CollectionUtils.isEmpty(cookies))
        return null;
    List<CookieItem> cookieList = new ArrayList<CookieItem>(cookies.size());
    for (Cookie cookie : cookies) {
        BasicClientCookie basicCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
        basicCookie.setDomain(cookie.getDomain());
        basicCookie.setExpiryDate(cookie.getExpiry());
        basicCookie.setPath(cookie.getPath());
        basicCookie.setSecure(cookie.isSecure());
        cookieList.add(new CookieItem(basicCookie));
    }//  w  ww . ja va2  s .co  m
    return cookieList;
}

From source file:com.lazerycode.ebselen.customhandlers.FileDownloader.java

License:Apache License

/**
 * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
 *
 * @param seleniumCookieSet/*from   www. j a  va 2s  . c o  m*/
 * @return
 */
private HttpState mimicCookieState(Set<org.openqa.selenium.Cookie> seleniumCookieSet) {
    HttpState mimicWebDriverCookieState = new HttpState();
    for (org.openqa.selenium.Cookie seleniumCookie : seleniumCookieSet) {
        Cookie httpClientCookie = new Cookie(seleniumCookie.getDomain(), seleniumCookie.getName(),
                seleniumCookie.getValue(), seleniumCookie.getPath(), seleniumCookie.getExpiry(),
                seleniumCookie.isSecure());
        mimicWebDriverCookieState.addCookie(httpClientCookie);
    }
    return mimicWebDriverCookieState;
}

From source file:com.liferay.faces.portal.test.integration.demo.JSFLoginPortletTester.java

License:Open Source License

public void testJSF_Login(boolean testRememberMe) {

    // 1. Navigate the browser to the portal page that contains the jsf-sign-in portlet.
    BrowserDriver browserDriver = getBrowserDriver();
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    String jsfLoginPageURL = PortalTestUtil.getGuestPageURL("jsf-sign-in");
    browserDriver.navigateWindowTo(jsfLoginPageURL);

    String emailFieldXpath = "//input[contains(@id,':handle')]";
    browserDriver.waitForElementEnabled(emailFieldXpath);

    if (testRememberMe) {
        browserDriver.clickElement("//div[contains(@id,'rememberMe')]/input");
    }//ww w.j  av  a2s. c  om

    // 2. Wait for the *Email Address* field element to accept input.
    browserDriver.waitForElementDisplayed(emailFieldXpath);
    waitingAsserter.assertElementDisplayed(emailFieldXpath);

    // 3. Clear the *Email Address* field.
    browserDriver.clearElement(emailFieldXpath);

    // 4. Enter "test@liferay.com" into the *Email Address* field.
    browserDriver.sendKeysToElement(emailFieldXpath, "test@liferay.com");

    String passwordFieldXpath = "//input[contains(@id,':password')]";
    String signInButtonXpath = "//input[@type='submit' and @value='Sign In']";

    // Note: skip steps 5-9 if you are testing the "Remember Me" feature.
    if (!testRememberMe) {

        // 5. Enter "invalid_password" into the *Password* feild.
        browserDriver.sendKeysToElement(passwordFieldXpath, "invalid_password");

        // 6. Click the *Sign In* button.
        browserDriver.clickElementAndWaitForRerender(signInButtonXpath);

        // 7. Verify that the "Authentication failed" error message is displayed.
        String messageErrorXpath = "//form[@method='post']/ul/li";
        waitingAsserter.assertTextPresentInElement("Authentication failed", messageErrorXpath);

        // 8. Verify that the email field value still contains "test@liferay.com".
        waitingAsserter.assertTextPresentInElementValue("test@liferay.com", emailFieldXpath);

        // 9. Verify that the password field value is empty.
        ExpectedCondition<Boolean> passwordValueEmptyCondition = ExpectedConditions
                .attributeToBe(By.xpath(passwordFieldXpath), "value", "");
        waitingAsserter.assertTrue(passwordValueEmptyCondition);
    }

    // 10. Enter "test" into the *Password* feild.
    browserDriver.sendKeysToElement(passwordFieldXpath, "test");

    // 11. Click the *Sign In* button.
    browserDriver.clickElement(signInButtonXpath);

    // 12. Verify that the 'Sign In' was successful.
    waitingAsserter.assertTextPresentInElement("You are signed in",
            "//div[contains(@class,'liferay-faces-bridge-body')]");

    //J-
    // 13. Close the browser.
    // 14. Reopen the browser.
    //J+

    // TECHNICAL NOTE: BrowserDriver removes all cookies on closing, so simulate the browser closing by removing all
    // cookies that do not have an expiry (non-persistent cookies). For more details, see here:
    // https://stackoverflow.com/questions/3869821/how-do-i-create-a-persistent-vs-a-non-persistent-cookie.
    Set<Cookie> browserCookies = browserDriver.getBrowserCookies();
    WebDriver webDriver = browserDriver.getWebDriver();

    for (Cookie cookie : browserCookies) {

        if (cookie.getExpiry() == null) {
            webDriver.manage().deleteCookie(cookie);
        }
    }

    // 15. Navigate the browser to the portal page that contains the jsf-sign-in portlet.
    browserDriver.navigateWindowTo(jsfLoginPageURL);

    // 16. If you are testing the "Remember Me" feature then,...
    if (testRememberMe) {

        // ...verify that you are still signed in.
        waitingAsserter.assertTextPresentInElement("You are signed in",
                "//div[contains(@class,'liferay-faces-bridge-body')]");
    }

    // Otherwise,...
    else {

        // ...verify that you are no longer signed in.
        waitingAsserter = getWaitingAsserter();
        waitingAsserter.assertTextNotPresentInElement("You are signed in",
                "//div[contains(@class,'liferay-faces-bridge-body')]", false);
    }
}

From source file:com.machinepublishers.jbrowserdriver.OptionsServer.java

License:Apache License

private org.apache.http.cookie.Cookie convert(Cookie in) {
    BasicClientCookie out = new BasicClientCookie(in.getName(), in.getValue());
    String domainStr = null;/* w  w w.j av  a2s . c  om*/
    if (StringUtils.isEmpty(in.getDomain())) {
        String urlStr = context.item().engine.get().getLocation();
        try {
            URL url = new URL(urlStr);
            domainStr = url.getHost();
        } catch (MalformedURLException e) {
            Matcher matcher = domain.matcher(urlStr);
            if (matcher.matches()) {
                domainStr = matcher.group(1);
            }
        }
    }
    out.setDomain(domainStr == null ? in.getDomain() : domainStr);
    if (in.getExpiry() != null) {
        out.setExpiryDate(in.getExpiry());
    }
    out.setPath(in.getPath());
    out.setSecure(in.isSecure());
    out.setValue(in.getValue());
    out.setVersion(1);
    return out;
}

From source file:de.tntinteractive.portalsammler.engine.FileDownloader.java

License:Open Source License

/**
 * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
 *//*from   w  w w.jav  a2 s .com*/
private BasicCookieStore mimicCookieState(final Set<Cookie> seleniumCookieSet) {
    final BasicCookieStore mimicWebDriverCookieStore = new BasicCookieStore();
    for (final Cookie seleniumCookie : seleniumCookieSet) {
        final BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(),
                seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        mimicWebDriverCookieStore.addCookie(duplicateCookie);
    }

    return mimicWebDriverCookieStore;
}

From source file:gov.nih.nci.firebird.commons.selenium2.util.FileDownloadUtils.java

License:Open Source License

private static BasicClientCookie translateCookie(Cookie webDriverCookie) {
    BasicClientCookie clientCookie = new BasicClientCookie(webDriverCookie.getName(),
            webDriverCookie.getValue());
    clientCookie.setDomain(webDriverCookie.getDomain());
    clientCookie.setExpiryDate(webDriverCookie.getExpiry());
    clientCookie.setPath(webDriverCookie.getPath());
    clientCookie.setSecure(webDriverCookie.isSecure());
    return clientCookie;
}