Example usage for org.openqa.selenium Cookie Cookie

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

Introduction

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

Prototype

public Cookie(String name, String value) 

Source Link

Document

Create a cookie for the default path with the given name and value with no expiry set.

Usage

From source file:io.selendroid.webviewdrivertests.CookieHandlerTest.java

License:Apache License

@Test
public void shouldDeleteAllCookies() {
    setupWebView();/*from   ww w  . j a  va 2 s . c  om*/
    Cookie cookie = new Cookie("name", "value");
    driver().manage().addCookie(cookie);
    driver().manage().deleteAllCookies();
    Assert.assertEquals(driver().manage().getCookies().contains(cookie), false);
}

From source file:io.selendroid.webviewdrivertests.CookieHandlerTest.java

License:Apache License

@Test
public void shouldGetAllCookies() {
    setupWebView();//from  w  w w.ja v a  2 s . c om
    Cookie cookie1 = new Cookie("name1", "value1");
    Cookie cookie2 = new Cookie("name2", "value2");
    Set<Cookie> cookies = new HashSet<Cookie>();
    cookies.add(cookie1);
    cookies.add(cookie2);
    driver().manage().addCookie(cookie1);
    driver().manage().addCookie(cookie2);
    Assert.assertEquals(driver().manage().getCookies().containsAll(cookies), true);
}

From source file:io.selendroid.webviewdrivertests.CookieHandlerTest.java

License:Apache License

@Test
public void shouldAddCookieAfterDeleting() {
    setupWebView();/*from w w w.ja v  a 2s. co  m*/
    Cookie cookie1 = new Cookie("name1", "value1");
    Cookie cookie2 = new Cookie("name2", "value2");
    driver().manage().addCookie(cookie2);
    driver().manage().deleteAllCookies();
    driver().manage().addCookie(cookie1);
    Assert.assertEquals(driver().manage().getCookies().contains(cookie1), true);
    Assert.assertEquals(driver().manage().getCookies().contains(cookie2), false);
}

From source file:io.selendroid.webviewdrivertests.CookieHandlerTest.java

License:Apache License

@Test
public void shouldGetCookieValue() {
    setupWebView();//from  w  w  w  .  j av a  2 s. c o m
    String cookieName = "name1";
    String val = "value1=alsoWithEqualSign";
    Cookie cookie1 = new Cookie(cookieName, val);
    driver().manage().addCookie(cookie1);
    Assert.assertEquals(val, driver().manage().getCookieNamed(cookieName).getValue());
}

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//w  w w . j  a  v a 2  s  .co  m
    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.auraframework.integration.test.http.WebDriverFilter.java

License:Apache License

/**
 * Make sure driver is already at the target domain since a Cookie will be
 * set for tracking./*from   w w  w .j  ava 2s .  c  o m*/
 * 
 * @param driver
 */
public WebDriverFilter(WebDriver driver) {
    super(((RemoteWebDriver) driver).getSessionId().toString());
    driver.manage().addCookie(new Cookie(getCookieName(), "$A"));
}

From source file:org.bigtester.ate.model.asserter.PagePropertyCorrectnessAsserter.java

License:Apache License

/**
 * {@inheritDoc}/*from  w  w  w  . j a  va  2 s.c  o  m*/
 */
@Override
public void assertER() {

    WebDriver webDriver = getResultPage().getMyWd().getWebDriver();// NOPMD
    if (null == webDriver) {
        throw new IllegalStateException("webDriver is not correctly populated.");
    }
    for (int i = 0; i < stepERValue.getValue().size(); i++) {
        StepErPageProperty sErPP = stepERValue.getValue().get(i);
        if (sErPP.getTestDataContext().getContextFieldValue()
                .equalsIgnoreCase(AssertType.PAGE_PROPERTY_CORRECTNESS)) {
            String assertProperty = sErPP.getAssertProperty();
            boolean correctFlag;
            if (PagePropertyType.COOKIE.equalsIgnoreCase(assertProperty)) {

                Cookie cki = new Cookie(sErPP.getAssertValue(), sErPP.getAssertValue());
                if (webDriver.manage().getCookies().contains(cki)) {
                    correctFlag = true;

                } else {
                    correctFlag = false;
                }
            } else if (PagePropertyType.PAGE_TITLE.equalsIgnoreCase(assertProperty)) {
                if (webDriver.getTitle().equals(sErPP.getAssertValue())) {
                    correctFlag = true;

                } else {
                    correctFlag = false;

                }
            } else {
                correctFlag = true;
            }
            if (correctFlag) {
                ItemCompareResult icr = new ItemCompareResult(sErPP.getAssertProperty(), sErPP.getAssertValue(),
                        EnumAssertResult.PAGEPROPERTYCORRECT.toString(), sErPP.getAssertPriority(),
                        EnumAssertResult.PAGEPROPERTYCORRECT);
                getExecResult().getComparedItemResults().put(sErPP.getIdColumn(), icr);
                super.appendAssertReportMSG(icr);
            } else {
                ItemCompareResult icr = new ItemCompareResult(sErPP.getAssertProperty(), sErPP.getAssertValue(),
                        EnumAssertResult.PAGEPROPERTYNOTCORRECT.toString(), sErPP.getAssertPriority(),
                        EnumAssertResult.PAGEPROPERTYNOTCORRECT);
                getExecResult().getComparedItemResults().put(sErPP.getIdColumn(), icr);
                getExecResult().getFailedItemResults().put(sErPP.getIdColumn(), icr);
                EnumAssertPriority failPriority = getStepERValue().getValue().get(i).getAssertPriority();
                if (failPriority.equals(EnumAssertPriority.HIGH)) {
                    setFlagFailCase(true);
                }
                super.appendAssertReportMSG(icr);
            }
        }
    }
}

From source file:org.eclipse.che.selenium.core.entrance.CookieEntrance.java

License:Open Source License

/**
 * Login to product by using cookies./*from w  w w .  ja v  a 2 s . co  m*/
 *
 * @param user
 */
@Override
public void login(TestUser user) {
    Cookie accessKey = new Cookie("session-access-key", user.obtainAuthToken());
    seleniumWebDriver.manage().addCookie(accessKey);
}

From source file:org.eclipse.che.selenium.pageobject.Ide.java

License:Open Source License

private void addAuthenticationToken(TestWorkspace testWorkspace) {
    seleniumWebDriver.get(testIdeUrlProvider.get().toString());
    seleniumWebDriver.manage()/*from ww  w  .  j av  a2s.co m*/
            .addCookie(new Cookie("session-access-key", testWorkspace.getOwner().getAuthToken()));
}

From source file:org.fluentlenium.integration.shareddriver.SharedDriverDeleteCookies.java

License:Apache License

@Test
public void cookieFirstMethod() {
    goTo(LocalFluentCase.DEFAULT_URL);
    assertThat($(".small", withName("name"))).hasSize(1);
    this.getDriver().manage().addCookie(new Cookie("cookie", "fluent"));
}