How to use isSecure method of org.openqa.selenium.Cookie.Builder class

Best Selenium code snippet using org.openqa.selenium.Cookie.Builder.isSecure

Source:CookieImplementationTest.java Github

copy

Full Screen

...300 driver.get(domainHelper.getSecureUrlForFirstValidHostname("animals"));301 Cookie addedCookie =302 new Cookie.Builder("fish", "cod")303 .path("/common/animals")304 .isSecure(true)305 .build();306 driver.manage().addCookie(addedCookie);307 driver.navigate().refresh();308 Cookie retrieved = driver.manage().getCookieNamed("fish");309 assertNotNull(retrieved);310 assertTrue(retrieved.isSecure());311 }312 @Ignore(value = {ANDROID, CHROME, FIREFOX, HTMLUNIT, IE, OPERA, OPERA_MOBILE, PHANTOMJS, SAFARI})313 @Test314 public void testRetainsHttpOnlyFlag() {315 Cookie addedCookie =316 new Cookie.Builder("fish", "cod")317 .path("/common/animals")318 .isHttpOnly(true)319 .build();320 addCookieOnServerSide(addedCookie);321 Cookie retrieved = driver.manage().getCookieNamed("fish");322 assertNotNull(retrieved);323 assertTrue(retrieved.isHttpOnly());324 }325 @Ignore(ANDROID)326 @Test327 public void testSettingACookieThatExpiredInThePast() {328 long expires = System.currentTimeMillis() - 1000;329 Cookie cookie = new Cookie.Builder("expired", "yes").expiresOn(new Date(expires)).build();330 driver.manage().addCookie(cookie);331 cookie = driver.manage().getCookieNamed("fish");332 assertNull(333 "Cookie expired before it was set, so nothing should be returned: " + cookie, cookie);334 }335 @Test336 public void testCanSetCookieWithoutOptionalFieldsSet() {337 String key = generateUniqueKey();338 String value = "foo";339 Cookie cookie = new Cookie(key, value);340 assertCookieIsNotPresentWithName(key);341 driver.manage().addCookie(cookie);342 assertCookieHasValue(key, value);343 }344 @Test345 public void testDeleteNotExistedCookie() {346 String key = generateUniqueKey();347 assertCookieIsNotPresentWithName(key);348 driver.manage().deleteCookieNamed(key);349 }350 @Ignore(value = {ANDROID, CHROME, FIREFOX, IE, OPERA, OPERA_MOBILE, PHANTOMJS, SAFARI})351 @Test352 public void testShouldDeleteOneOfTheCookiesWithTheSameName() {353 driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));354 Cookie cookie1 = new Cookie.Builder("fish", "cod")355 .domain(domainHelper.getHostName()).path("/common/animals").build();356 Cookie cookie2 = new Cookie.Builder("fish", "tune")357 .domain(domainHelper.getHostName()).path("/common/").build();358 WebDriver.Options options = driver.manage();359 options.addCookie(cookie1);360 options.addCookie(cookie2);361 assertEquals(driver.manage().getCookies().size(), 2);362 driver.manage().deleteCookie(cookie1);363 assertEquals(driver.manage().getCookies().size(), 1);364 Cookie retrieved = driver.manage().getCookieNamed("fish");365 assertNotNull("Cookie was null", retrieved);366 assertEquals(cookie2, retrieved);367 }368 private String generateUniqueKey() {369 return String.format("key_%d", random.nextInt());370 }371 private void assertNoCookiesArePresent() {372 Set<Cookie> cookies = driver.manage().getCookies();373 assertTrue("Cookies were not empty, present: " + cookies,374 cookies.isEmpty());375 String documentCookie = getDocumentCookieOrNull();376 if (documentCookie != null) {377 assertEquals("Cookies were not empty", "", documentCookie);378 }379 }380 private void assertSomeCookiesArePresent() {381 assertFalse("Cookies were empty",382 driver.manage().getCookies().isEmpty());383 String documentCookie = getDocumentCookieOrNull();384 if (documentCookie != null) {385 assertNotSame("Cookies were empty", "", documentCookie);386 }387 }388 private void assertCookieIsNotPresentWithName(final String key) {389 assertNull("Cookie was present with name " + key, driver.manage().getCookieNamed(key));390 String documentCookie = getDocumentCookieOrNull();391 if (documentCookie != null) {392 assertThat("Cookie was present with name " + key,393 documentCookie,394 not(containsString(key + "=")));395 }396 }397 private void assertCookieIsPresentWithName(final String key) {398 assertNotNull("Cookie was not present with name " + key, driver.manage().getCookieNamed(key));399 String documentCookie = getDocumentCookieOrNull();400 if (documentCookie != null) {401 assertThat("Cookie was not present with name " + key + ", got: " + documentCookie,402 documentCookie,403 containsString(key + "="));404 }405 }406 private void assertCookieHasValue(final String key, final String value) {407 assertEquals("Cookie had wrong value",408 value,409 driver.manage().getCookieNamed(key).getValue());410 String documentCookie = getDocumentCookieOrNull();411 if (documentCookie != null) {412 assertThat("Cookie was present with name " + key,413 documentCookie,414 containsString(key + "=" + value));415 }416 }417 private String getDocumentCookieOrNull() {418 if (!(driver instanceof JavascriptExecutor)) {419 return null;420 }421 try {422 return (String) ((JavascriptExecutor) driver).executeScript("return document.cookie");423 } catch (UnsupportedOperationException e) {424 return null;425 }426 }427 private Date someTimeInTheFuture() {428 return new Date(System.currentTimeMillis() + 100000);429 }430 private void openAnotherPage() {431 driver.get(domainHelper.getUrlForFirstValidHostname("simpleTest.html"));432 }433 private void deleteAllCookiesOnServerSide() {434 driver.get(cookiePage + "?action=deleteAll");435 }436 private void addCookieOnServerSide(Cookie cookie) {437 StringBuilder url = new StringBuilder(cookiePage);438 url.append("?action=add");439 url.append("&name=").append(cookie.getName());440 url.append("&value=").append(cookie.getValue());441 if (cookie.getDomain() != null) {442 url.append("&domain=").append(cookie.getDomain());443 }444 if (cookie.getPath() != null) {445 url.append("&path=").append(cookie.getPath());446 }447 if (cookie.getExpiry() != null) {448 url.append("&expiry=").append(cookie.getExpiry().getTime());449 }450 if (cookie.isSecure()) {451 url.append("&secure=").append(cookie.isSecure());452 }453 if (cookie.isHttpOnly()) {454 url.append("&httpOnly=").append(cookie.isHttpOnly());455 }456 driver.get(url.toString());457 }458}...

