Path: blob/trunk/rb/spec/unit/selenium/webdriver/safari/options_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 Safari24describe Options do25subject(:options) { described_class.new }2627describe '#initialize' do28it 'accepts all defined parameters' do29allow(File).to receive(:directory?).and_return(true)3031opts = described_class.new(browser_version: '12',32platform_name: 'mac_sierra',33accept_insecure_certs: false,34page_load_strategy: 'eager',35unhandled_prompt_behavior: 'accept',36strict_file_interactability: true,37timeouts: {script: 40000,38page_load: 400000,39implicit: 1},40set_window_rect: false, in_private: true,41automatic_profiling: false,42automatic_inspection: true,43'custom:options': {foo: 'bar'})4445expect(opts.automatic_profiling).to be(false)46expect(opts.automatic_inspection).to be(true)47expect(opts.browser_name).to eq('safari')48expect(opts.browser_version).to eq('12')49expect(opts.platform_name).to eq('mac_sierra')50expect(opts.accept_insecure_certs).to be(false)51expect(opts.page_load_strategy).to eq('eager')52expect(opts.unhandled_prompt_behavior).to eq('accept')53expect(opts.strict_file_interactability).to be(true)54expect(opts.timeouts).to eq(script: 40000, page_load: 400000, implicit: 1)55expect(opts.set_window_rect).to be(false)56expect(opts.options[:'custom:options']).to eq(foo: 'bar')57end58end5960describe '#add_option' do61context 'when namespaced' do62it 'adds an option with ordered pairs' do63options.add_option('safari:foo', 'bar')64expect(options.instance_variable_get(:@options)['safari:foo']).to eq('bar')65end6667it 'adds an option with keyword' do68options.add_option('safari:foo': 'bar')69expect(options.instance_variable_get(:@options)[:'safari:foo']).to eq('bar')70end71end7273context 'when not namespaced' do74it 'adds an option with ordered pairs' do75expect {76options.add_option(:foo, 'bar')77}.to raise_error(ArgumentError, /Safari does not support options that are not namespaced/)78end7980it 'raises exception with keyword' do81expect {82options.add_option(foo: 'bar')83}.to raise_error(ArgumentError, /Safari does not support options that are not namespaced/)84end85end86end8788describe '#as_json' do89it 'returns empty options by default' do90expect(options.as_json).to eq('browserName' => 'safari')91end9293it 'returns added options' do94options.add_option('safari:foo', 'bar')95expect(options.as_json).to eq('browserName' => 'safari',96'safari:foo' => 'bar')97end9899it 'returns JSON hash' do100opts = described_class.new(browser_version: '12',101platform_name: 'mac_sierra',102accept_insecure_certs: false,103page_load_strategy: 'eager',104unhandled_prompt_behavior: 'accept',105strict_file_interactability: true,106timeouts: {script: 40000,107page_load: 400000,108implicit: 1},109set_window_rect: false,110automatic_profiling: false,111automatic_inspection: true,112'safari:foo': 'foo')113114expect(opts.as_json).to eq('browserName' => 'safari',115'browserVersion' => '12',116'platformName' => 'mac_sierra',117'acceptInsecureCerts' => false,118'pageLoadStrategy' => 'eager',119'unhandledPromptBehavior' => 'accept',120'strictFileInteractability' => true,121'timeouts' => {'script' => 40000,122'pageLoad' => 400000,123'implicit' => 1},124'setWindowRect' => false,125'safari:automaticInspection' => true,126'safari:automaticProfiling' => false,127'safari:foo' => 'foo')128end129end130end # Options131end # Safari132end # WebDriver133end # Selenium134135136