/
manager_spec.rb
140 lines (114 loc) · 5.24 KB
/
manager_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# frozen_string_literal: true
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require_relative 'spec_helper'
module Selenium
module WebDriver
describe Manager do
describe 'logs', except: [{browser: %i[firefox ie safari safari_preview]},
{driver: :remote, browser: %i[chrome edge]}] do
it 'can fetch remote log types', only: {driver: :remote} do
expect(driver.manage.logs.available_types).to include(:server, :browser, :driver)
end
it 'can fetch available log types', except: {driver: :remote} do
expect(driver.manage.logs.available_types).to include(:browser, :driver)
expect(driver.manage.logs.available_types).not_to include(:server)
end
it 'can get the browser log' do
driver.navigate.to url_for('errors.html')
driver.find_element(tag_name: 'input').click
entries = driver.manage.logs.get(:browser)
expect(entries).not_to be_empty
expect(entries.first).to be_kind_of(LogEntry)
end
# Chrome - turned off by default
it 'can get the driver log', except: {browser: %i[chrome edge]} do
driver.navigate.to url_for('simpleTest.html')
entries = driver.manage.logs.get(:driver)
expect(entries).not_to be_empty
expect(entries.first).to be_kind_of(LogEntry)
end
end
describe 'cookie management' do
it 'should get all' do
driver.navigate.to url_for('xhtmlTest.html')
driver.manage.add_cookie name: 'foo', value: 'bar'
cookies = driver.manage.all_cookies
expect(cookies.size).to eq(1)
expect(cookies.first[:name]).to eq('foo')
expect(cookies.first[:value]).to eq('bar')
end
it 'should add sameSite cookie with attribute Strict', only: {browser: %i[chrome edge]} do
driver.navigate.to url_for('xhtmlTest.html')
driver.manage.add_cookie name: 'foo', value: 'bar', same_site: 'Strict'
expect(driver.manage.cookie_named('foo')[:same_site]).to eq('Strict')
end
it 'should add sameSite cookie with attribute Lax', only: {browser: %i[chrome edge]} do
driver.navigate.to url_for('xhtmlTest.html')
driver.manage.add_cookie name: 'foo', value: 'bar', same_site: 'Lax'
expect(driver.manage.cookie_named('foo')[:same_site]).to eq('Lax')
end
it 'should get named cookie' do
driver.navigate.to url_for('xhtmlTest.html')
driver.manage.add_cookie name: 'foo', value: 'bar'
expect(driver.manage.cookie_named('foo')[:value]).to eq('bar')
end
it 'should delete one' do
driver.navigate.to url_for('xhtmlTest.html')
driver.manage.add_cookie name: 'foo', value: 'bar'
driver.manage.delete_cookie('foo')
expect(driver.manage.all_cookies.find { |c| c[:name] == 'foo' }).to be_nil
end
it 'should delete all' do
driver.navigate.to url_for('xhtmlTest.html')
driver.manage.add_cookie name: 'foo', value: 'bar'
driver.manage.add_cookie name: 'bar', value: 'foo'
driver.manage.delete_all_cookies
expect(driver.manage.all_cookies).to be_empty
end
it 'should use DateTime for expires' do
driver.navigate.to url_for('xhtmlTest.html')
expected = (Date.today + 2).to_datetime
driver.manage.add_cookie name: 'foo',
value: 'bar',
expires: expected
actual = driver.manage.cookie_named('foo')[:expires]
expect(actual).to be_kind_of(DateTime)
expect(actual).to eq(expected)
end
end
describe 'new_window' do
after { ensure_single_window }
types = %i[tab window]
types.each do |type|
it "should be able to open a new #{type}" do
before_window_handles = driver.window_handles.length
driver.manage.new_window(type)
expect(driver.window_handles.length).to eq(before_window_handles + 1)
end
end
it "returns an exception if an invalid type is provided" do
invalid_types = [:invalid, 'invalid', 'tab', 'window']
invalid_types.each do |type|
expect { driver.manage.new_window(type) }.to \
raise_error(ArgumentError, "invalid argument for type. Got: '#{type.inspect}'. Try :tab or :window")
end
end
end
end # Options
end # WebDriver
end # Selenium