Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb] Allow driver path to be set using ENV variables #14287

Merged
merged 22 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d3af87c
Add ENV variables for path
aguspe Jul 20, 2024
1a24735
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Jul 24, 2024
910f297
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Jul 25, 2024
4ba0c7e
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Aug 24, 2024
3242228
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Aug 30, 2024
13f0336
Update RBS and gecko driver
aguspe Aug 30, 2024
e0be315
Update RBS and tests
aguspe Aug 30, 2024
154e35c
Remove firefox guard
aguspe Sep 2, 2024
8bd44c2
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Sep 6, 2024
a2152ec
Merge branch 'rb_use_env_var_for_driver_location' of github.com:agusp…
aguspe Sep 6, 2024
09d6cb1
Update environment to be working now
aguspe Sep 6, 2024
b0f0277
Remove extra spaces
aguspe Sep 6, 2024
d57095b
update rbs
aguspe Sep 6, 2024
01860f6
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Sep 13, 2024
d207384
Move tests from integration to unit tests
aguspe Sep 13, 2024
18a140a
Update specs and add service environment variable
aguspe Sep 14, 2024
37d9145
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Sep 14, 2024
9975b39
Move the integration tests to unit tests
aguspe Sep 15, 2024
e982b78
Merge remote-tracking branch 'origin/rb_use_env_var_for_driver_locati…
aguspe Sep 15, 2024
510b50e
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Sep 15, 2024
b14883d
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Sep 16, 2024
a6a1720
Merge branch 'trunk' into rb_use_env_var_for_driver_location
aguspe Sep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/chrome/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Service < WebDriver::Service
DEFAULT_PORT = 9515
EXECUTABLE = 'chromedriver'
SHUTDOWN_SUPPORTED = true
DRIVER_PATH_ENV_KEY = 'SE_CHROMEDRIVER'

def log
return @log unless @log.is_a? String
Expand Down
15 changes: 11 additions & 4 deletions rb/lib/selenium/webdriver/common/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def driver_path=(path)
def initialize(path: nil, port: nil, log: nil, args: nil)
port ||= self.class::DEFAULT_PORT
args ||= []
path ||= env_path

@executable_path = path
@host = Platform.localhost
Expand All @@ -87,16 +88,22 @@ def initialize(path: nil, port: nil, log: nil, args: nil)
end

def launch
@executable_path ||= begin
default_options = WebDriver.const_get("#{self.class.name&.split('::')&.[](2)}::Options").new
DriverFinder.new(default_options, self).driver_path
end
@executable_path ||= env_path || find_driver_path
ServiceManager.new(self).tap(&:start)
end

def shutdown_supported
self.class::SHUTDOWN_SUPPORTED
end

def find_driver_path
default_options = WebDriver.const_get("#{self.class.name&.split('::')&.[](2)}::Options").new
DriverFinder.new(default_options, self).driver_path
end

def env_path
ENV.fetch(self.class::DRIVER_PATH_ENV_KEY, nil)
end
end # Service
end # WebDriver
end # Selenium
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/edge/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Service < WebDriver::Service
DEFAULT_PORT = 9515
EXECUTABLE = 'msedgedriver'
SHUTDOWN_SUPPORTED = true

DRIVER_PATH_ENV_KEY = 'SE_EDGEDRIVER'
def log
return @log unless @log.is_a? String

Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/firefox/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Service < WebDriver::Service
DEFAULT_PORT = 4444
EXECUTABLE = 'geckodriver'
SHUTDOWN_SUPPORTED = false
DRIVER_PATH_ENV_KEY = 'SE_GECKODRIVER'
end # Service
end # Firefox
end # WebDriver
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/ie/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Service < WebDriver::Service
DEFAULT_PORT = 5555
EXECUTABLE = 'IEDriverServer'
SHUTDOWN_SUPPORTED = true
DRIVER_PATH_ENV_KEY = 'SE_IEDRIVER'
end # Server
end # IE
end # WebDriver
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/safari/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Service < WebDriver::Service
DEFAULT_PORT = 7050
EXECUTABLE = 'safaridriver'
SHUTDOWN_SUPPORTED = false

DRIVER_PATH_ENV_KEY = 'SE_SAFARIDRIVER'
def initialize(path: nil, port: nil, log: nil, args: nil)
raise Error::WebDriverError, 'Safari Service does not support setting log output' if log

Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/chrome/service.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Selenium
module WebDriver
module Chrome
class Service < WebDriver::Service
DRIVER_PATH_ENV_KEY: String

@log: untyped

DEFAULT_PORT: Integer
Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/common/service.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ module Selenium

attr_accessor args: untyped

def env_path: -> String

alias extra_args args

def initialize: (?path: untyped?, ?port: untyped?, ?log: untyped?, ?args: untyped?) -> void
Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/edge/service.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Selenium
module WebDriver
module Edge
class Service < WebDriver::Service
DRIVER_PATH_ENV_KEY: String

@log: untyped

DEFAULT_PORT: Integer
Expand Down
1 change: 1 addition & 0 deletions rb/sig/lib/selenium/webdriver/firefox/service.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Selenium
class Service < WebDriver::Service
DEFAULT_PORT: 4444

DRIVER_PATH_ENV_KEY: String
EXECUTABLE: "geckodriver"

SHUTDOWN_SUPPORTED: false
Expand Down
1 change: 1 addition & 0 deletions rb/sig/lib/selenium/webdriver/ie/service.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Selenium
class Service < WebDriver::Service
DEFAULT_PORT: Integer

