Path: blob/trunk/rb/spec/unit/selenium/webdriver/edge/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 Edge24describe Driver do25let(:service) do26instance_double(Service, launch: service_manager, executable_path: nil, 'executable_path=': nil,27class: Edge::Service)28end29let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }30let(:valid_response) do31{status: 200,32body: {value: {sessionId: 0, capabilities: {browserName: 'MicrosoftEdge'}}}.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: 'MicrosoftEdge', 'ms:edgeOptions': {}}}}).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, executable_path: nil)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 = {args: ['-f']}75expect_request(body: {capabilities: {alwaysMatch: {browserName: 'MicrosoftEdge', 'ms:edgeOptions': opts}}})7677expect { described_class.new(options: Options.new(**opts)) }.not_to raise_exception78end7980it 'raises an ArgumentError if parameter is not recognized' do81allow(DriverFinder).to receive(:new).and_return(finder)82msg = 'unknown keyword: :invalid'83expect { described_class.new(invalid: 'foo') }.to raise_error(ArgumentError, msg)84end8586it 'does not accept Options of the wrong class' do87expect {88described_class.new(options: Options.chrome)89}.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::Edge::Options')90end91end92end # Chrome93end # WebDriver94end # Selenium959697