Path: blob/trunk/rb/spec/unit/selenium/webdriver/edge/service_spec.rb
4101 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)30allow(WebDriver.logger).to receive(:debug?).and_return(false)31described_class.driver_path = nil32end3334it 'uses default port and nil path' do35service = described_class.new3637expect(service.port).to eq Service::DEFAULT_PORT38expect(service.host).to eq Platform.localhost39expect(service.executable_path).to be_nil40end4142it 'uses provided path and port' do43path = 'foo'44port = 56784546service = described_class.new(path: path, port: port)4748expect(service.executable_path).to eq path49expect(service.port).to eq port50expect(service.host).to eq Platform.localhost51end5253it 'does not create args by default' do54service = described_class.new5556expect(service.extra_args).to be_empty57end5859it 'uses sets log path to stdout' do60service = described_class.chrome(log: :stdout)6162expect(service.log).to eq $stdout63end6465it 'uses sets log path to stderr' do66service = described_class.chrome(log: :stderr)6768expect(service.log).to eq $stderr69end7071it 'setting log output as a file converts to argument' do72service = described_class.chrome(log: '/path/to/log.txt')7374expect(service.log).to be_nil75expect(service.args).to eq ['--log-path=/path/to/log.txt']76end7778it 'uses provided args' do79service = described_class.new(args: ['--foo', '--bar'])8081expect(service.extra_args).to eq ['--foo', '--bar']82end8384context 'when SE_DEBUG is set' do85around do |example|86ENV['SE_DEBUG'] = '1'87example.run88ensure89ENV.delete('SE_DEBUG')90end9192it 'adds --verbose flag' do93service = described_class.new9495expect(service.extra_args).to include('--verbose')96end9798it 'removes conflicting --log-level args' do99service = described_class.new(args: ['--log-level=INFO'])100101expect(service.extra_args).to include('--verbose')102expect(service.extra_args).not_to include('--log-level=INFO')103end104105it 'removes conflicting --silent args' do106service = described_class.new(args: ['--silent'])107108expect(service.extra_args).to include('--verbose')109expect(service.extra_args).not_to include('--silent')110end111end112end113114context 'when initializing driver' do115let(:driver) { Edge::Driver }116let(:finder) { instance_double(DriverFinder, browser_path?: false, driver_path: '/path/to/driver') }117let(:service) do118instance_double(described_class, launch: service_manager, executable_path: nil, 'executable_path=': nil,119class: described_class)120end121let(:service_manager) { instance_double(ServiceManager, uri: 'http://example.com') }122let(:bridge) { instance_double(Remote::Bridge, quit: nil, create_session: {}) }123124before do125allow(Remote::Bridge).to receive(:new).and_return(bridge)126allow(bridge).to receive(:browser).and_return(:msedge)127end128129it 'is not created when :url is provided' do130allow(described_class).to receive(:new)131132expect {133driver.new(url: 'http://example.com:4321')134}.to raise_error(ArgumentError, "Can't initialize Selenium::WebDriver::Edge::Driver with :url")135136expect(described_class).not_to have_received(:new)137end138139it 'is created when :url is not provided' do140allow(DriverFinder).to receive(:new).and_return(finder)141allow(described_class).to receive(:new).and_return(service)142143driver.new144expect(described_class).to have_received(:new).with(no_args)145end146147it 'accepts :service without creating a new instance' do148allow(DriverFinder).to receive(:new).and_return(finder)149allow(described_class).to receive(:new)150151driver.new(service: service)152expect(described_class).not_to have_received(:new)153end154155it 'setting log output as a file converts to argument' do156service = described_class.chrome(log: '/path/to/log.txt')157158expect(service.log).to be_nil159expect(service.args).to eq ['--log-path=/path/to/log.txt']160end161162context 'with a path env variable' do163let(:service) { described_class.new }164let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }165166before do167ENV['SE_EDGEDRIVER'] = service_path168end169170after { ENV.delete('SE_EDGEDRIVER') }171172it 'uses the path from the environment' do173expect(service.executable_path).to match(/edgedriver/)174end175176it 'updates the path after setting the environment variable' do177ENV['SE_EDGEDRIVER'] = '/foo/bar'178service.executable_path = service_path179180expect(service.executable_path).to match(/edgedriver/)181end182end183end184end185end # Edge186end # WebDriver187end # Selenium188189190