Path: blob/trunk/rb/spec/unit/selenium/webdriver/ie/driver_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 Driver do25let(:service) do26instance_double(Service, launch: service_manager, executable_path: nil, 'executable_path=': nil,27class: IE::Service)28end29let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }30let(:valid_response) do31{status: 200,32body: {value: {sessionId: 0, capabilities: {browserName: 'internet explorer'}}}.to_json,33headers: {content_type: 'application/json'}}34end35let(:finder) { instance_double(DriverFinder, browser_path?: false, driver_path: '/path/to/driver') }3637def expect_request(body: nil, endpoint: nil)38body = (body || {capabilities: {alwaysMatch: {browserName: 'internet explorer',39'se:ieOptions': {nativeEvents: true}}}}).to_json40endpoint ||= "#{service_manager.uri}/session"41stub_request(:post, endpoint).with(body: body).to_return(valid_response)42end4344before do45allow(Service).to receive_messages(new: service)46end4748it 'uses DriverFinder when provided Service without path' do49expect_request50allow(DriverFinder).to receive(:new).and_return(finder)51options = Options.new5253described_class.new(service: service, options: options)54expect(finder).to have_received(:driver_path)55end5657it 'does not use DriverFinder when provided Service with path' do58expect_request59allow(service).to receive(:executable_path).and_return('path')60allow(DriverFinder).to receive(:new).and_return(finder)6162described_class.new(service: service)63expect(finder).not_to have_received(:driver_path)64end6566it 'does not require any parameters' do67allow(DriverFinder).to receive(:new).and_return(finder)68expect_request6970expect { described_class.new }.not_to raise_exception71end7273it 'accepts provided Options as sole parameter' do74allow(DriverFinder).to receive(:new).and_return(finder)75opts = {args: ['-f']}76expect_request(body: {capabilities: {alwaysMatch: {browserName: 'internet explorer',77'se:ieOptions': {nativeEvents: true,78'ie.browserCommandLineSwitches': '-f'}}}})7980expect { described_class.new(options: Options.new(**opts)) }.not_to raise_exception81end8283it 'does not accept Options of the wrong class' do84expect {85described_class.new(options: Options.chrome)86}.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::IE::Options')87end88end89end # IE90end # WebDriver91end # Selenium929394