use of org.openqa.selenium.Cookie in project selenium_java by sergueik.
the class VisualTest method addCookieforTopBanner.
// utils
// Add Cookie to suppress top banner animation
public void addCookieforTopBanner() {
// Set cookie expiration to Next Month Last Date
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
Date nextMonthLastDay = calendar.getTime();
// provide name, domain, path, expiration date of the cookie
Cookie topBannerCloseCookie = // Name
new Cookie.Builder("AA-kobiBannerClosed", "4").domain(baseURL.replaceAll("(?:https?://)([^/]+)(?:/.*)?$", "$1")).path("/").expiresOn(nextMonthLastDay).build();
driver.manage().addCookie(topBannerCloseCookie);
}
use of org.openqa.selenium.Cookie in project webmagic by code4craft.
the class SeleniumDownloader method download.
@Override
public Page download(Request request, Task task) {
checkInit();
WebDriver webDriver;
try {
webDriver = webDriverPool.get();
} catch (InterruptedException e) {
logger.warn("interrupted", e);
return null;
}
logger.info("downloading page " + request.getUrl());
webDriver.get(request.getUrl());
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebDriver.Options manage = webDriver.manage();
Site site = task.getSite();
if (site.getCookies() != null) {
for (Map.Entry<String, String> cookieEntry : site.getCookies().entrySet()) {
Cookie cookie = new Cookie(cookieEntry.getKey(), cookieEntry.getValue());
manage.addCookie(cookie);
}
}
/*
* TODO You can add mouse event or other processes
*
* @author: bob.li.0718@gmail.com
*/
WebElement webElement = webDriver.findElement(By.xpath("/html"));
String content = webElement.getAttribute("outerHTML");
Page page = new Page();
page.setRawText(content);
page.setHtml(new Html(content, request.getUrl()));
page.setUrl(new PlainText(request.getUrl()));
page.setRequest(request);
webDriverPool.returnToPool(webDriver);
return page;
}
use of org.openqa.selenium.Cookie in project ghostdriver by detro.
the class CookieTest method modifyingACookie.
@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[1].getName());
assertEquals("newValue", cookies[1].getValue());
assertEquals(".localhost", cookies[1].getDomain());
assertEquals("/", cookies[1].getPath());
assertEquals(false, cookies[1].isSecure());
assertEquals("test2", cookies[0].getName());
assertEquals("test2", cookies[0].getValue());
assertEquals(".localhost", cookies[0].getDomain());
assertEquals("/", cookies[0].getPath());
assertEquals(false, cookies[0].isSecure());
}
use of org.openqa.selenium.Cookie in project ghostdriver by detro.
the class CookieTest method gettingAllCookies.
@Test
public void gettingAllCookies() {
server.setHttpHandler("GET", COOKIE_SETTING_CALLBACK);
goToPage();
Cookie[] cookies = getCookies();
assertEquals(2, cookies.length);
Cookie cookie = driver.manage().getCookieNamed("test");
assertEquals("test", cookie.getName());
assertEquals("test", cookie.getValue());
assertEquals(".localhost", cookie.getDomain());
assertEquals("/", cookie.getPath());
assertTrue(cookie.getExpiry() != null);
assertEquals(false, cookie.isSecure());
Cookie cookie2 = driver.manage().getCookieNamed("test2");
assertEquals("test2", cookie2.getName());
assertEquals("test2", cookie2.getValue());
assertEquals(".localhost", cookie2.getDomain());
assertEquals("/", cookie2.getPath());
assertEquals(false, cookie2.isSecure());
assertTrue(cookie2.getExpiry() == null);
}
use of org.openqa.selenium.Cookie in project ghostdriver by detro.
the class CookieTest method addingACookieWithDefaults.
@Test
public void addingACookieWithDefaults() {
server.setHttpHandler("GET", EMPTY_CALLBACK);
goToPage();
long startTime = new Date().getTime();
driver.manage().addCookie(new Cookie("newCookie", "newValue"));
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());
// expiry > 19 years in the future
assertTrue(startTime + 599184000000L <= cookies[0].getExpiry().getTime());
}
Aggregations