@@ -53,37 +53,102 @@ module WebDriver
53
53
end
54
54
55
55
describe 'cookie management' do
56
- it 'should get all' do
56
+ after { driver . manage . delete_all_cookies }
57
+
58
+ it 'should not show secure when insecure' do
57
59
driver . navigate . to url_for ( 'xhtmlTest.html' )
58
- driver . manage . add_cookie name : 'foo' , value : 'bar'
60
+ driver . manage . add_cookie name : 'security' ,
61
+ value : 'secure' ,
62
+ secure : true
59
63
60
64
cookies = driver . manage . all_cookies
65
+ expect ( cookies . size ) . to eq ( 0 )
66
+ end
61
67
62
- expect ( cookies . size ) . to eq ( 1 )
63
- expect ( cookies . first [ :name ] ) . to eq ( 'foo' )
64
- expect ( cookies . first [ :value ] ) . to eq ( 'bar' )
68
+ it 'should respect path' do
69
+ driver . navigate . to url_for ( 'xhtmlTest.html' )
70
+ driver . manage . add_cookie name : 'path' ,
71
+ value : 'specified' ,
72
+ path : '/child'
73
+ cookies = driver . manage . all_cookies
74
+ expect ( cookies . size ) . to eq ( 0 )
75
+
76
+ driver . navigate . to url_for ( 'child/childPage.html' )
77
+ expect ( driver . manage . cookie_named ( 'path' ) [ :path ] ) . to eq '/child'
78
+ end
79
+
80
+ it 'should add expiration with DateTime' do
81
+ driver . navigate . to url_for ( 'xhtmlTest.html' )
82
+
83
+ expected = ( Date . today + 2 ) . to_datetime
84
+ driver . manage . add_cookie name : 'expiration' ,
85
+ value : 'datetime' ,
86
+ expires : expected
87
+
88
+ actual = driver . manage . cookie_named ( 'expiration' ) [ :expires ]
89
+ expect ( actual ) . to be_kind_of ( DateTime )
90
+ expect ( actual ) . to eq ( expected )
91
+ end
92
+
93
+ it 'should add expiration with Time' do
94
+ driver . navigate . to url_for ( 'xhtmlTest.html' )
95
+
96
+ expected = ( Date . today + 2 ) . to_datetime
97
+ driver . manage . add_cookie name : 'expiration' ,
98
+ value : 'time' ,
99
+ expires : expected . to_time
100
+
101
+ actual = driver . manage . cookie_named ( 'expiration' ) [ :expires ]
102
+ expect ( actual ) . to be_kind_of ( DateTime )
103
+ expect ( actual ) . to eq ( expected )
104
+ end
105
+
106
+ it 'should add expiration with Number' do
107
+ driver . navigate . to url_for ( 'xhtmlTest.html' )
108
+
109
+ expected = ( Date . today + 2 ) . to_datetime
110
+ driver . manage . add_cookie name : 'expiration' ,
111
+ value : 'number' ,
112
+ expires : expected . to_time . to_f
113
+
114
+ actual = driver . manage . cookie_named ( 'expiration' ) [ :expires ]
115
+ expect ( actual ) . to be_kind_of ( DateTime )
116
+ expect ( actual ) . to eq ( expected )
65
117
end
66
118
67
119
it 'should add sameSite cookie with attribute Strict' , only : { browser : %i[ chrome edge firefox ] } do
68
120
driver . navigate . to url_for ( 'xhtmlTest.html' )
69
- driver . manage . add_cookie name : 'foo ' , value : 'bar ' , same_site : 'Strict'
121
+ driver . manage . add_cookie name : 'samesite ' , value : 'strict ' , same_site : 'Strict'
70
122
71
- expect ( driver . manage . cookie_named ( 'foo ' ) [ :same_site ] ) . to eq ( 'Strict' )
123
+ expect ( driver . manage . cookie_named ( 'samesite ' ) [ :same_site ] ) . to eq ( 'Strict' )
72
124
end
73
125
74
126
it 'should add sameSite cookie with attribute Lax' , only : { browser : %i[ chrome edge firefox ] } do
75
127
driver . navigate . to url_for ( 'xhtmlTest.html' )
76
- driver . manage . add_cookie name : 'foo' , value : 'bar' , same_site : 'Lax'
77
- expect ( driver . manage . cookie_named ( 'foo' ) [ :same_site ] ) . to eq ( 'Lax' )
128
+ driver . manage . add_cookie name : 'samesite' ,
129
+ value : 'lax' ,
130
+ same_site : 'Lax'
131
+ expect ( driver . manage . cookie_named ( 'samesite' ) [ :same_site ] ) . to eq ( 'Lax' )
78
132
end
79
133
80
- it 'should get named cookie ' do
134
+ it 'should get one ' do
81
135
driver . navigate . to url_for ( 'xhtmlTest.html' )
82
136
driver . manage . add_cookie name : 'foo' , value : 'bar'
83
137
84
138
expect ( driver . manage . cookie_named ( 'foo' ) [ :value ] ) . to eq ( 'bar' )
85
139
end
86
140
141
+ it 'should get all' do
142
+ driver . navigate . to url_for ( 'xhtmlTest.html' )
143
+ driver . manage . add_cookie name : 'foo' , value : 'bar'
144
+
145
+ cookies = driver . manage . all_cookies
146
+
147
+ expect ( cookies . size ) . to eq ( 1 )
148
+ expect ( cookies . first [ :name ] ) . to eq ( 'foo' )
149
+ expect ( cookies . first [ :value ] ) . to eq ( 'bar' )
150
+ end
151
+
87
152
it 'should delete one' do
88
153
driver . navigate . to url_for ( 'xhtmlTest.html' )
89
154
driver . manage . add_cookie name : 'foo' , value : 'bar'
@@ -100,19 +165,6 @@ module WebDriver
100
165
driver . manage . delete_all_cookies
101
166
expect ( driver . manage . all_cookies ) . to be_empty
102
167
end
103
-
104
- it 'should use DateTime for expires' do
105
- driver . navigate . to url_for ( 'xhtmlTest.html' )
106
-
107
- expected = ( Date . today + 2 ) . to_datetime
108
- driver . manage . add_cookie name : 'foo' ,
109
- value : 'bar' ,
110
- expires : expected
111
-
112
- actual = driver . manage . cookie_named ( 'foo' ) [ :expires ]
113
- expect ( actual ) . to be_kind_of ( DateTime )
114
- expect ( actual ) . to eq ( expected )
115
- end
116
168
end
117
169
118
170
describe 'new_window' do
0 commit comments