Package org.openqa.selenium

Examples of org.openqa.selenium.Cookie


    }

    @Then("the value of the session cookie issued after authentication should be different from that of the previously noted session ID")
    public void compareSessionIds() {
        for (String name : Config.getSessionIDs()) {
            Cookie initialSessionCookie = findCookieByName(sessionIds, name);
            if (initialSessionCookie != null) {
                String existingCookieValue = findCookieByName(sessionIds, name)
                        .getValue();
                assertThat(app.getCookieByName(name).getValue(),
                        not(initialSessionCookie.getValue()));
            } else if (app.getCookieByName(name).getValue() == null) {
                throw new RuntimeException(
                        "No session IDs found after login with name: " + name);
            }
        }
View Full Code Here


   
    driver.get(deploymentURL.toString());
    WebElement username = driver.findElement(By.id("uname"));
    assertNotNull(username);
   
    driver.manage().addCookie(new Cookie("rememberMe", rememberToken));
   
    driver.get(deploymentURL.toString());
    waitForPresent(driver, "root logged");
  }
View Full Code Here

        // Login
        String tokenCookie = loginToCustomerCookiePortal();
        String changedTokenCookie = tokenCookie.replace("a", "b");

        // change cookie to invalid value
        driver.manage().addCookie(new Cookie(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE, changedTokenCookie, "/customer-cookie-portal"));

        // visit page and assert re-logged and cookie was refreshed
        driver.navigate().to("http://localhost:8081/customer-cookie-portal");
        Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/customer-cookie-portal");
        String currentCookie = driver.manage().getCookieNamed(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE).getValue();
View Full Code Here

        assertThat(htmlUnitDriver.findElement(By.className("message")).getText(), is("Success"));

        htmlUnitDriver.get("http://localhost/contacts/1");

        Cookie flashMessageCookie = htmlUnitDriver.manage().getCookieNamed("FLASH_MESSAGE");
        assertThat(flashMessageCookie, is(nullValue()));


         assertThat(htmlUnitDriver.findElements(By.className("message")), is(Matchers.<WebElement>empty()));
    }
View Full Code Here

        assertThat(htmlUnitDriver.findElement(By.className("message")).getText(), is("Success"));

        htmlUnitDriver.get("http://localhost/contacts/1");

        Cookie flashMessageCookie = htmlUnitDriver.manage().getCookieNamed("FLASH_MESSAGE");
        assertThat(flashMessageCookie, is(nullValue()));


        assertThat(htmlUnitDriver.findElements(By.className("message")), is(Matchers.<WebElement>empty()));
    }
View Full Code Here

    @Test
    public void addingACookie() {
        server.setHttpHandler("GET", EMPTY_CALLBACK);
        goToPage();

        driver.manage().addCookie(new Cookie("newCookie", "newValue"));

        Cookie[] cookies = getCookies();
        assertEquals(1, cookies.length);
        assertEquals("newCookie", cookies[0].getName());
        assertEquals("newValue", cookies[0].getValue());
View Full Code Here

    @Test
    public void modifyingACookie() {
        server.setHttpHandler("GET", COOKIE_SETTING_CALLBACK);
        goToPage();

        driver.manage().addCookie(new Cookie("test", "newValue", "localhost", "/", null, false));

        Cookie[] cookies = getCookies();
        assertEquals(2, cookies.length);
        assertEquals("test", cookies[0].getName());
        assertEquals("newValue", cookies[0].getValue());
View Full Code Here

    public void shouldRetainCookieInfo() {
        server.setHttpHandler("GET", EMPTY_CALLBACK);
        goToPage();

        // Added cookie (in a sub-path - allowed)
        Cookie addedCookie =
                new Cookie.Builder("fish", "cod")
                        .expiresOn(new Date(System.currentTimeMillis() + 100 * 1000)) //< now + 100sec
                        .path("/404")
                        .domain("localhost")
                        .build();
        driver.manage().addCookie(addedCookie);

        // Search cookie on the root-path and fail to find it
        Cookie retrieved = driver.manage().getCookieNamed("fish");
        assertNull(retrieved);

        // Go to the "/404" sub-path (to find the cookie)
        goToPage("404");
        retrieved = driver.manage().getCookieNamed("fish");
        assertNotNull(retrieved);
        // Check that it all matches
        assertEquals(addedCookie.getName(), retrieved.getName());
        assertEquals(addedCookie.getValue(), retrieved.getValue());
        assertEquals(addedCookie.getExpiry(), retrieved.getExpiry());
        assertEquals(addedCookie.isSecure(), retrieved.isSecure());
        assertEquals(addedCookie.getPath(), retrieved.getPath());
        assertTrue(retrieved.getDomain().contains(addedCookie.getDomain()));
    }
View Full Code Here

    @Test(expected = InvalidCookieDomainException.class)
    public void shouldNotAllowToCreateCookieOnDifferentDomain() {
        goToPage();

        // Added cookie (in a sub-path)
        Cookie addedCookie = new Cookie.Builder("fish", "cod")
                .expiresOn(new Date(System.currentTimeMillis() + 100 * 1000)) //< now + 100sec
                .path("/404")
                .domain("github.com")
                .build();
        driver.manage().addCookie(addedCookie);
View Full Code Here

        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(new Date(System.currentTimeMillis() - 1000)) //< now - 1 second
                .build();
        d.manage().addCookie(addedCookie);

        Cookie cookie = d.manage().getCookieNamed("expired");
        assertNull(cookie);
    }
View Full Code Here

TOP

Related Classes of org.openqa.selenium.Cookie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.