Path: blob/trunk/rb/spec/unit/selenium/webdriver/safari/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 Safari24describe Driver do25let(:service) do26instance_double(Service, launch: service_manager, executable_path: nil, 'executable_path=': nil,27class: Safari::Service)28end29let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }30let(:valid_response) do31{status: 200,32body: {value: {sessionId: 0, capabilities: {browserName: 'safari'}}}.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: 'safari'}}}).to_json39endpoint ||= "#{service_manager.uri}/session"40stub_request(:post, endpoint).with(body: body).to_return(valid_response)41end4243before do44allow(Service).to receive_messages(new: service)45end4647it 'uses DriverFinder when provided Service without path' do48allow(DriverFinder).to receive(:new).and_return(finder)49expect_request50options = Options.new5152described_class.new(service: service, options: options)53expect(finder).to have_received(:driver_path)54end5556it 'does not use DriverFinder when provided Service with path' do57expect_request58allow(service).to receive(:executable_path).and_return('path')59allow(DriverFinder).to receive(:new).and_return(finder)6061described_class.new(service: service)62expect(finder).not_to have_received(:driver_path)63end6465it 'does not require any parameters' do66allow(DriverFinder).to receive(:new).and_return(finder)67expect_request6869expect { described_class.new }.not_to raise_exception70end7172it 'accepts provided Options as sole parameter' do73allow(DriverFinder).to receive(:new).and_return(finder)74opts = {automatic_inspection: true}75expect_request(body: {capabilities: {alwaysMatch: {browserName: 'safari',76'safari:automaticInspection': true}}})7778expect { described_class.new(options: Options.new(**opts)) }.not_to raise_exception79end8081it 'does not accept Options of the wrong class' do82expect {83described_class.new(options: Options.chrome)84}.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::Safari::Options')85end86end87end # Safari88end # WebDriver89end # Selenium909192