Skip to content

Commit 41a22c0

Browse files
committed
[rb] add more specs for cookies
1 parent 610a674 commit 41a22c0

File tree

1 file changed

+75
-23
lines changed

1 file changed

+75
-23
lines changed

rb/spec/integration/selenium/webdriver/manager_spec.rb

+75-23
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,102 @@ module WebDriver
5353
end
5454

5555
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
5759
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
5963

6064
cookies = driver.manage.all_cookies
65+
expect(cookies.size).to eq(0)
66+
end
6167

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)
65117
end
66118

67119
it 'should add sameSite cookie with attribute Strict', only: {browser: %i[chrome edge firefox]} do
68120
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'
70122

71-
expect(driver.manage.cookie_named('foo')[:same_site]).to eq('Strict')
123+
expect(driver.manage.cookie_named('samesite')[:same_site]).to eq('Strict')
72124
end
73125

74126
it 'should add sameSite cookie with attribute Lax', only: {browser: %i[chrome edge firefox]} do
75127
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')
78132
end
79133

80-
it 'should get named cookie' do
134+
it 'should get one' do
81135
driver.navigate.to url_for('xhtmlTest.html')
82136
driver.manage.add_cookie name: 'foo', value: 'bar'
83137

84138
expect(driver.manage.cookie_named('foo')[:value]).to eq('bar')
85139
end
86140

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+
87152
it 'should delete one' do
88153
driver.navigate.to url_for('xhtmlTest.html')
89154
driver.manage.add_cookie name: 'foo', value: 'bar'
@@ -100,19 +165,6 @@ module WebDriver
100165
driver.manage.delete_all_cookies
101166
expect(driver.manage.all_cookies).to be_empty
102167
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
116168
end
117169

118170
describe 'new_window' do

0 commit comments

Comments
 (0)