Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb
1865 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require File.expand_path('../spec_helper', __dir__)
21
22
module Selenium
23
module WebDriver
24
module Remote
25
describe Capabilities do
26
it 'converts noProxy from string to array' do
27
proxy = Proxy.new(no_proxy: 'proxy_url, localhost')
28
caps = described_class.new(proxy: proxy)
29
expect(caps.as_json['proxy']['noProxy']).to eq(%w[proxy_url localhost])
30
end
31
32
it 'does not convert noProxy if it is already array' do
33
proxy = Proxy.new(no_proxy: ['proxy_url'])
34
caps = described_class.new(proxy: proxy)
35
expect(caps.as_json['proxy']['noProxy']).to eq(['proxy_url'])
36
end
37
38
it 'defaults to no proxy' do
39
expect(described_class.new.proxy).to be_nil
40
end
41
42
it 'can set and get standard capabilities' do
43
caps = described_class.new
44
45
caps.browser_name = 'foo'
46
expect(caps.browser_name).to eq('foo')
47
48
caps.page_load_strategy = :eager
49
expect(caps.page_load_strategy).to eq(:eager)
50
end
51
52
it 'can set and get arbitrary capabilities' do
53
caps = described_class.new(browser_name: 'chrome')
54
caps['chrome'] = :foo
55
expect(caps['chrome']).to eq(:foo)
56
end
57
58
it 'sets the given proxy' do
59
proxy = Proxy.new(http: 'proxy_url')
60
capabilities = described_class.new(proxy: proxy)
61
62
expect(capabilities.as_json).to eq('proxy' => {'proxyType' => 'manual',
63
'httpProxy' => 'proxy_url'})
64
end
65
66
it 'accepts a Hash' do
67
capabilities = described_class.new(proxy: {http: 'foo:123'})
68
expect(capabilities.proxy.http).to eq('foo:123')
69
end
70
71
it 'does not contain proxy hash when no proxy settings' do
72
capabilities_hash = described_class.new.as_json
73
expect(capabilities_hash).not_to have_key('proxy')
74
end
75
76
it 'can merge capabilities' do
77
a = described_class.new(browser_name: 'chrome')
78
b = described_class.new(browser_name: 'firefox')
79
a.merge!(b)
80
81
expect(a.browser_name).to eq('firefox')
82
end
83
84
it 'can be serialized and deserialized to JSON' do
85
caps = described_class.new(browser_name: 'firefox',
86
timeouts: {
87
implicit: 1,
88
page_load: 2,
89
script: 3
90
},
91
'extension:customCapability': true)
92
expect(caps).to eq(described_class.json_create(caps.as_json))
93
end
94
95
it 'allows to set alwaysMatch' do
96
expected = {'alwaysMatch' => {'browserName' => 'chrome'}}
97
expect(described_class.always_match(browser_name: 'chrome').as_json).to eq(expected)
98
expect(described_class.always_match('browserName' => 'chrome').as_json).to eq(expected)
99
expect(described_class.always_match(described_class.new(browser_name: 'chrome')).as_json).to eq(expected)
100
end
101
102
it 'allows to set firstMatch' do
103
expected = {'firstMatch' => [{'browserName' => 'chrome'}, {'browserName' => 'firefox'}]}
104
expect(described_class.first_match({browser_name: 'chrome'},
105
{browser_name: 'firefox'}).as_json).to eq(expected)
106
expect(described_class.first_match({'browserName' => 'chrome'},
107
{'browserName' => 'firefox'}).as_json).to eq(expected)
108
expect(described_class.first_match(described_class.new(browser_name: 'chrome'),
109
described_class.new(browser_name: 'firefox')).as_json).to eq(expected)
110
end
111
112
describe 'timeouts' do
113
let(:as_json) do
114
{
115
'browserName' => 'chrome',
116
'timeouts' => {
117
'implicit' => 1,
118
'pageLoad' => 2,
119
'script' => 3
120
}
121
}
122
end
123
124
it 'processes timeouts as hash' do
125
caps = described_class.new(browser_name: 'chrome', timeouts: {implicit: 1, page_load: 2, script: 3})
126
expect(caps.timeouts).to eq(implicit: 1, page_load: 2, script: 3)
127
expect(caps.implicit_timeout).to eq(1)
128
expect(caps.page_load_timeout).to eq(2)
129
expect(caps.script_timeout).to eq(3)
130
expect(caps.as_json).to eq(as_json)
131
end
132
133
it 'processes timeouts via timeouts reader' do
134
caps = described_class.new(browser_name: 'chrome')
135
caps.timeouts[:implicit] = 1
136
caps.timeouts[:page_load] = 2
137
caps.timeouts[:script] = 3
138
expect(caps.timeouts).to eq(implicit: 1, page_load: 2, script: 3)
139
expect(caps.implicit_timeout).to eq(1)
140
expect(caps.page_load_timeout).to eq(2)
141
expect(caps.script_timeout).to eq(3)
142
expect(caps.as_json).to eq(as_json)
143
end
144
145
it 'processes timeouts via per-timeout writers' do
146
caps = described_class.new(browser_name: 'chrome')
147
caps.implicit_timeout = 1
148
caps.page_load_timeout = 2
149
caps.script_timeout = 3
150
expect(caps.timeouts).to eq(implicit: 1, page_load: 2, script: 3)
151
expect(caps.implicit_timeout).to eq(1)
152
expect(caps.page_load_timeout).to eq(2)
153
expect(caps.script_timeout).to eq(3)
154
expect(caps.as_json).to eq(as_json)
155
end
156
end
157
end
158
end # Remote
159
end # WebDriver
160
end # Selenium
161
162