本文整理了Java中org.openqa.selenium.Cookie.getDomain()
方法的一些代码示例,展示了Cookie.getDomain()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.getDomain()
方法的具体详情如下:
包路径:org.openqa.selenium.Cookie
类名称:Cookie
方法名:getDomain
暂无
代码示例来源:origin: selenide/selenide
private BasicClientCookie duplicateCookie(Cookie seleniumCookie) {
BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue());
duplicateCookie.setDomain(seleniumCookie.getDomain());
duplicateCookie.setAttribute(BasicClientCookie.DOMAIN_ATTR, seleniumCookie.getDomain());
duplicateCookie.setSecure(seleniumCookie.isSecure());
duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
duplicateCookie.setPath(seleniumCookie.getPath());
return duplicateCookie;
}
}
代码示例来源:origin: org.openqa.selenium.webdriver/webdriver-htmlunit
private void verifyDomain(Cookie cookie, String expectedDomain) {
String domain = cookie.getDomain();
if (domain == null)
return;
if ("".equals(domain)) {
throw new WebDriverException(
"Domain must not be an empty string. Consider using null instead");
}
expectedDomain = expectedDomain.startsWith(".") ? expectedDomain : "." + expectedDomain;
domain = domain.startsWith(".") ? domain : "." + domain;
if (!expectedDomain.endsWith(domain)) {
throw new WebDriverException(
String.format("You may only add cookies that would be visible to the current domain: %s => %s",
domain, expectedDomain));
}
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver
private void verifyDomain(Cookie cookie, String expectedDomain) {
String domain = cookie.getDomain();
if (domain == null) {
return;
}
if ("".equals(domain)) {
throw new InvalidCookieDomainException(
"Domain must not be an empty string. Consider using null instead");
}
// Line-noise-tastic
if (domain.matches(".*[^:]:\\d+$")) {
domain = domain.replaceFirst(":\\d+$", "");
}
expectedDomain = expectedDomain.startsWith(".") ? expectedDomain : "." + expectedDomain;
domain = domain.startsWith(".") ? domain : "." + domain;
if (!expectedDomain.endsWith(domain)) {
throw new InvalidCookieDomainException(
String.format(
"You may only add cookies that would be visible to the current domain: %s => %s",
domain, expectedDomain));
}
}
代码示例来源:origin: org.seleniumhq.webdriver/webdriver-ie
public void addCookie(Cookie cookie) {
StringBuilder sb = new StringBuilder(cookie.getName());
sb.append("=").append(cookie.getValue()).append("; ");
if (cookie.getPath() != null && !"".equals(cookie.getPath())) {
sb.append("path=").append(cookie.getPath()).append("; ");
}
if (cookie.getDomain() != null && !"".equals(cookie.getDomain())) {
String domain = cookie.getDomain();
int colon = domain.indexOf(":");
if (colon != -1) {
domain = domain.substring(0, colon);
}
sb.append("domain=").append(domain).append("; ");
}
if (cookie.getExpiry() != null) {
sb.append("expires=");
sb.append(new SimpleDateFormat("EEE, d MMM yyyy hh:mm:ss z").format(cookie.getExpiry()));
}
executeScript("document.cookie = arguments[0]", sb.toString());
}
代码示例来源:origin: com.machinepublishers/jbrowserdriver
/**
* {@inheritDoc}
*/
@Override
public void deleteCookie(Cookie cookie) {
List<org.apache.http.cookie.Cookie> cookies = cookieStore.getCookies();
String toDelete = new StringBuilder().append(cookie.getDomain().toLowerCase())
.append("\n").append(cookie.getName().toLowerCase())
.append("\n").append(cookie.getPath().toLowerCase()).toString();
for (org.apache.http.cookie.Cookie cur : cookies) {
String curString = new StringBuilder().append(cur.getDomain().toLowerCase())
.append("\n").append(cur.getName().toLowerCase())
.append("\n").append(cur.getPath().toLowerCase()).toString();
if (toDelete.equals(curString)) {
removeFromCookieStore(cur);
}
}
}
代码示例来源:origin: com.opera/operadriver
public void deleteCookie(Cookie cookie) {
if (cookieManager == null) {
throw new UnsupportedOperationException(
"Deleting cookies are not supported without the cookie-manager service");
}
cookieManager.removeCookie(cookie.getDomain(), cookie.getPath(), cookie.getName());
gc();
//Date dateInPast = new Date(0); Cookie toDelete = new Cookie(cookie.getName(),
//cookie.getValue(), cookie.getDomain(), cookie.getPath(), dateInPast, false);
//addCookie(toDelete);
}
代码示例来源:origin: com.opera/operadriver
public void addCookie(Cookie cookie) {
// TODO: Numeric overflow
if (cookie.getExpiry() == null) {
cookie =
new Cookie(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(),
new Date(new Date().getTime() + (10 * 365 * 24 * 60 * 60 * 1000)), false);
}
debugger.executeJavascript("document.cookie='" + cookie.toString() + "'", false);
}
代码示例来源:origin: org.seleniumhq.webdriver/webdriver-ie
private void deleteCookieByPath(Cookie cookie) {
String path = cookie.getPath();
if (path != null) {
String[] segments = cookie.getPath().split("/");
StringBuilder currentPath = new StringBuilder();
for (String segment : segments) {
if ("".equals(segment)) continue;
currentPath.append("/").append(segment);
Cookie toDelete = new NullPathCookie(cookie.getName(), cookie.getValue(),
cookie.getDomain(), currentPath.toString(),
new Date(0));
recursivelyDeleteCookieByDomain(toDelete);
}
}
Cookie toDelete = new NullPathCookie(cookie.getName(), cookie.getValue(),
cookie.getDomain(), "/",
new Date(0));
recursivelyDeleteCookieByDomain(toDelete);
toDelete = new NullPathCookie(cookie.getName(), cookie.getValue(),
cookie.getDomain(), null,
new Date(0));
recursivelyDeleteCookieByDomain(toDelete);
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-api
public Map<String, Object> toJson() {
Map<String, Object> toReturn = new TreeMap<>();
if (getDomain() != null) {
toReturn.put("domain", getDomain());
}
if (getExpiry() != null) {
toReturn.put("expiry", getExpiry());
}
if (getName() != null) {
toReturn.put("name", getName());
}
if (getPath() != null) {
toReturn.put("path", getPath());
}
if (getValue() != null) {
toReturn.put("value", getValue());
}
toReturn.put("secure", isSecure());
toReturn.put("httpOnly", isHttpOnly());
return toReturn;
}
代码示例来源:origin: org.seleniumhq.webdriver/webdriver-ie
private void recursivelyDeleteCookieByDomain(Cookie cookie) {
addCookie(cookie);
int dotIndex = cookie.getDomain().indexOf('.');
if (dotIndex == 0) {
String domain = cookie.getDomain().substring(1);
Cookie toDelete =
new NullPathCookie(cookie.getName(), cookie.getValue(), domain,
cookie.getPath(), new Date(0));
recursivelyDeleteCookieByDomain(toDelete);
} else if (dotIndex != -1) {
String domain = cookie.getDomain().substring(dotIndex);
Cookie toDelete =
new NullPathCookie(cookie.getName(), cookie.getValue(), domain,
cookie.getPath(), new Date(0));
recursivelyDeleteCookieByDomain(toDelete);
} else {
Cookie toDelete =
new NullPathCookie(cookie.getName(), cookie.getValue(), "",
cookie.getPath(), new Date(0));
addCookie(toDelete);
}
}
代码示例来源:origin: com.watchrabbit/crawler-auth
@RequestMapping(method = RequestMethod.GET, value = "/session/{domain}")
public List<Cookie> getSession(@PathVariable String domain) {
return authService.getSession(domain).stream()
.map(cookie -> new Cookie.Builder()
.withDomain(cookie.getDomain())
.withExpiry(cookie.getExpiry())
.withIsHttpOnly(cookie.isHttpOnly())
.withIsSecure(cookie.isSecure())
.withName(cookie.getName())
.withPath(cookie.getPath())
.withValue(cookie.getValue())
.build()
).collect(toList());
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver
private com.gargoylesoftware.htmlunit.util.Cookie convertSeleniumCookieToHtmlUnit(Cookie cookie) {
return new com.gargoylesoftware.htmlunit.util.Cookie(
cookie.getDomain(),
cookie.getName(),
cookie.getValue(),
cookie.getPath(),
cookie.getExpiry(),
cookie.isSecure(),
cookie.isHttpOnly()
);
}
代码示例来源:origin: com.googlecode.fighting-layout-bugs/fighting-layout-bugs
public MockBrowser(HttpClient httpClient) {
_httpClient = httpClient;
HttpConnectionManager connectionManager = httpClient.getHttpConnectionManager();
if (connectionManager instanceof MultiThreadedHttpConnectionManager) {
_threadPool = Executors.newFixedThreadPool(10);
} else {
LOG.warn("The configured HttpClient does not use a MultiThreadedHttpConnectionManager, will only use 1 thread (instead of 10) for downloading CSS files and checking image URLs ...");
_threadPool = Executors.newFixedThreadPool(1);
}
HttpState httpState = new HttpState();
WebDriver driver = _webPage.getDriver();
for (org.openqa.selenium.Cookie cookie : driver.manage().getCookies()) {
httpState.addCookie(new Cookie(cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure()));
}
_httpClient.setState(httpState);
}
代码示例来源:origin: vmi/selenese-runner-java
/**
* Add cookie information.
*
* @param cookie cookie.
*/
public void add(Cookie cookie) {
CookieKey key = new CookieKey(
cookie.getName(),
cookie.getPath(),
cookie.getDomain());
CookieValue value = new CookieValue(
key,
cookie.getValue(),
cookie.getExpiry());
put(key, value);
}
代码示例来源:origin: otto-de/jlineup
private void assertThatCookieContentIsIdentical(org.openqa.selenium.Cookie cookie, Cookie expectedCookie) {
assertThat(cookie.getName(), is(expectedCookie.name));
assertThat(cookie.getValue(), is(expectedCookie.value));
assertThat(cookie.getDomain(), is(expectedCookie.domain));
assertThat(cookie.getPath(), is(expectedCookie.path != null ? expectedCookie.path : "/"));
assertThat(cookie.getExpiry(), is(expectedCookie.expiry));
assertThat(cookie.isSecure(), is(expectedCookie.secure));
}
代码示例来源:origin: com.axway.ats.framework/ats-uiengine
/**
* Get all the cookies for the current domain. This is the equivalent of calling "document.cookie" and parsing the result
*
* @return {@link com.axway.ats.uiengine.elements.html.Cookie Cookie}s array
*/
@PublicAtsApi
public com.axway.ats.uiengine.elements.html.Cookie[] getCookies() {
Set<Cookie> cookies = webDriver.manage().getCookies();
com.axway.ats.uiengine.elements.html.Cookie[] cookiesArr = new com.axway.ats.uiengine.elements.html.Cookie[cookies.size()];
int i = 0;
for (Cookie c : cookies) {
cookiesArr[i++] = new com.axway.ats.uiengine.elements.html.Cookie(c.getName(),
c.getValue(),
c.getDomain(),
c.getPath(),
c.getExpiry(),
c.isSecure());
}
return cookiesArr;
}
代码示例来源:origin: fhoeben/hsac-fitnesse-fixtures
/**
* Converts Selenium cookie to Apache http client.
* @param browserCookie selenium cookie.
* @return http client format.
*/
protected ClientCookie convertCookie(Cookie browserCookie) {
BasicClientCookie cookie = new BasicClientCookie(browserCookie.getName(), browserCookie.getValue());
String domain = browserCookie.getDomain();
if (domain != null && domain.startsWith(".")) {
// http client does not like domains starting with '.', it always removes it when it receives them
domain = domain.substring(1);
}
cookie.setDomain(domain);
cookie.setPath(browserCookie.getPath());
cookie.setExpiryDate(browserCookie.getExpiry());
cookie.setSecure(browserCookie.isSecure());
if (browserCookie.isHttpOnly()) {
cookie.setAttribute("httponly", "");
}
return cookie;
}
}
代码示例来源:origin: Ardesco/Ebselen
/**
* Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
*
* @param seleniumCookieSet
* @return
*/
private HttpState mimicCookieState(Set<org.openqa.selenium.Cookie> seleniumCookieSet) {
HttpState mimicWebDriverCookieState = new HttpState();
for (org.openqa.selenium.Cookie seleniumCookie : seleniumCookieSet) {
Cookie httpClientCookie = new Cookie(seleniumCookie.getDomain(), seleniumCookie.getName(), seleniumCookie.getValue(), seleniumCookie.getPath(), seleniumCookie.getExpiry(), seleniumCookie.isSecure());
mimicWebDriverCookieState.addCookie(httpClientCookie);
}
return mimicWebDriverCookieState;
}
代码示例来源:origin: otto-de/jlineup
@Test
public void shouldSetCookies() {
//given
ArgumentCaptor<org.openqa.selenium.Cookie> cookieCaptor = ArgumentCaptor.forClass(org.openqa.selenium.Cookie.class);
Cookie cookieOne = new Cookie("someName", "someValue", "someDomain", "somePath", new Date(10000L), true);
Cookie cookieTwo = new Cookie("someOtherName", "someOtherValue", "someOtherDomain", "someOtherPath", new Date(10000000000L), false);
//when
testee.setCookies(ImmutableList.of(cookieOne, cookieTwo));
//then
verify(webDriverOptionsMock, times(2)).addCookie(cookieCaptor.capture());
List<org.openqa.selenium.Cookie> capturedCookies = cookieCaptor.getAllValues();
assertEquals("someName", capturedCookies.get(0).getName());
assertEquals("someValue", capturedCookies.get(0).getValue());
assertEquals("someDomain", capturedCookies.get(0).getDomain());
assertEquals("somePath", capturedCookies.get(0).getPath());
assertEquals(new Date(10000L), capturedCookies.get(0).getExpiry());
Assert.assertTrue(capturedCookies.get(0).isSecure());
assertEquals("someOtherName", capturedCookies.get(1).getName());
assertEquals("someOtherValue", capturedCookies.get(1).getValue());
assertEquals("someOtherDomain", capturedCookies.get(1).getDomain());
assertEquals("someOtherPath", capturedCookies.get(1).getPath());
assertEquals(new Date(10000000000L), capturedCookies.get(1).getExpiry());
assertFalse(capturedCookies.get(1).isSecure());
}
代码示例来源:origin: Ardesco/Powder-Monkey
/**
* Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
*
* @param seleniumCookieSet Set<Cookie>
*/
private BasicCookieStore mimicCookieState(Set<Cookie> seleniumCookieSet) {
BasicCookieStore copyOfWebDriverCookieStore = new BasicCookieStore();
for (Cookie seleniumCookie : seleniumCookieSet) {
BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue());
duplicateCookie.setDomain(seleniumCookie.getDomain());
duplicateCookie.setSecure(seleniumCookie.isSecure());
duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
duplicateCookie.setPath(seleniumCookie.getPath());
copyOfWebDriverCookieStore.addCookie(duplicateCookie);
}
return copyOfWebDriverCookieStore;
}
内容来源于网络,如有侵权,请联系作者删除!