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());
}
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);
}
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);
}
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");
}
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;
}
Aggregations