Path: blob/trunk/rb/spec/unit/selenium/webdriver/firefox/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 Firefox24describe Driver do25let(:service) do26instance_double(Service, launch: service_manager, executable_path: nil, 'executable_path=': nil,27class: Firefox::Service)28end29let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }30let(:valid_response) do31{status: 200,32body: {value: {sessionId: 0, capabilities: {browserName: 'firefox'}}}.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: {acceptInsecureCerts: true,39browserName: 'firefox',40'moz:firefoxOptions': {prefs: {'remote.active-protocols' => 1}},41'moz:debuggerAddress': true}}}).to_json42endpoint ||= "#{service_manager.uri}/session"43stub_request(:post, endpoint).with(body: body).to_return(valid_response)44end4546before do47allow(Service).to receive_messages(new: service, executable_path: nil)48end4950it 'uses DriverFinder when provided Service without path' do51allow(DriverFinder).to receive(:new).and_return(finder)52expect_request53options = Options.new5455described_class.new(service: service, options: options)56expect(finder).to have_received(:driver_path)57end5859it 'does not use DriverFinder when provided Service with path' do60expect_request61allow(DriverFinder).to receive(:new).and_return(finder)62allow(service).to receive(:executable_path).and_return('path')6364described_class.new(service: service)65expect(finder).not_to have_received(:driver_path)66end6768it 'does not require any parameters' do69allow(DriverFinder).to receive(:new).and_return(finder)70expect_request7172expect { described_class.new }.not_to raise_exception73end7475it 'accepts provided Options as sole parameter' do76allow(DriverFinder).to receive(:new).and_return(finder)7778opts = {args: ['-f']}79expect_request(body: {capabilities: {alwaysMatch: {acceptInsecureCerts: true,80browserName: 'firefox',81'moz:firefoxOptions': {82args: ['-f'],83prefs: {'remote.active-protocols' => 1}84},85'moz:debuggerAddress': true}}})86expect { described_class.new(options: Options.new(**opts)) }.not_to raise_exception87end8889it 'does not accept Options of the wrong class' do90expect {91described_class.new(options: Options.chrome)92}.to raise_exception(ArgumentError, ':options must be an instance of Selenium::WebDriver::Firefox::Options')93end94end95end # Firefox96end # WebDriver97end # Selenium9899100