Path: blob/trunk/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require File.expand_path('../spec_helper', __dir__)2021module Selenium22module WebDriver23module Remote24describe Capabilities do25it 'converts noProxy from string to array' do26proxy = Proxy.new(no_proxy: 'proxy_url, localhost')27caps = described_class.new(proxy: proxy)28expect(caps.as_json['proxy']['noProxy']).to eq(%w[proxy_url localhost])29end3031it 'does not convert noProxy if it is already array' do32proxy = Proxy.new(no_proxy: ['proxy_url'])33caps = described_class.new(proxy: proxy)34expect(caps.as_json['proxy']['noProxy']).to eq(['proxy_url'])35end3637it 'defaults to no proxy' do38expect(described_class.new.proxy).to be_nil39end4041it 'can set and get standard capabilities' do42caps = described_class.new4344caps.browser_name = 'foo'45expect(caps.browser_name).to eq('foo')4647caps.page_load_strategy = :eager48expect(caps.page_load_strategy).to eq(:eager)49end5051it 'can set and get arbitrary capabilities' do52caps = described_class.new(browser_name: 'chrome')53caps['chrome'] = :foo54expect(caps['chrome']).to eq(:foo)55end5657it 'sets the given proxy' do58proxy = Proxy.new(http: 'proxy_url')59capabilities = described_class.new(proxy: proxy)6061expect(capabilities.as_json).to eq('proxy' => {'proxyType' => 'manual',62'httpProxy' => 'proxy_url'})63end6465it 'accepts a Hash' do66capabilities = described_class.new(proxy: {http: 'foo:123'})67expect(capabilities.proxy.http).to eq('foo:123')68end6970it 'does not contain proxy hash when no proxy settings' do71capabilities_hash = described_class.new.as_json72expect(capabilities_hash).not_to have_key('proxy')73end7475it 'can merge capabilities' do76a = described_class.new(browser_name: 'chrome')77b = described_class.new(browser_name: 'firefox')78a.merge!(b)7980expect(a.browser_name).to eq('firefox')81end8283it 'can be serialized and deserialized to JSON' do84caps = described_class.new(browser_name: 'firefox',85timeouts: {86implicit: 1,87page_load: 2,88script: 389},90'extension:customCapability': true)91expect(caps).to eq(described_class.json_create(caps.as_json))92end9394it 'allows to set alwaysMatch' do95expected = {'alwaysMatch' => {'browserName' => 'chrome'}}96expect(described_class.always_match(browser_name: 'chrome').as_json).to eq(expected)97expect(described_class.always_match('browserName' => 'chrome').as_json).to eq(expected)98expect(described_class.always_match(described_class.new(browser_name: 'chrome')).as_json).to eq(expected)99end100101it 'allows to set firstMatch' do102expected = {'firstMatch' => [{'browserName' => 'chrome'}, {'browserName' => 'firefox'}]}103expect(described_class.first_match({browser_name: 'chrome'},104{browser_name: 'firefox'}).as_json).to eq(expected)105expect(described_class.first_match({'browserName' => 'chrome'},106{'browserName' => 'firefox'}).as_json).to eq(expected)107expect(described_class.first_match(described_class.new(browser_name: 'chrome'),108described_class.new(browser_name: 'firefox')).as_json).to eq(expected)109end110111describe 'timeouts' do112let(:as_json) do113{114'browserName' => 'chrome',115'timeouts' => {116'implicit' => 1,117'pageLoad' => 2,118'script' => 3119}120}121end122123it 'processes timeouts as hash' do124caps = described_class.new(browser_name: 'chrome', timeouts: {implicit: 1, page_load: 2, script: 3})125expect(caps.timeouts).to eq(implicit: 1, page_load: 2, script: 3)126expect(caps.implicit_timeout).to eq(1)127expect(caps.page_load_timeout).to eq(2)128expect(caps.script_timeout).to eq(3)129expect(caps.as_json).to eq(as_json)130end131132it 'processes timeouts via timeouts reader' do133caps = described_class.new(browser_name: 'chrome')134caps.timeouts[:implicit] = 1135caps.timeouts[:page_load] = 2136caps.timeouts[:script] = 3137expect(caps.timeouts).to eq(implicit: 1, page_load: 2, script: 3)138expect(caps.implicit_timeout).to eq(1)139expect(caps.page_load_timeout).to eq(2)140expect(caps.script_timeout).to eq(3)141expect(caps.as_json).to eq(as_json)142end143144it 'processes timeouts via per-timeout writers' do145caps = described_class.new(browser_name: 'chrome')146caps.implicit_timeout = 1147caps.page_load_timeout = 2148caps.script_timeout = 3149expect(caps.timeouts).to eq(implicit: 1, page_load: 2, script: 3)150expect(caps.implicit_timeout).to eq(1)151expect(caps.page_load_timeout).to eq(2)152expect(caps.script_timeout).to eq(3)153expect(caps.as_json).to eq(as_json)154end155end156end157end # Remote158end # WebDriver159end # Selenium160161162