List of usage examples for org.openqa.selenium Cookie Cookie
public Cookie(String name, String value, String path, Date expiry)
From source file:com.galenframework.ide.tests.integration.ui.GalenTestBase.java
License:Apache License
@Override public WebDriver createDriver(Object[] args) { WebDriver driver = WebDriverSingleInstance.getDriver(); driver.get(getTestUrl());/* w ww . j av a 2s .c om*/ driver.manage().window().setSize(desktopDevice.getSize()); driver.manage().deleteAllCookies(); driver.manage().addCookie(new Cookie(MockedWebApp.MOCK_KEY_COOKIE_NAME, mockUniqueKey, "/", new Date(new Date().getTime() + ONE_YEAR))); return driver; }
From source file:com.thoughtworks.selenium.webdriven.commands.CreateCookie.java
License:Apache License
@Override protected Void handleSeleneseCommand(WebDriver driver, String nameValuePair, String optionsString) { Matcher nameValuePairMatcher = NAME_VALUE_PAIR_PATTERN.matcher(nameValuePair); if (!nameValuePairMatcher.find()) throw new SeleniumException("Invalid parameter: " + nameValuePair); String name = nameValuePairMatcher.group(1); String value = nameValuePairMatcher.group(2); Matcher maxAgeMatcher = MAX_AGE_PATTERN.matcher(optionsString); Date maxAge = null;// www.ja va 2 s .c om if (maxAgeMatcher.find()) { maxAge = new Date(System.currentTimeMillis() + Integer.parseInt(maxAgeMatcher.group(1)) * 1000); } String path = null; Matcher pathMatcher = PATH_PATTERN.matcher(optionsString); if (pathMatcher.find()) { path = pathMatcher.group(1); try { if (path.startsWith("http")) { path = new URL(path).getPath(); } } catch (MalformedURLException e) { // Fine. } } Cookie cookie = new Cookie(name, value, path, maxAge); driver.manage().addCookie(cookie); return null; }
From source file:io.selendroid.webviewdrivertests.CookieHandlerTest.java
License:Apache License
@Test public void shouldAddCookie() { setupWebView();/* ww w .j a v a 2 s.c o m*/ Cookie cookie = new Cookie("name", "value", "/", null); Set<Cookie> cookies = new HashSet<Cookie>(); cookies.add(cookie); driver().manage().addCookie(cookie); Assert.assertEquals(driver().manage().getCookies().containsAll(cookies), true); }
From source file:jp.vmi.selenium.selenese.command.CreateCookie.java
License:Apache License
@Override protected Result executeImpl(Context context, String... curArgs) { String nameValuePair = curArgs[ARG_NAME_VALUE_PAIR]; String optionsString = curArgs[ARG_OPTIONS_STRING]; Matcher nameValuePairMatcher = NAME_VALUE_PAIR_PATTERN.matcher(nameValuePair); if (!nameValuePairMatcher.find()) return new Error("Invalid parameter: " + nameValuePair); String name = nameValuePairMatcher.group(1); String value = nameValuePairMatcher.group(2); Matcher maxAgeMatcher = MAX_AGE_PATTERN.matcher(optionsString); Date maxAge = null;/*from w ww . j a v a 2 s.c o m*/ if (maxAgeMatcher.find()) maxAge = new Date(System.currentTimeMillis() + Integer.parseInt(maxAgeMatcher.group(1)) * 1000); String path = null; Matcher pathMatcher = PATH_PATTERN.matcher(optionsString); if (pathMatcher.find()) { path = pathMatcher.group(1); try { if (path.startsWith("http")) path = new URL(path).getPath(); } catch (MalformedURLException e) { // Fine. } } Cookie cookie = new Cookie(name, value, path, maxAge); try { context.getWrappedDriver().manage().addCookie(cookie); } catch (InvalidCookieDomainException | UnableToSetCookieException e) { // This is workaround for PhanomJS bug. // TODO remove it when fix the bug. if (!context.isBrowser(PHANTOMJS)) throw e; } return SUCCESS; }