DRIVER_PATH_ENV_KEY: String
EXECUTABLE: String

SHUTDOWN_SUPPORTED: bool
Expand Down
1 change: 1 addition & 0 deletions rb/sig/lib/selenium/webdriver/safari/service.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Selenium
class Service < WebDriver::Service
DEFAULT_PORT: Integer

DRIVER_PATH_ENV_KEY: String
EXECUTABLE: String

SHUTDOWN_SUPPORTED: bool
Expand Down
43 changes: 43 additions & 0 deletions rb/spec/integration/selenium/webdriver/ie/service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

require_relative '../spec_helper'

module Selenium
module WebDriver
module IE
describe Service, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {browser: :ie}] do
let(:service) { described_class.new }
let(:service_manager) { service.launch }

after { service_manager.stop }

it 'auto uses iedriver' do
service.executable_path = DriverFinder.new(Options.new, described_class.new).driver_path

expect(service_manager.uri).to be_a(URI)
end

it 'can be started outside driver' do
expect(service_manager.uri).to be_a(URI)
end
end
end # IE
end # WebDriver
end # Selenium
43 changes: 43 additions & 0 deletions rb/spec/integration/selenium/webdriver/safari/service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

require_relative '../spec_helper'

module Selenium
module WebDriver
module Safari
describe Service, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {browser: :safari}] do
let(:service) { described_class.new }
let(:service_manager) { service.launch }

after { service_manager.stop }

it 'auto uses safaridriver' do
service.executable_path = DriverFinder.new(Options.new, described_class.new).driver_path

expect(service_manager.uri).to be_a(URI)
end

it 'can be started outside driver' do
expect(service_manager.uri).to be_a(URI)
end
end
end # Safari
end # WebDriver
end # Selenium
22 changes: 22 additions & 0 deletions rb/spec/unit/selenium/webdriver/chrome/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ module Chrome
driver.new(service: service)
expect(described_class).not_to have_received(:new)
end

context 'with a path env variable' do
let(:service) { described_class.new }
let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }

before do
ENV['SE_CHROMEDRIVER'] = service_path
end

after { ENV.delete('SE_CHROMEDRIVER') }

it 'uses the path from the environment' do
expect(service.executable_path).to match(/chromedriver/)
end

it 'updates the path after setting the environment variable' do
ENV['SE_CHROMEDRIVER'] = '/foo/bar'
service.executable_path = service_path

expect(service.executable_path).to match(/chromedriver/)
end
end
end
end
end # Chrome
Expand Down
22 changes: 22 additions & 0 deletions rb/spec/unit/selenium/webdriver/edge/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@ module Edge
expect(service.log).to be_nil
expect(service.args).to eq ['--log-path=/path/to/log.txt']
end

context 'with a path env variable' do
let(:service) { described_class.new }
let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }

before do
ENV['SE_EDGEDRIVER'] = service_path
end

after { ENV.delete('SE_EDGEDRIVER') }

it 'uses the path from the environment' do
expect(service.executable_path).to match(/edgedriver/)
end

it 'updates the path after setting the environment variable' do
ENV['SE_EDGEDRIVER'] = '/foo/bar'
service.executable_path = service_path

expect(service.executable_path).to match(/edgedriver/)
end
end
end
end
end # Edge
Expand Down
22 changes: 22 additions & 0 deletions rb/spec/unit/selenium/webdriver/firefox/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ module Firefox

expect(described_class).not_to have_received(:new)
end

context 'with a path env variable' do
let(:service) { described_class.new }
let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }

before do
ENV['SE_GECKODRIVER'] = service_path
end

after { ENV.delete('SE_GECKODRIVER') }

it 'uses the path from the environment' do
expect(service.executable_path).to match(/geckodriver/)
end

it 'updates the path after setting the environment variable' do
ENV['SE_GECKODRIVER'] = '/foo/bar'
service.executable_path = service_path

expect(service.executable_path).to match(/geckodriver/)
end
end
end
end
end # Firefox
Expand Down
22 changes: 22 additions & 0 deletions rb/spec/unit/selenium/webdriver/ie/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ module IE

expect(described_class).not_to have_received(:new)
end

context 'with a path env variable' do
let(:service) { described_class.new }
let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }

before do
ENV['SE_IEDRIVER'] = service_path
end

after { ENV.delete('SE_IEDRIVER') }

it 'uses the path from the environment' do
expect(service.executable_path).to match(/IEDriver/)
end

it 'updates the path after setting the environment variable' do
ENV['SE_IEDRIVER'] = '/foo/bar'
service.executable_path = service_path

expect(service.executable_path).to match(/IEDriver/)
end
end
end
end
end # IE
Expand Down
22 changes: 22 additions & 0 deletions rb/spec/unit/selenium/webdriver/safari/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,28 @@ module Safari

expect(described_class).not_to have_received(:new)
end

context 'with a path env variable' do
let(:service) { described_class.new }
let(:service_path) { "/path/to/#{Service::EXECUTABLE}" }

before do
ENV['SE_SAFARIDRIVER'] = service_path
end

after { ENV.delete('SE_SAFARIDRIVER') }

it 'uses the path from the environment' do
expect(service.executable_path).to match(/safaridriver/)
end

it 'updates the path after setting the environment variable' do
ENV['SE_SAFARIDRIVER'] = '/foo/bar'
service.executable_path = service_path

expect(service.executable_path).to match(/safaridriver/)
end
end
end
end
end # Safari
Expand Down
Loading