Path: blob/trunk/rb/spec/unit/selenium/webdriver/ie/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 IE24describe 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: '11',32platform_name: 'win10',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,41args: %w[foo bar],42browser_attach_timeout: 30000,43element_scroll_behavior: Options::SCROLL_BOTTOM,44full_page_screenshot: true,45ensure_clean_session: true,46file_upload_dialog_timeout: 30000,47force_create_process_api: true,48force_shell_windows_api: true,49ignore_protected_mode_settings: true,50ignore_zoom_level: true,51initial_browser_url: 'http://google.com',52native_events: false,53persistent_hover: true,54require_window_focus: true,55use_per_process_proxy: true,56use_legacy_file_upload_dialog_handling: true,57attach_to_edge_chrome: true,58edge_executable_path: '/path/to/edge',59silent: true,60'custom:options': {foo: 'bar'})6162expect(opts.args.to_a).to eq(%w[foo bar])63expect(opts.browser_attach_timeout).to eq(30000)64expect(opts.element_scroll_behavior).to eq(1)65expect(opts.full_page_screenshot).to be(true)66expect(opts.ensure_clean_session).to be(true)67expect(opts.file_upload_dialog_timeout).to eq(30000)68expect(opts.force_create_process_api).to be(true)69expect(opts.force_shell_windows_api).to be(true)70expect(opts.ignore_protected_mode_settings).to be(true)71expect(opts.ignore_zoom_level).to be(true)72expect(opts.initial_browser_url).to eq('http://google.com')73expect(opts.native_events).to be(false)74expect(opts.persistent_hover).to be(true)75expect(opts.require_window_focus).to be(true)76expect(opts.use_per_process_proxy).to be(true)77expect(opts.use_legacy_file_upload_dialog_handling).to be(true)78expect(opts.attach_to_edge_chrome).to be(true)79expect(opts.edge_executable_path).to eq('/path/to/edge')80expect(opts.browser_name).to eq('internet explorer')81expect(opts.browser_version).to eq('11')82expect(opts.platform_name).to eq('win10')83expect(opts.accept_insecure_certs).to be(false)84expect(opts.page_load_strategy).to eq('eager')85expect(opts.unhandled_prompt_behavior).to eq('accept')86expect(opts.strict_file_interactability).to be(true)87expect(opts.timeouts).to eq(script: 40000, page_load: 400000, implicit: 1)88expect(opts.set_window_rect).to be(false)89expect(opts.options[:'custom:options']).to eq(foo: 'bar')90expect(opts.silent).to be_truthy91end9293it 'has native events on by default' do94expect(options.native_events).to be(true)95end96end9798describe '#add_argument' do99it 'adds a command-line argument' do100options.add_argument('foo')101expect(options.args.to_a).to eq(['foo'])102end103end104105describe '#add_option' do106it 'adds vendor namespaced options with ordered pairs' do107options.add_option('foo:bar', {bar: 'foo'})108expect(options.instance_variable_get(:@options)['foo:bar']).to eq({bar: 'foo'})109end110111it 'adds vendor namespaced options with Hash' do112options.add_option('foo:bar' => {bar: 'foo'})113expect(options.instance_variable_get(:@options)['foo:bar']).to eq({bar: 'foo'})114end115end116117describe '#as_json' do118it 'returns empty options by default' do119expect(options.as_json).to eq('browserName' => 'internet explorer',120'se:ieOptions' => {'nativeEvents' => true})121end122123it 'returns added options' do124options.add_option('foo:bar', {foo: 'bar'})125expect(options.as_json).to eq('browserName' => 'internet explorer',126'foo:bar' => {'foo' => 'bar'},127'se:ieOptions' => {'nativeEvents' => true})128end129130it 'returns a JSON hash' do131opts = described_class.new(browser_version: '11',132platform_name: 'win10',133accept_insecure_certs: false,134page_load_strategy: 'eager',135silent: true,136unhandled_prompt_behavior: 'accept',137strict_file_interactability: true,138timeouts: {script: 40000,139page_load: 400000,140implicit: 1},141set_window_rect: false,142args: %w[foo bar],143browser_attach_timeout: 30000,144element_scroll_behavior: Options::SCROLL_BOTTOM,145full_page_screenshot: true,146ensure_clean_session: true,147file_upload_dialog_timeout: 30000,148force_create_process_api: true,149force_shell_windows_api: true,150ignore_protected_mode_settings: true,151ignore_zoom_level: true,152initial_browser_url: 'http://google.com',153native_events: false,154persistent_hover: true,155require_window_focus: true,156use_per_process_proxy: true,157use_legacy_file_upload_dialog_handling: true,158attach_to_edge_chrome: true,159edge_executable_path: '/path/to/edge',160'custom:options': {foo: 'bar'})161162key = 'se:ieOptions'163expect(opts.as_json).to eq('browserName' => 'internet explorer',164'browserVersion' => '11',165'platformName' => 'win10',166'acceptInsecureCerts' => false,167'pageLoadStrategy' => 'eager',168'unhandledPromptBehavior' => 'accept',169'strictFileInteractability' => true,170'timeouts' => {'script' => 40000,171'pageLoad' => 400000,172'implicit' => 1},173'setWindowRect' => false,174'custom:options' => {'foo' => 'bar'},175key => {'ie.browserCommandLineSwitches' => 'foo bar',176'browserAttachTimeout' => 30000,177'elementScrollBehavior' => 1,178'ie.enableFullPageScreenshot' => true,179'ie.ensureCleanSession' => true,180'ie.fileUploadDialogTimeout' => 30000,181'ie.forceCreateProcessApi' => true,182'ie.forceShellWindowsApi' => true,183'ignoreProtectedModeSettings' => true,184'ignoreZoomSetting' => true,185'initialBrowserUrl' => 'http://google.com',186'nativeEvents' => false,187'enablePersistentHover' => true,188'requireWindowFocus' => true,189'ie.usePerProcessProxy' => true,190'ie.useLegacyFileUploadDialogHandling' => true,191'ie.edgechromium' => true,192'ie.edgepath' => '/path/to/edge',193'silent' => true})194end195end196end # Options197end # IE198end # WebDriver199end # Selenium200201202