Path: blob/trunk/rb/spec/unit/selenium/webdriver/edge/service_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 Service do25describe '#new' do26let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }2728before do29allow(Platform).to receive(:assert_executable)30described_class.driver_path = nil31end3233it 'uses default port and nil path' do34service = described_class.new3536expect(service.port).to eq Service::DEFAULT_PORT37expect(service.host).to eq Platform.localhost38expect(service.executable_path).to be_nil39end4041it 'uses provided path and port' do42path = 'foo'43port = 56784445service = described_class.new(path: path, port: port)4647expect(service.executable_path).to eq path48expect(service.port).to eq port49expect(service.host).to eq Platform.localhost50end5152it 'does not create args by default' do53service = described_class.new5455expect(service.extra_args).to be_empty56end5758it 'uses sets log path to stdout' do59service = described_class.chrome(log: :stdout)6061expect(service.log).to eq $stdout62end6364it 'uses sets log path to stderr' do65service = described_class.chrome(log: :stderr)6667expect(service.log).to eq $stderr68end6970it 'setting log output as a file converts to argument' do71service = described_class.chrome(log: '/path/to/log.txt')7273expect(service.log).to be_nil74expect(service.args).to eq ['--log-path=/path/to/log.txt']75end7677it 'uses provided args' do78service = described_class.new(args: ['--foo', '--bar'])7980expect(service.extra_args).to eq ['--foo', '--bar']81end82end8384context 'when initializing driver' do85let(:driver) { Edge::Driver }86let(:finder) { instance_double(DriverFinder, browser_path?: false, driver_path: '/path/to/driver') }87let(:service) do88instance_double(described_class, launch: service_manager, executable_path: nil, 'executable_path=': nil,89class: described_class)90end91let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }92let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }9394before do95allow(Remote::Bridge).to receive(:new).and_return(bridge)96allow(bridge).to receive(:browser).and_return(:msedge)97end9899it 'is not created when :url is provided' do100allow(described_class).to receive(:new)101102expect {103driver.new(url: 'http://example.com:4321')104}.to raise_error(ArgumentError, "Can't initialize Selenium::WebDriver::Edge::Driver with :url")105106expect(described_class).not_to have_received(:new)107end108109it 'is created when :url is not provided' do110allow(DriverFinder).to receive(:new).and_return(finder)111allow(described_class).to receive(:new).and_return(service)112113driver.new114expect(described_class).to have_received(:new).with(no_args)115end116117it 'accepts :service without creating a new instance' do118allow(DriverFinder).to receive(:new).and_return(finder)119allow(described_class).to receive(:new)120121driver.new(service: service)122expect(described_class).not_to have_received(:new)123end124125it 'setting log output as a file converts to argument' do126service = described_class.chrome(log: '/path/to/log.txt')127128expect(service.log).to be_nil129expect(service.args).to eq ['--log-path=/path/to/log.txt']130end131132context 'with a path env variable' do133let(:service) { described_class.new }134let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }135136before do137ENV['SE_EDGEDRIVER'] = service_path138end139140after { ENV.delete('SE_EDGEDRIVER') }141142it 'uses the path from the environment' do143expect(service.executable_path).to match(/edgedriver/)144end145146it 'updates the path after setting the environment variable' do147ENV['SE_EDGEDRIVER'] = '/foo/bar'148service.executable_path = service_path149150expect(service.executable_path).to match(/edgedriver/)151end152end153end154end155end # Edge156end # WebDriver157end # Selenium158159160