Search in sources :

Example 36 with Cookie

use of org.openqa.selenium.Cookie in project ghostdriver by detro.

the class CookieTest method addingACookie.

@Test
public void addingACookie() {
    server.setHttpHandler("GET", EMPTY_CALLBACK);
    goToPage();
    driver.manage().addCookie(new Cookie("newCookie", "newValue", ".localhost", "/", null, false, false));
    Cookie[] cookies = getCookies();
    assertEquals(1, cookies.length);
    assertEquals("newCookie", cookies[0].getName());
    assertEquals("newValue", cookies[0].getValue());
    assertEquals(".localhost", cookies[0].getDomain());
    assertEquals("/", cookies[0].getPath());
    assertEquals(false, cookies[0].isSecure());
    assertEquals(false, cookies[0].isHttpOnly());
}
Also used : Cookie(org.openqa.selenium.Cookie) Test(org.junit.Test)

Example 37 with Cookie

use of org.openqa.selenium.Cookie in project ghostdriver by detro.

the class CookieTest method shouldNotAllowToCreateCookieOnDifferentDomain.

@Test(expected = InvalidCookieDomainException.class)
public void shouldNotAllowToCreateCookieOnDifferentDomain() {
    goToPage();
    // Added cookie (in a sub-path)
    Cookie addedCookie = new Cookie.Builder("fish", "cod").expiresOn(// < now + 100sec
    new Date(System.currentTimeMillis() + 100 * 1000)).path("/404").domain("github.com").build();
    driver.manage().addCookie(addedCookie);
}
Also used : Cookie(org.openqa.selenium.Cookie) Date(java.util.Date) Test(org.junit.Test)

Example 38 with Cookie

use of org.openqa.selenium.Cookie in project ghostdriver by detro.

the class CookieTest method shouldAllowToSetCookieThatIsAlreadyExpired.

@Test
public void shouldAllowToSetCookieThatIsAlreadyExpired() {
    WebDriver d = getDriver();
    d.get("https://github.com/");
    // Clear all cookies
    assertTrue(d.manage().getCookies().size() > 0);
    d.manage().deleteAllCookies();
    assertEquals(d.manage().getCookies().size(), 0);
    // Added cookie that expires in the past
    Cookie addedCookie = new Cookie.Builder("expired", "yes").expiresOn(// < now - 1 second
    new Date(System.currentTimeMillis() - 1000)).build();
    d.manage().addCookie(addedCookie);
    Cookie cookie = d.manage().getCookieNamed("expired");
    assertNull(cookie);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Cookie(org.openqa.selenium.Cookie) Date(java.util.Date) Test(org.junit.Test)

Example 39 with Cookie

use of org.openqa.selenium.Cookie in project java.webdriver by sayems.

the class LoadCookieInfo method main.

public static void main(String... args) {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.facebook.com");
    try {
        File f2 = new File("browser.data");
        FileReader fr = new FileReader(f2);
        BufferedReader br = new BufferedReader(fr);
        String line;
        while ((line = br.readLine()) != null) {
            StringTokenizer str = new StringTokenizer(line, ";");
            while (str.hasMoreTokens()) {
                String name = str.nextToken();
                String value = str.nextToken();
                String domain = str.nextToken();
                String path = str.nextToken();
                Date expiry = null;
                String dt;
                if (!(dt = str.nextToken()).equals("null")) {
                    expiry = new Date(dt);
                }
                boolean isSecure = new Boolean(str.nextToken()).booleanValue();
                Cookie ck = new Cookie(name, value, domain, path, expiry, isSecure);
                driver.manage().addCookie(ck);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    driver.get("http://www.facebook.com");
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Cookie(org.openqa.selenium.Cookie) StringTokenizer(java.util.StringTokenizer) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) Date(java.util.Date)

Example 40 with Cookie

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

the class FeaturedVideoMobileComponentObject method setAutoplayCookie.

public FeaturedVideoMobileComponentObject setAutoplayCookie(boolean autoplay) {
    driver.manage().addCookie(new Cookie(AUTOPLAY_COOKIE, autoplay ? "1" : "0", String.format(".%s", Configuration.getEnvType().getDomain(driver.getCurrentUrl())), null, null));
    driver.navigate().refresh();
    return this;
}
Also used : Cookie(org.openqa.selenium.Cookie)

Aggregations

Cookie (org.openqa.selenium.Cookie)73 Test (org.junit.Test)26 WebElement (org.openqa.selenium.WebElement)16 WebDriver (org.openqa.selenium.WebDriver)14 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)9 Date (java.util.Date)8 App (com.coveros.selenified.application.App)7 IOException (java.io.IOException)7 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)7 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)6 Test (org.testng.annotations.Test)6 Collectors (java.util.stream.Collectors)5 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)5 AuthorizeClient (org.gluu.oxauth.client.AuthorizeClient)5 Matchers (org.hamcrest.Matchers)5 Page (org.jboss.arquillian.graphene.page.Page)5 Assert (org.junit.Assert)5 AdminRoles (org.keycloak.models.AdminRoles)5