Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/test/org/openqa/selenium/CookieImplementationTest.java
1865 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
package org.openqa.selenium;
19
20
import static org.assertj.core.api.Assertions.assertThat;
21
import static org.junit.jupiter.api.Assertions.assertThrows;
22
import static org.junit.jupiter.api.Assumptions.assumeTrue;
23
import static org.openqa.selenium.testing.drivers.Browser.ALL;
24
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
25
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
26
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
27
import static org.openqa.selenium.testing.drivers.Browser.IE;
28
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
29
30
import java.net.URI;
31
import java.util.Date;
32
import java.util.Random;
33
import java.util.Set;
34
import org.junit.jupiter.api.BeforeEach;
35
import org.junit.jupiter.api.Test;
36
import org.openqa.selenium.environment.DomainHelper;
37
import org.openqa.selenium.testing.Ignore;
38
import org.openqa.selenium.testing.JupiterTestBase;
39
import org.openqa.selenium.testing.NeedsSecureServer;
40
import org.openqa.selenium.testing.NotWorkingInRemoteBazelBuilds;
41
import org.openqa.selenium.testing.SwitchToTopAfterTest;
42
43
@NeedsSecureServer
44
class CookieImplementationTest extends JupiterTestBase {
45
46
private DomainHelper domainHelper;
47
private String cookiePage;
48
private static final Random random = new Random();
49
50
@BeforeEach
51
public void setUp() {
52
domainHelper = new DomainHelper(appServer);
53
assumeTrue(domainHelper.checkIsOnValidHostname());
54
cookiePage = domainHelper.getUrlForFirstValidHostname("/common/cookie");
55
56
deleteAllCookiesOnServerSide();
57
58
// This page is the deepest page we go to in the cookie tests
59
// We go to it to ensure that cookies with /common/... paths are deleted
60
// Do not write test in this class which use pages other than under /common
61
// without ensuring that cookies are deleted on those pages as required
62
try {
63
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
64
} catch (IllegalArgumentException e) {
65
// Ideally we would throw an IgnoredTestError or something here,
66
// but our test runner doesn't pay attention to those.
67
// Rely on the tests skipping themselves if they need to be on a useful page.
68
return;
69
}
70
71
driver.manage().deleteAllCookies();
72
assertNoCookiesArePresent();
73
}
74
75
@Test
76
public void testShouldGetCookieByName() {
77
String key = generateUniqueKey();
78
String value = "set";
79
assertCookieIsNotPresentWithName(key);
80
81
addCookieOnServerSide(new Cookie(key, value));
82
83
Cookie cookie = driver.manage().getCookieNamed(key);
84
assertThat(cookie.getValue()).isEqualTo(value);
85
}
86
87
@Test
88
@NotWorkingInRemoteBazelBuilds(FIREFOX)
89
public void testShouldBeAbleToAddCookie() {
90
String key = generateUniqueKey();
91
String value = "foo";
92
Cookie cookie = new Cookie.Builder(key, value).domain(domainHelper.getHostName()).build();
93
assertCookieIsNotPresentWithName(key);
94
95
driver.manage().addCookie(cookie);
96
97
assertCookieHasValue(key, value);
98
99
openAnotherPage();
100
assertCookieHasValue(key, value);
101
}
102
103
@Test
104
public void testGetAllCookies() {
105
String key1 = generateUniqueKey();
106
String key2 = generateUniqueKey();
107
108
assertCookieIsNotPresentWithName(key1);
109
assertCookieIsNotPresentWithName(key2);
110
111
Set<Cookie> cookies = driver.manage().getCookies();
112
int countBefore = cookies.size();
113
114
Cookie one = new Cookie.Builder(key1, "value").build();
115
Cookie two = new Cookie.Builder(key2, "value").build();
116
117
driver.manage().addCookie(one);
118
driver.manage().addCookie(two);
119
120
openAnotherPage();
121
cookies = driver.manage().getCookies();
122
assertThat(cookies.size()).isEqualTo(countBefore + 2);
123
124
assertThat(cookies.contains(one)).isTrue();
125
assertThat(cookies.contains(two)).isTrue();
126
}
127
128
@Test
129
public void testDeleteAllCookies() {
130
addCookieOnServerSide(new Cookie("foo", "set"));
131
assertSomeCookiesArePresent();
132
133
driver.manage().deleteAllCookies();
134
135
assertNoCookiesArePresent();
136
137
openAnotherPage();
138
assertNoCookiesArePresent();
139
}
140
141
@Test
142
public void testDeleteCookieWithName() {
143
String key1 = generateUniqueKey();
144
String key2 = generateUniqueKey();
145
146
addCookieOnServerSide(new Cookie(key1, "set"));
147
addCookieOnServerSide(new Cookie(key2, "set"));
148
149
assertCookieIsPresentWithName(key1);
150
assertCookieIsPresentWithName(key2);
151
152
driver.manage().deleteCookieNamed(key1);
153
154
assertCookieIsNotPresentWithName(key1);
155
assertCookieIsPresentWithName(key2);
156
157
openAnotherPage();
158
assertCookieIsNotPresentWithName(key1);
159
assertCookieIsPresentWithName(key2);
160
}
161
162
@Test
163
public void testShouldNotDeleteCookiesWithASimilarName() {
164
String cookieOneName = "fish";
165
Cookie cookie1 = new Cookie.Builder(cookieOneName, "cod").build();
166
Cookie cookie2 = new Cookie.Builder(cookieOneName + "x", "earth").build();
167
WebDriver.Options options = driver.manage();
168
assertCookieIsNotPresentWithName(cookie1.getName());
169
170
options.addCookie(cookie1);
171
options.addCookie(cookie2);
172
173
assertCookieIsPresentWithName(cookie1.getName());
174
175
options.deleteCookieNamed(cookieOneName);
176
Set<Cookie> cookies = options.getCookies();
177
178
assertThat(cookies).doesNotContain(cookie1);
179
assertThat(cookies).contains(cookie2);
180
}
181
182
@Test
183
public void testAddCookiesWithDifferentPathsThatAreRelatedToOurs() {
184
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
185
Cookie cookie1 = new Cookie.Builder("fish", "cod").path("/common/animals").build();
186
Cookie cookie2 = new Cookie.Builder("planet", "earth").path("/common/").build();
187
WebDriver.Options options = driver.manage();
188
options.addCookie(cookie1);
189
options.addCookie(cookie2);
190
191
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
192
193
assertCookieIsPresentWithName(cookie1.getName());
194
assertCookieIsPresentWithName(cookie2.getName());
195
196
driver.get(domainHelper.getUrlForFirstValidHostname("/common/simpleTest.html"));
197
assertCookieIsNotPresentWithName(cookie1.getName());
198
}
199
200
@SwitchToTopAfterTest
201
@Test
202
@Ignore(SAFARI)
203
@NotWorkingInRemoteBazelBuilds(CHROME)
204
@NotWorkingInRemoteBazelBuilds(EDGE)
205
@NotWorkingInRemoteBazelBuilds(FIREFOX)
206
public void testGetCookiesInAFrame() {
207
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
208
Cookie cookie1 = new Cookie.Builder("fish", "cod").path("/common/animals").build();
209
driver.manage().addCookie(cookie1);
210
211
driver.get(domainHelper.getUrlForFirstValidHostname("frameWithAnimals.html"));
212
assertCookieIsNotPresentWithName(cookie1.getName());
213
214
driver.switchTo().frame("iframe1");
215
assertCookieIsPresentWithName(cookie1.getName());
216
}
217
218
@Test
219
public void testCannotGetCookiesWithPathDifferingOnlyInCase() {
220
String cookieName = "fish";
221
Cookie cookie = new Cookie.Builder(cookieName, "cod").path("/Common/animals").build();
222
driver.manage().addCookie(cookie);
223
224
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
225
assertThat(driver.manage().getCookieNamed(cookieName)).isNull();
226
}
227
228
@Test
229
public void testShouldNotGetCookieOnDifferentDomain() {
230
assumeTrue(domainHelper.checkHasValidAlternateHostname());
231
232
String cookieName = "fish";
233
driver.manage().addCookie(new Cookie.Builder(cookieName, "cod").build());
234
assertCookieIsPresentWithName(cookieName);
235
236
driver.get(domainHelper.getUrlForSecondValidHostname("simpleTest.html"));
237
238
assertCookieIsNotPresentWithName(cookieName);
239
}
240
241
@Test
242
@NotWorkingInRemoteBazelBuilds(FIREFOX)
243
public void testShouldBeAbleToAddToADomainWhichIsRelatedToTheCurrentDomain() {
244
String cookieName = "name";
245
assertCookieIsNotPresentWithName(cookieName);
246
247
String shorter = domainHelper.getHostName().replaceFirst(".*?\\.", ".");
248
Cookie cookie = new Cookie.Builder(cookieName, "value").domain(shorter).build();
249
driver.manage().addCookie(cookie);
250
251
assertCookieIsPresentWithName(cookieName);
252
}
253
254
@Test
255
@Ignore(ALL)
256
public void testsShouldNotGetCookiesRelatedToCurrentDomainWithoutLeadingPeriod() {
257
String cookieName = "name";
258
assertCookieIsNotPresentWithName(cookieName);
259
260
String shorter = domainHelper.getHostName().replaceFirst(".*?\\.", "");
261
Cookie cookie = new Cookie.Builder(cookieName, "value").domain(shorter).build();
262
driver.manage().addCookie(cookie);
263
assertCookieIsNotPresentWithName(cookieName);
264
}
265
266
@Test
267
@NotWorkingInRemoteBazelBuilds(FIREFOX)
268
void testShouldBeAbleToIncludeLeadingPeriodInDomainName() {
269
String cookieName = "name";
270
assertCookieIsNotPresentWithName(cookieName);
271
272
String shorter = domainHelper.getHostName().replaceFirst(".*?\\.", ".");
273
Cookie cookie = new Cookie.Builder("name", "value").domain(shorter).build();
274
275
driver.manage().addCookie(cookie);
276
277
assertCookieIsPresentWithName(cookieName);
278
}
279
280
@Test
281
@NotWorkingInRemoteBazelBuilds(FIREFOX)
282
public void testShouldBeAbleToSetDomainToTheCurrentDomain() throws Exception {
283
URI url = new URI(driver.getCurrentUrl());
284
String host = url.getHost() + ":" + url.getPort();
285
286
Cookie cookie = new Cookie.Builder("fish", "cod").domain(host).build();
287
driver.manage().addCookie(cookie);
288
289
driver.get(domainHelper.getUrlForFirstValidHostname("javascriptPage.html"));
290
Set<Cookie> cookies = driver.manage().getCookies();
291
assertThat(cookies).contains(cookie);
292
}
293
294
@Test
295
@NotWorkingInRemoteBazelBuilds(CHROME)
296
@NotWorkingInRemoteBazelBuilds(EDGE)
297
@NotWorkingInRemoteBazelBuilds(FIREFOX)
298
public void testShouldWalkThePathToDeleteACookie() {
299
Cookie cookie1 = new Cookie.Builder("fish", "cod").build();
300
driver.manage().addCookie(cookie1);
301
302
driver.get(domainHelper.getUrlForFirstValidHostname("child/childPage.html"));
303
Cookie cookie2 = new Cookie("rodent", "hamster", "/common/child");
304
driver.manage().addCookie(cookie2);
305
306
driver.get(domainHelper.getUrlForFirstValidHostname("child/grandchild/grandchildPage.html"));
307
Cookie cookie3 = new Cookie("dog", "dalmatian", "/common/child/grandchild/");
308
driver.manage().addCookie(cookie3);
309
310
driver.get(domainHelper.getUrlForFirstValidHostname("child/grandchild/grandchildPage.html"));
311
driver.manage().deleteCookieNamed("rodent");
312
313
assertThat(driver.manage().getCookieNamed("rodent")).isNull();
314
315
Set<Cookie> cookies = driver.manage().getCookies();
316
assertThat(cookies).hasSize(2);
317
assertThat(cookies).contains(cookie1);
318
assertThat(cookies).contains(cookie3);
319
320
driver.manage().deleteAllCookies();
321
driver.get(domainHelper.getUrlForFirstValidHostname("child/grandchild/grandchildPage.html"));
322
assertNoCookiesArePresent();
323
}
324
325
@Test
326
@NotWorkingInRemoteBazelBuilds(FIREFOX)
327
public void testShouldIgnoreThePortNumberOfTheHostWhenSettingTheCookie() throws Exception {
328
URI uri = new URI(driver.getCurrentUrl());
329
String host = String.format("%s:%d", uri.getHost(), uri.getPort());
330
331
String cookieName = "name";
332
assertCookieIsNotPresentWithName(cookieName);
333
334
Cookie cookie = new Cookie.Builder(cookieName, "value").domain(host).build();
335
driver.manage().addCookie(cookie);
336
337
assertCookieIsPresentWithName(cookieName);
338
}
339
340
@Test
341
@NotWorkingInRemoteBazelBuilds(CHROME)
342
@NotWorkingInRemoteBazelBuilds(EDGE)
343
@NotWorkingInRemoteBazelBuilds(FIREFOX)
344
public void testCookieEqualityAfterSetAndGet() {
345
driver.get(domainHelper.getUrlForFirstValidHostname("animals"));
346
347
driver.manage().deleteAllCookies();
348
349
Cookie addedCookie =
350
new Cookie.Builder("fish", "cod")
351
.path("/common/animals")
352
.expiresOn(someTimeInTheFuture())
353
.build();
354
driver.manage().addCookie(addedCookie);
355
356
Set<Cookie> cookies = driver.manage().getCookies();
357
Cookie retrievedCookie = null;
358
for (Cookie temp : cookies) {
359
if (addedCookie.equals(temp)) {
360
retrievedCookie = temp;
361
break;
362
}
363
}
364
365
assertThat(retrievedCookie).isNotNull();
366
// Cookie.equals only compares name, domain and path
367
assertThat(retrievedCookie).isEqualTo(addedCookie);
368
}
369
370
@Test
371
public void testRetainsCookieExpiry() {
372
Cookie addedCookie =
373
new Cookie.Builder("fish", "cod")
374
.path("/common/animals")
375
.expiresOn(someTimeInTheFuture())
376
.build();
377
driver.manage().addCookie(addedCookie);
378
379
Cookie retrieved = driver.manage().getCookieNamed("fish");
380
assertThat(retrieved).isNotNull();
381
assertThat(retrieved.getExpiry()).isEqualTo(addedCookie.getExpiry());
382
}
383
384
@Test
385
@Ignore(IE)
386
@Ignore(SAFARI)
387
@NotWorkingInRemoteBazelBuilds(CHROME)
388
@NotWorkingInRemoteBazelBuilds(EDGE)
389
@NotWorkingInRemoteBazelBuilds(FIREFOX)
390
public void canHandleSecureCookie() {
391
driver.get(domainHelper.getSecureUrlForFirstValidHostname("animals"));
392
393
Cookie addedCookie =
394
new Cookie.Builder("fish", "cod").path("/common/animals").isSecure(true).build();
395
driver.manage().addCookie(addedCookie);
396
397
driver.navigate().refresh();
398
399
Cookie retrieved = driver.manage().getCookieNamed("fish");
400
assertThat(retrieved).isNotNull();
401
}
402
403
@Test
404
@Ignore(IE)
405
@Ignore(SAFARI)
406
@NotWorkingInRemoteBazelBuilds(CHROME)
407
@NotWorkingInRemoteBazelBuilds(EDGE)
408
@NotWorkingInRemoteBazelBuilds(FIREFOX)
409
public void testRetainsCookieSecure() {
410
driver.get(domainHelper.getSecureUrlForFirstValidHostname("animals"));
411
412
Cookie addedCookie =
413
new Cookie.Builder("fish", "cod").path("/common/animals").isSecure(true).build();
414
driver.manage().addCookie(addedCookie);
415
416
driver.navigate().refresh();
417
418
Cookie retrieved = driver.manage().getCookieNamed("fish");
419
assertThat(retrieved).isNotNull();
420
assertThat(retrieved.isSecure()).isTrue();
421
}
422
423
@Test
424
@Ignore(SAFARI)
425
@NotWorkingInRemoteBazelBuilds(CHROME)
426
@NotWorkingInRemoteBazelBuilds(EDGE)
427
@NotWorkingInRemoteBazelBuilds(FIREFOX)
428
public void canHandleHttpOnlyCookie() {
429
Cookie addedCookie =
430
new Cookie.Builder("fish", "cod").path("/common/animals").isHttpOnly(true).build();
431
432
addCookieOnServerSide(addedCookie);
433
434
driver.get(domainHelper.getUrlForFirstValidHostname("animals"));
435
Cookie retrieved = driver.manage().getCookieNamed("fish");
436
assertThat(retrieved).isNotNull();
437
}
438
439
@Test
440
@Ignore(SAFARI)
441
@NotWorkingInRemoteBazelBuilds(CHROME)
442
@NotWorkingInRemoteBazelBuilds(EDGE)
443
@NotWorkingInRemoteBazelBuilds(FIREFOX)
444
public void testRetainsHttpOnlyFlag() {
445
Cookie addedCookie =
446
new Cookie.Builder("fish", "cod").path("/common/animals").isHttpOnly(true).build();
447
448
addCookieOnServerSide(addedCookie);
449
450
driver.get(domainHelper.getUrlForFirstValidHostname("animals"));
451
Cookie retrieved = driver.manage().getCookieNamed("fish");
452
assertThat(retrieved).isNotNull();
453
assertThat(retrieved.isHttpOnly()).isTrue();
454
}
455
456
@Test
457
public void testSettingACookieThatExpiredInThePast() {
458
long expires = System.currentTimeMillis() - 1000;
459
Cookie cookie = new Cookie.Builder("expired", "yes").expiresOn(new Date(expires)).build();
460
driver.manage().addCookie(cookie);
461
462
cookie = driver.manage().getCookieNamed("fish");
463
assertThat(cookie)
464
.as("Cookie expired before it was set, so nothing should be returned")
465
.isNull();
466
}
467
468
@Test
469
public void testCanSetCookieWithoutOptionalFieldsSet() {
470
String key = generateUniqueKey();
471
String value = "foo";
472
Cookie cookie = new Cookie(key, value);
473
assertCookieIsNotPresentWithName(key);
474
475
driver.manage().addCookie(cookie);
476
477
assertCookieHasValue(key, value);
478
}
479
480
@Test
481
public void testDeleteNotExistedCookie() {
482
String key = generateUniqueKey();
483
assertCookieIsNotPresentWithName(key);
484
485
driver.manage().deleteCookieNamed(key);
486
}
487
488
@Test
489
public void testDeleteEmptyNamedCookie() {
490
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(""));
491
assertThrows(IllegalArgumentException.class, () -> driver.manage().deleteCookieNamed(" "));
492
}
493
494
@Test
495
public void testGetEmptyNamedCookie() {
496
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(""));
497
assertThrows(IllegalArgumentException.class, () -> driver.manage().getCookieNamed(" "));
498
}
499
500
@Test
501
@Ignore(value = ALL, reason = "Non W3C conformant")
502
public void testShouldDeleteOneOfTheCookiesWithTheSameName() {
503
driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));
504
Cookie cookie1 =
505
new Cookie.Builder("fish", "cod")
506
.domain(domainHelper.getHostName())
507
.path("/common/animals")
508
.build();
509
Cookie cookie2 =
510
new Cookie.Builder("fish", "tune")
511
.domain(domainHelper.getHostName())
512
.path("/common/")
513
.build();
514
WebDriver.Options options = driver.manage();
515
options.addCookie(cookie1);
516
options.addCookie(cookie2);
517
assertThat(driver.manage().getCookies()).hasSize(2);
518
519
driver.manage().deleteCookie(cookie1);
520
521
assertThat(driver.manage().getCookies()).hasSize(1);
522
Cookie retrieved = driver.manage().getCookieNamed("fish");
523
assertThat(retrieved).isEqualTo(cookie2);
524
}
525
526
private String generateUniqueKey() {
527
return String.format("key_%d", random.nextInt());
528
}
529
530
private void assertNoCookiesArePresent() {
531
assertThat(driver.manage().getCookies()).isEmpty();
532
String documentCookie = getDocumentCookieOrNull();
533
if (documentCookie != null) {
534
assertThat(documentCookie).isEmpty();
535
}
536
}
537
538
private void assertSomeCookiesArePresent() {
539
assertThat(driver.manage().getCookies()).isNotEmpty();
540
String documentCookie = getDocumentCookieOrNull();
541
if (documentCookie != null) {
542
assertThat(documentCookie).as("Cookies were empty").isNotEqualTo("");
543
}
544
}
545
546
private void assertCookieIsNotPresentWithName(final String key) {
547
assertThat(driver.manage().getCookieNamed(key)).as("Cookie with name " + key).isNull();
548
String documentCookie = getDocumentCookieOrNull();
549
if (documentCookie != null) {
550
assertThat(documentCookie).as("Cookie with name " + key).doesNotContain((key + "="));
551
}
552
}
553
554
private void assertCookieIsPresentWithName(final String key) {
555
assertThat(driver.manage().getCookieNamed(key)).as("Cookie with name " + key).isNotNull();
556
String documentCookie = getDocumentCookieOrNull();
557
if (documentCookie != null) {
558
assertThat(documentCookie)
559
.as("Cookie was not present with name " + key + ", got: " + documentCookie)
560
.contains(key + "=");
561
}
562
}
563
564
private void assertCookieHasValue(final String key, final String value) {
565
assertThat(driver.manage().getCookieNamed(key).getValue()).isEqualTo(value);
566
String documentCookie = getDocumentCookieOrNull();
567
if (documentCookie != null) {
568
assertThat(documentCookie)
569
.as("Cookie was present with name " + key)
570
.contains(key + "=" + value);
571
}
572
}
573
574
private String getDocumentCookieOrNull() {
575
if (!(driver instanceof JavascriptExecutor)) {
576
return null;
577
}
578
try {
579
return (String) ((JavascriptExecutor) driver).executeScript("return document.cookie");
580
} catch (UnsupportedOperationException e) {
581
return null;
582
}
583
}
584
585
private Date someTimeInTheFuture() {
586
return new Date(System.currentTimeMillis() + 100000);
587
}
588
589
private void openAnotherPage() {
590
driver.get(domainHelper.getUrlForFirstValidHostname("simpleTest.html"));
591
}
592
593
private void deleteAllCookiesOnServerSide() {
594
driver.get(cookiePage + "?action=deleteAll");
595
}
596
597
private void addCookieOnServerSide(Cookie cookie) {
598
StringBuilder url = new StringBuilder(cookiePage);
599
url.append("?action=add");
600
url.append("&name=").append(cookie.getName());
601
url.append("&value=").append(cookie.getValue());
602
if (cookie.getDomain() != null) {
603
url.append("&domain=").append(cookie.getDomain());
604
}
605
if (cookie.getPath() != null) {
606
url.append("&path=").append(cookie.getPath());
607
}
608
if (cookie.getExpiry() != null) {
609
url.append("&expiry=").append(cookie.getExpiry().getTime());
610
}
611
if (cookie.isSecure()) {
612
url.append("&secure=").append(cookie.isSecure());
613
}
614
if (cookie.isHttpOnly()) {
615
url.append("&httpOnly=").append(cookie.isHttpOnly());
616
}
617
driver.get(url.toString());
618
}
619
620
@Test
621
public void deleteAllCookies() {
622
assumeTrue(domainHelper.checkHasValidAlternateHostname());
623
624
Cookie cookie1 = new Cookie.Builder("fish1", "cod").domain(appServer.getHostName()).build();
625
Cookie cookie2 =
626
new Cookie.Builder("fish2", "tune").domain(appServer.getAlternateHostName()).build();
627
628
String url1 = domainHelper.getUrlForFirstValidHostname("/common");
629
String url2 = domainHelper.getUrlForSecondValidHostname("/common");
630
631
WebDriver.Options options = driver.manage();
632
633
options.addCookie(cookie1);
634
assertCookieIsPresentWithName(cookie1.getName());
635
636
driver.get(url2);
637
options.addCookie(cookie2);
638
assertCookieIsNotPresentWithName(cookie1.getName());
639
assertCookieIsPresentWithName(cookie2.getName());
640
641
driver.get(url1);
642
assertCookieIsPresentWithName(cookie1.getName());
643
assertCookieIsNotPresentWithName(cookie2.getName());
644
645
options.deleteAllCookies();
646
assertCookieIsNotPresentWithName(cookie1.getName());
647
648
driver.get(url2);
649
assertCookieIsPresentWithName(cookie2.getName());
650
}
651
}
652
653