Full Screen

Full Screen

Source:CookieTest.java Github

copy

Full Screen

...64 Assert.assertEquals("test", cookie.getValue());65 Assert.assertEquals(".localhost", cookie.getDomain());66 Assert.assertEquals("/", cookie.getPath());67 Assert.assertTrue(((cookie.getExpiry()) != null));68 Assert.assertEquals(false, cookie.isSecure());69 org.openqa.selenium.Cookie cookie2 = driver.manage().getCookieNamed("test2");70 Assert.assertEquals("test2", cookie2.getName());71 Assert.assertEquals("test2", cookie2.getValue());72 Assert.assertEquals(".localhost", cookie2.getDomain());73 Assert.assertEquals("/", cookie2.getPath());74 Assert.assertEquals(false, cookie2.isSecure());75 Assert.assertTrue(((cookie2.getExpiry()) == null));76 }77 @Test78 public void gettingAllCookiesOnANonCookieSettingPage() {79 server.setHttpHandler("GET", CookieTest.EMPTY_CALLBACK);80 goToPage();81 Assert.assertEquals(0, getCookies().length);82 }83 @Test84 public void deletingAllCookies() {85 server.setHttpHandler("GET", CookieTest.COOKIE_SETTING_CALLBACK);86 goToPage();87 driver.manage().deleteAllCookies();88 Assert.assertEquals(0, getCookies().length);89 }90 @Test91 public void deletingOneCookie() {92 server.setHttpHandler("GET", CookieTest.COOKIE_SETTING_CALLBACK);93 goToPage();94 driver.manage().deleteCookieNamed("test");95 org.openqa.selenium.Cookie[] cookies = getCookies();96 Assert.assertEquals(1, cookies.length);97 Assert.assertEquals("test2", cookies[0].getName());98 }99 @Test100 public void addingACookie() {101 server.setHttpHandler("GET", CookieTest.EMPTY_CALLBACK);102 goToPage();103 driver.manage().addCookie(new org.openqa.selenium.Cookie("newCookie", "newValue", ".localhost", "/", null, false, false));104 org.openqa.selenium.Cookie[] cookies = getCookies();105 Assert.assertEquals(1, cookies.length);106 Assert.assertEquals("newCookie", cookies[0].getName());107 Assert.assertEquals("newValue", cookies[0].getValue());108 Assert.assertEquals(".localhost", cookies[0].getDomain());109 Assert.assertEquals("/", cookies[0].getPath());110 Assert.assertEquals(false, cookies[0].isSecure());111 Assert.assertEquals(false, cookies[0].isHttpOnly());112 }113 @Test114 public void modifyingACookie() {115 server.setHttpHandler("GET", CookieTest.COOKIE_SETTING_CALLBACK);116 goToPage();117 driver.manage().addCookie(new org.openqa.selenium.Cookie("test", "newValue", "localhost", "/", null, false));118 org.openqa.selenium.Cookie[] cookies = getCookies();119 Assert.assertEquals(2, cookies.length);120 Assert.assertEquals("test", cookies[1].getName());121 Assert.assertEquals("newValue", cookies[1].getValue());122 Assert.assertEquals(".localhost", cookies[1].getDomain());123 Assert.assertEquals("/", cookies[1].getPath());124 Assert.assertEquals(false, cookies[1].isSecure());125 Assert.assertEquals("test2", cookies[0].getName());126 Assert.assertEquals("test2", cookies[0].getValue());127 Assert.assertEquals(".localhost", cookies[0].getDomain());128 Assert.assertEquals("/", cookies[0].getPath());129 Assert.assertEquals(false, cookies[0].isSecure());130 }131 @Test132 public void shouldRetainCookieInfo() {133 server.setHttpHandler("GET", CookieTest.EMPTY_CALLBACK);134 goToPage();135 // Added cookie (in a sub-path - allowed)136 org.openqa.selenium.Cookie addedCookie = // < now + 100sec137 new org.openqa.selenium.Cookie.Builder("fish", "cod").expiresOn(new Date(((System.currentTimeMillis()) + (100 * 1000)))).path("/404").domain("localhost").build();138 driver.manage().addCookie(addedCookie);139 // Search cookie on the root-path and fail to find it140 org.openqa.selenium.Cookie retrieved = driver.manage().getCookieNamed("fish");141 Assert.assertNull(retrieved);142 // Go to the "/404" sub-path (to find the cookie)143 goToPage("404");144 retrieved = driver.manage().getCookieNamed("fish");145 Assert.assertNotNull(retrieved);146 // Check that it all matches147 Assert.assertEquals(addedCookie.getName(), retrieved.getName());148 Assert.assertEquals(addedCookie.getValue(), retrieved.getValue());149 Assert.assertEquals(addedCookie.getExpiry(), retrieved.getExpiry());150 Assert.assertEquals(addedCookie.isSecure(), retrieved.isSecure());151 Assert.assertEquals(addedCookie.getPath(), retrieved.getPath());152 Assert.assertTrue(retrieved.getDomain().contains(addedCookie.getDomain()));153 }154 @Test(expected = InvalidCookieDomainException.class)155 public void shouldNotAllowToCreateCookieOnDifferentDomain() {156 goToPage();157 // Added cookie (in a sub-path)158 org.openqa.selenium.Cookie addedCookie = // < now + 100sec159 new org.openqa.selenium.Cookie.Builder("fish", "cod").expiresOn(new Date(((System.currentTimeMillis()) + (100 * 1000)))).path("/404").domain("github.com").build();160 driver.manage().addCookie(addedCookie);161 }162 @Test163 public void shouldAllowToDeleteCookiesEvenIfNotSet() {164 WebDriver d = getDriver();165 d.get("https://github.com/");166 // Clear all cookies167 Assert.assertTrue(((d.manage().getCookies().size()) > 0));168 d.manage().deleteAllCookies();169 Assert.assertEquals(d.manage().getCookies().size(), 0);170 // All cookies deleted, call deleteAllCookies again. Should be a no-op.171 d.manage().deleteAllCookies();172 d.manage().deleteCookieNamed("non_existing_cookie");173 Assert.assertEquals(d.manage().getCookies().size(), 0);174 }175 @Test176 public void shouldAllowToSetCookieThatIsAlreadyExpired() {177 WebDriver d = getDriver();178 d.get("https://github.com/");179 // Clear all cookies180 Assert.assertTrue(((d.manage().getCookies().size()) > 0));181 d.manage().deleteAllCookies();182 Assert.assertEquals(d.manage().getCookies().size(), 0);183 // Added cookie that expires in the past184 org.openqa.selenium.Cookie addedCookie = // < now - 1 second185 new org.openqa.selenium.Cookie.Builder("expired", "yes").expiresOn(new Date(((System.currentTimeMillis()) - 1000))).build();186 d.manage().addCookie(addedCookie);187 org.openqa.selenium.Cookie cookie = d.manage().getCookieNamed("expired");188 Assert.assertNull(cookie);189 }190 @Test(expected = Exception.class)191 public void shouldThrowExceptionIfAddingCookieBeforeLoadingAnyUrl() {192 // NOTE: At the time of writing, this test doesn't pass with FirefoxDriver.193 // ChromeDriver is fine instead.194 String xval = "123456789101112";// < detro: I buy you a beer if you guess what am I quoting here195 WebDriver d = getDriver();196 // Set cookie, without opening any page: should throw an exception197 d.manage().addCookie(new org.openqa.selenium.Cookie("x", xval));198 }199 @Test200 public void shouldBeAbleToCreateCookieViaJavascriptOnGoogle() {201 String ckey = "cookiekey";202 String cval = "cookieval";203 WebDriver d = getDriver();204 d.get("http://www.google.com");205 JavascriptExecutor js = ((JavascriptExecutor) (d));206 // Of course, no cookie yet(!)207 org.openqa.selenium.Cookie c = d.manage().getCookieNamed(ckey);208 Assert.assertNull(c);209 // Attempt to create cookie on multiple Google domains210 js.executeScript((((((((((((((((((((((("javascript:(" + (("function() {" + " cook = document.cookie;") + " begin = cook.indexOf('")) + ckey) + "=');") + " var val;") + " if (begin !== -1) {") + " var end = cook.indexOf(\";\",begin);") + " if (end === -1)") + " end=cook.length;") + " val=cook.substring(begin+11,end);") + " }") + " val = ['") + cval) + "'];") + " if (val) {") + " var d=Array('com','co.jp','ca','fr','de','co.uk','it','es','com.br');") + " for (var i = 0; i < d.length; i++) {") + " document.cookie = '") + ckey) + "='+val+';path=/;domain=.google.'+d[i]+'; ';") + " }") + " }") + "})();"));211 c = d.manage().getCookieNamed(ckey);212 Assert.assertNotNull(c);213 Assert.assertEquals(cval, c.getValue());214 // Set cookie as empty215 js.executeScript(((((("javascript:(" + ((("function() {" + " var d = Array('com','co.jp','ca','fr','de','co.uk','it','cn','es','com.br');") + " for(var i = 0; i < d.length; i++) {") + " document.cookie='")) + ckey) + "=;path=/;domain=.google.'+d[i]+'; ';") + " }") + "})();"));216 c = d.manage().getCookieNamed(ckey);217 Assert.assertNotNull(c);218 Assert.assertEquals("", c.getValue());219 }220 @Test221 public void addingACookieWithDefaults() {222 server.setHttpHandler("GET", CookieTest.EMPTY_CALLBACK);223 goToPage();224 long startTime = new Date().getTime();225 driver.manage().addCookie(new org.openqa.selenium.Cookie("newCookie", "newValue"));226 org.openqa.selenium.Cookie[] cookies = getCookies();227 Assert.assertEquals(1, cookies.length);228 Assert.assertEquals("newCookie", cookies[0].getName());229 Assert.assertEquals("newValue", cookies[0].getValue());230 Assert.assertEquals(".localhost", cookies[0].getDomain());231 Assert.assertEquals("/", cookies[0].getPath());232 Assert.assertEquals(false, cookies[0].isSecure());233 Assert.assertEquals(false, cookies[0].isHttpOnly());234 // expiry > 19 years in the future235 Assert.assertTrue(((startTime + 599184000000L) <= (cookies[0].getExpiry().getTime())));236 }237}...

Full Screen

Full Screen

Source:SeleniumCookieConverterTest.java Github

copy

Full Screen

...36 DeserializableCookie output = new SeleniumCookieConverter().doForward(input);37 assertEquals("cookie equals", true, isEqualEnough(output, input));38 }39 private org.openqa.selenium.Cookie toSeleniumCookie(org.apache.http.cookie.Cookie reference, boolean httpOnly) {40 org.openqa.selenium.Cookie c = new org.openqa.selenium.Cookie(reference.getName(), reference.getValue(), reference.getDomain(), reference.getPath(), reference.getExpiryDate(), reference.isSecure(), httpOnly);41 return c;42 }43 @Test44 public void doBackward() throws Exception {45 String exampleSetCookieHeaderValue = "YP=v=AwAAY&d=AEgAMEUCIAphCQ1YdKiZJVYwQOKscLhHZEHsT5JhZcSiQ.Hi5AjKAiEAhqK8LNfPJpAyDnvLzNZV_ByH9Zjz3v55lqYO2eiL4msA; expires=Thu, 29-Nov-2018 19:22:24 GMT; path=/; domain=.yahoo.com; secure; HttpOnly";46 org.apache.http.cookie.Cookie reference = parseCookie(URI.create("https://yahoo.com:443/some/where"), exampleSetCookieHeaderValue);47 DeserializableCookie input = toDeserializableCookie(reference);48 org.openqa.selenium.Cookie output = new SeleniumCookieConverter().doBackward(input);49 assertEquals("cookie equals", true, isEqualEnough(input, output));50 }51 private static boolean isEqualEnough(DeserializableCookie a, org.openqa.selenium.Cookie b) {52 EqualsBuilder eq = new EqualsBuilder()53 .append(b.getDomain(), a.getDomain())54 .append(b.getExpiry(), a.getExpiryAsDate())55 .append(b.getName(), a.getName())56 .append(b.getPath(), a.getPath())57 .append(b.getValue(), a.getValue())58 .append(b.isSecure(), a.isSecure())59 .append(b.isHttpOnly(), a.isHttpOnly());60 return eq.isEquals();61 }62 private static DeserializableCookie toDeserializableCookie(org.apache.http.cookie.Cookie reference) {63 DeserializableCookie.Builder c = DeserializableCookie.builder(reference.getName(), reference.getValue());64 c.setComment(reference.getComment());65 c.setDomain(reference.getDomain());66 Date refExpiryDate = reference.getExpiryDate();67 if (refExpiryDate != null) {68 c.expiry(refExpiryDate.toInstant());69 }70 c.setPath(reference.getPath());71 c.setSecure(reference.isSecure());72 return c.build();73 }74 private static CookieOrigin urlToOrigin(URI uri) {75 CookieOrigin origin = new CookieOrigin(uri.getHost(), uri.getPort(), uri.getPath(), "https".equals(uri.getScheme()));76 return origin;77 }78 private static org.apache.http.cookie.Cookie parseCookie(URI cookieOrigin, String setCookieHeaderValue) throws MalformedCookieException {79 return parseCookie(urlToOrigin(cookieOrigin), setCookieHeaderValue);80 }81 private static org.apache.http.cookie.Cookie parseCookie(CookieOrigin origin, String setCookieHeaderValue) throws MalformedCookieException {82 CookieSpec cookieSpec = new DefaultCookieSpecProvider().create(new BasicHttpContext());83 List<org.apache.http.cookie.Cookie> cookies = cookieSpec.parse(new BasicHeader(HttpHeaders.SET_COOKIE, setCookieHeaderValue), origin);84 checkState(cookies.size() == 1, "wrong number of cookies in header: %s", cookies.size());85 return cookies.get(0);...

Full Screen

Full Screen

Source:SessionUtil.java Github

copy

Full Screen

...41 String domain = m.getString("domain");42 String path = m.getString("path");43 Boolean secure = m.getBoolean("secure");44 Boolean httpOnly = m.getBoolean("httpOnly");45 builder.domain(domain).path(path).isSecure(secure).isHttpOnly(httpOnly);46 Long expiry = m.getLong("expiry");47 if (expiry != null) {48 builder.expiresOn(new Date(expiry));49 }50 Cookie cookie = builder.build();51 driver.manage().addCookie(cookie);52 } catch (Exception e) {53 throw new RuntimeException(e);54 }55 });56 JSONArray lc = session.getJSONArray("lc");57 WebStorage webStorage = (WebStorage) new Augmenter().augment(driver);58 LocalStorage localStorage = webStorage.getLocalStorage();59 lc.forEach(o -> {60 try {61 JSONObject item = (JSONObject) o;62 String key = item.getString("key");63 String value = item.getString("value");64 localStorage.setItem(key, value);65 } catch (Exception e) {66 throw new RuntimeException(e);67 }68 });69 }70 public static JSONObject getSessionV2(WebDriver driver) {71 JSONObject session = new JSONObject();72 Set<Cookie> set = driver.manage().getCookies();73 session.put("cookie", set);74 JSONObject lc = new JSONObject();75 WebStorage webStorage = (WebStorage) new Augmenter().augment(driver);76 LocalStorage localStorage = webStorage.getLocalStorage();77 localStorage.keySet().forEach(c -> {78 lc.put(c, localStorage.getItem(c));79 });80 session.put("lc", lc);81 return session;82 }83 public static void setSessionV2(WebDriver driver, JSONObject session) {84 JSONArray cookies = session.getJSONArray("cookie");85 cookies.forEach(o -> {86 try {87 JSONObject m = (JSONObject) o;88 Cookie.Builder builder = new Cookie.Builder(m.getString("name"), m.getString("value"));89 String domain = m.getString("domain");90 String path = m.getString("path");91 Boolean secure = m.getBoolean("secure");92 Boolean httpOnly = m.getBoolean("httpOnly");93 builder.domain(domain).path(path).isSecure(secure).isHttpOnly(httpOnly);94 Long expiry = m.getLong("expiry");95 if (expiry != null) {96 builder.expiresOn(new Date(expiry));97 }98 Cookie cookie = builder.build();99 driver.manage().addCookie(cookie);100 } catch (Exception e) {101 throw new RuntimeException(e);102 }103 });104 JSONObject lc = session.getJSONObject("lc");105 WebStorage webStorage = (WebStorage) new Augmenter().augment(driver);106 LocalStorage localStorage = webStorage.getLocalStorage();107 lc.forEach((k, v) -> {...

Full Screen

Full Screen

Source:WebDriver81CookiesTest.java Github

copy

Full Screen

...92 Cookie aNewCookie = new Cookie( aCookie.getName(),93 String.valueOf(42),94 aCookie.getDomain(),95 aCookie.getPath(),96 aCookie.getExpiry(),aCookie.isSecure());97 98 driver.manage().deleteCookie(aCookie);99 driver.manage().addCookie(aNewCookie);100 101 searchBox.clear();102 searchBox.sendKeys("New Cookie Test");103 searchButton.click();104 105 aCookie = driver.manage().getCookieNamed("seleniumSimplifiedSearchNumVisits");106 assertEquals("This should be my first visit", "43", aCookie.getValue());107 108 }109 110 @Test111 public void webDriverUpdateCookieBuilder() {112 113 searchBox.clear();114 searchBox.sendKeys("Cookie Test");115 searchButton.click();116 117 refreshSearchPage();118 119 Cookie aCookie = driver.manage().getCookieNamed("seleniumSimplifiedSearchNumVisits");120 assertEquals("This should be my first visit", "1", aCookie.getValue());121 122 // Clone Cookie and set Value to what is wanted123 Cookie aNewCookie = new Cookie.Builder( aCookie.getName(), String.valueOf(29))124 .domain(aCookie.getDomain())125 .path(aCookie.getPath())126 .expiresOn(aCookie.getExpiry())127 .isSecure(aCookie.isSecure()).build();128 129 driver.manage().deleteCookie(aCookie);130 driver.manage().addCookie(aNewCookie);131 132 searchBox.clear();133 searchBox.sendKeys("Another Cookie Test");134 searchButton.click();135 136 aCookie = driver.manage().getCookieNamed("seleniumSimplifiedSearchNumVisits");137 assertEquals("This should be my first visit", "30", aCookie.getValue());138 139 }140 141 @AfterClass ...

Full Screen

Full Screen

Source:CookieAdapter.java Github

copy

Full Screen

...35 }36 if(cookie.getPath() != null){37 newCookie.path(cookie.getPath());38 }39 if(cookie.isSecured()){40 newCookie.isSecure(cookie.isSecured());41 }42 if(cookie.getVersion() != -1){43 System.out.println("NOTE: The cookie taken from RestAssured has a version attribute of '" + cookie.getVersion() + "'. Selenium doesn't support the addition of version so this has been discarded");44 }45 return newCookie.build();46 }47 public Cookie convertToRestAssured(org.openqa.selenium.Cookie cookie) {48 Cookie.Builder newCookie = new Cookie.Builder(cookie.getName(), cookie.getValue());49 if(cookie.getDomain() != null){50 newCookie.setDomain(cookie.getDomain());51 }52 if(cookie.getExpiry() != null){53 if(expiryType.equals(ExpiryType.EXPIRY)){54 newCookie.setExpiryDate(cookie.getExpiry());55 } else if(expiryType.equals(ExpiryType.MAXAGE)){56 Calendar futureDate = Calendar.getInstance();57 futureDate.setTime(cookie.getExpiry());58 Calendar currentDate = Calendar.getInstance();59 long end = TimeUnit.MILLISECONDS.toSeconds(futureDate.getTimeInMillis());60 long start = TimeUnit.MILLISECONDS.toSeconds(currentDate.getTimeInMillis());61 int result = toIntExact(end - start);62 newCookie.setMaxAge(result);63 }64 }65 if(cookie.isHttpOnly()){66 newCookie.setHttpOnly(cookie.isHttpOnly());67 }68 if(cookie.isSecure()){69 newCookie.setSecured(cookie.isSecure());70 }71 if(cookie.getPath() != null){72 newCookie.setPath(cookie.getPath());73 }74 return newCookie.build();75 }76}...

