Java Code Examples for org.openqa.selenium.Cookie#getValue()
The following examples show how to use
org.openqa.selenium.Cookie#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractHtmlEngine.java From ats-framework with Apache License 2.0 | 6 votes |
/** * 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; }
Example 2
Source File: CookieConverter.java From hsac-fitnesse-fixtures with Apache License 2.0 | 6 votes |
/** * 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; }
Example 3
Source File: DemoServletsAdapterTest.java From keycloak with Apache License 2.0 | 6 votes |
@Test public void testTokenInCookieSSORoot() { // Login String tokenCookie = loginToCustomerCookiePortalRoot(); Cookie cookie = driver.manage().getCookieNamed(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE); assertEquals("/", cookie.getPath()); // SSO to second app customerPortal.navigateTo(); assertLogged(); customerCookiePortalRoot.navigateTo(); assertLogged(); cookie = driver.manage().getCookieNamed(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE); String tokenCookie2 = cookie.getValue(); assertEquals(tokenCookie, tokenCookie2); assertEquals("/", cookie.getPath()); // Logout with httpServletRequest logoutFromCustomerCookiePortalRoot(); // Also should be logged-out from the second app customerPortal.navigateTo(); assertCurrentUrlStartsWithLoginUrlOf(testRealmPage); }
Example 4
Source File: CookieManager.java From vividus with Apache License 2.0 | 5 votes |
private static org.apache.http.cookie.Cookie createHttpClientCookie(Cookie seleniumCookie) { BasicClientCookie httpClientCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue()); httpClientCookie.setDomain(seleniumCookie.getDomain()); httpClientCookie.setPath(seleniumCookie.getPath()); httpClientCookie.setExpiryDate(seleniumCookie.getExpiry()); httpClientCookie.setSecure(seleniumCookie.isSecure()); httpClientCookie.setAttribute(ClientCookie.DOMAIN_ATTR, seleniumCookie.getDomain()); httpClientCookie.setAttribute(ClientCookie.PATH_ATTR, seleniumCookie.getPath()); return httpClientCookie; }
Example 5
Source File: FileDownloader.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 5 votes |
private BasicCookieStore getWebDriverCookies(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; }
Example 6
Source File: FileDownloader.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 5 votes |
private BasicCookieStore getWebDriverCookies(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; }
Example 7
Source File: KaptchaInvoker.java From phoenix.webui.framework with Apache License 2.0 | 5 votes |
/** * 获取验证码 * @param engine 引擎 * @param param 例如:data,http://localhost:8080/G2/captcha!getLastCode.do * @return 验证码 */ public static String execute(SeleniumEngine engine, String param) { WebDriver driver = engine.getDriver(); Options manage = driver.manage(); String[] paramArray = param.split(",", 2); if(paramArray.length != 2) { throw new RuntimeException("Param format is error, should be 'data,url'"); } String key = paramArray[0]; String url = paramArray[1]; Set<Cookie> cookies = manage.getCookies(); List<AtCookie> atCookieList = new ArrayList<AtCookie>(); for(Cookie cookie : cookies) { String name = cookie.getName(); String value = cookie.getValue(); AtCookie atCookie = new AtCookie(); atCookie.setName(name); atCookie.setValue(value); atCookie.setPath(cookie.getPath()); atCookie.setDomain(cookie.getDomain()); atCookieList.add(atCookie); } String code = HttpApiUtil.getJsonValue(url, atCookieList, key); return code; }
Example 8
Source File: BrowserTest.java From hsac-fitnesse-fixtures with Apache License 2.0 | 5 votes |
/** * Gets the value of the cookie with the supplied name. * @param cookieName name of cookie to get value from. * @return cookie's value if any. */ public String cookieValue(String cookieName) { String result = null; Cookie cookie = getSeleniumHelper().getCookie(cookieName); if (cookie != null) { result = cookie.getValue(); } return result; }
Example 9
Source File: WebDriverService.java From cerberus-source with GNU General Public License v3.0 | 5 votes |
@Override public String getFromCookie(Session session, String cookieName, String cookieParameter) { Cookie cookie = session.getDriver().manage().getCookieNamed(cookieName); if (cookie != null) { if (cookieParameter.equals("name")) { return cookie.getName(); } if (cookieParameter.equals("expiry")) { return cookie.getExpiry().toString(); } if (cookieParameter.equals("value")) { return cookie.getValue(); } if (cookieParameter.equals("domain")) { return cookie.getDomain(); } if (cookieParameter.equals("path")) { return cookie.getPath(); } if (cookieParameter.equals("isHttpOnly")) { return String.valueOf(cookie.isHttpOnly()); } if (cookieParameter.equals("isSecure")) { return String.valueOf(cookie.isSecure()); } } else { return "cookieNotFound"; } return null; }
Example 10
Source File: GetCookieByName.java From selenium with Apache License 2.0 | 4 votes |
@Override protected String handleSeleneseCommand(WebDriver driver, String name, String ignored) { Cookie cookie = driver.manage().getCookieNamed(name); return cookie == null ? null : cookie.getValue(); }
Example 11
Source File: AuthenticationSessionFailoverClusterTest.java From keycloak with Apache License 2.0 | 4 votes |
public static String getAuthSessionCookieValue(WebDriver driver) { Cookie authSessionCookie = driver.manage().getCookieNamed(AuthenticationSessionManager.AUTH_SESSION_ID); Assert.assertNotNull(authSessionCookie); return authSessionCookie.getValue(); }
Example 12
Source File: UserPageVisit.java From cia with Apache License 2.0 | 3 votes |
/** * Logout user. * * @throws Exception * the exception */ public void logoutUser() throws Exception { final WebElement logoutButton =findButton("Logout"); assertNotNull("Expect to find a Logout Button",logoutButton); final Cookie cookie= driver.manage().getCookieNamed("JSESSIONID"); final String sessionId = cookie.getValue(); performClickAction(logoutButton); final WebElement body = driver.findElement(By.tagName("body")); body.sendKeys(Keys.ESCAPE); final WebDriverWait wait = new WebDriverWait(driver, WAIT_FOR_PAGE_ELEMENT); wait.until(containsViewAction(ViewAction.VISIT_MAIN_VIEW)); wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.tagName("body"))); driver.navigate().refresh(); action.pause(500L).perform(); wait.until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete")); wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.tagName("body"))); final Cookie newCookie= driver.manage().getCookieNamed("JSESSIONID"); final String newSessionId = newCookie.getValue(); assertNotEquals(sessionId,newSessionId); final String url = systemTestTargetUrl +"#!" + CommonsViews.MAIN_VIEW_NAME; assertEquals(browser, url,driver.getCurrentUrl()); }