Full Screen

Full Screen

Source:selenium.java Github

copy

Full Screen

...42 new Cookie.Builder(cookie.getName(), "A_SHOW_MINICART")43 .domain(cookie.getDomain())44 .expiresOn(cookie.getExpiry())45 .path(cookie.getPath())46 .isSecure(cookie.isSecure())47 .build()48 );49 50 */51 }52}...

Full Screen

Full Screen

Source:SeleniumCookieConverter.java Github

copy

Full Screen

...20 DeserializableCookie d = DeserializableCookie.builder(cookie.getName(), cookie.getValue())21 .domain(cookie.getDomain())22 .expiry(expiryInstant)23 .path(cookie.getPath())24 .secure(cookie.isSecure())25 .httpOnly(cookie.isHttpOnly()).build();26 return d;27 }28 @Override29 protected org.openqa.selenium.Cookie doBackward(DeserializableCookie d) {30 org.openqa.selenium.Cookie c = new org.openqa.selenium.Cookie(d.getName(), d.getValue(), d.getDomain(), d.getPath(), d.getExpiryAsDate(), d.isSecure(), d.isHttpOnly());31 return c;32 }33}...

Full Screen

Full Screen

isSecure

Using AI Code Generation

copy

Full Screen

1Cookie cookie = new Cookie.Builder("name", "value")2 .isSecure(true)3 .build();4driver.manage().addCookie(cookie);5Cookie cookie = new Cookie.Builder("name", "value")6 .isHttpOnly(true)7 .build();8driver.manage().addCookie(cookie);9Cookie cookie = new Cookie.Builder("name", "value")10 .isHttpOnly(true)11 .build();12driver.manage().addCookie(cookie);13Cookie cookie = new Cookie.Builder("name", "value")14 .isHttpOnly(true)15 .build();16driver.manage().addCookie(cookie);17Cookie cookie = new Cookie.Builder("name", "value")18 .isHttpOnly(true)19 .build();20driver.manage().addCookie(cookie);21Cookie cookie = new Cookie.Builder("name", "value")22 .isHttpOnly(true)23 .build();24driver.manage().addCookie(cookie);25Cookie cookie = new Cookie.Builder("name", "value")26 .isHttpOnly(true)27 .build();28driver.manage().addCookie(cookie);29Cookie cookie = new Cookie.Builder("name", "value")30 .isHttpOnly(true)31 .build();32driver.manage().addCookie(cookie);33Cookie cookie = new Cookie.Builder("name", "value")34 .isHttpOnly(true)35 .build();36driver.manage().addCookie(cookie);37Cookie cookie = new Cookie.Builder("name", "value")38 .isHttpOnly(true)39 .build();40driver.manage().addCookie(cookie);41Cookie cookie = new Cookie.Builder("name", "value")42 .isHttpOnly(true)43 .build();44driver.manage().addCookie(cookie);

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Cookie.Builder

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful