From f843e8b14630b3a8f21120f9378cf57aa28ed32b Mon Sep 17 00:00:00 2001 From: titusfortner Date: Sun, 24 Sep 2023 18:51:53 -0500 Subject: [PATCH] [rb] allow service to be started before the driver --- rb/lib/selenium/webdriver/common/service.rb | 4 ++++ .../selenium/webdriver/chrome/service_spec.rb | 7 ++++++- .../selenium/webdriver/edge/service_spec.rb | 7 ++++++- .../selenium/webdriver/firefox/service_spec.rb | 10 +++++++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/rb/lib/selenium/webdriver/common/service.rb b/rb/lib/selenium/webdriver/common/service.rb index dc24ce1d33ea2..442f90849369a 100644 --- a/rb/lib/selenium/webdriver/common/service.rb +++ b/rb/lib/selenium/webdriver/common/service.rb @@ -87,6 +87,10 @@ 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.path(default_options, self.class) + end ServiceManager.new(self).tap(&:start) end diff --git a/rb/spec/integration/selenium/webdriver/chrome/service_spec.rb b/rb/spec/integration/selenium/webdriver/chrome/service_spec.rb index c40eed3d18865..2815dc5f4ce8e 100644 --- a/rb/spec/integration/selenium/webdriver/chrome/service_spec.rb +++ b/rb/spec/integration/selenium/webdriver/chrome/service_spec.rb @@ -26,10 +26,15 @@ module Chrome let(:service) { described_class.new } let(:service_manager) { service.launch } - before { service.executable_path = DriverFinder.path(Options.new, described_class) } after { service_manager.stop } it 'auto uses chromedriver' do + service.executable_path = DriverFinder.path(Options.new, described_class) + + 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 diff --git a/rb/spec/integration/selenium/webdriver/edge/service_spec.rb b/rb/spec/integration/selenium/webdriver/edge/service_spec.rb index cf71b9a625998..457c89d2f096c 100644 --- a/rb/spec/integration/selenium/webdriver/edge/service_spec.rb +++ b/rb/spec/integration/selenium/webdriver/edge/service_spec.rb @@ -26,10 +26,15 @@ module Edge let(:service) { described_class.new } let(:service_manager) { service.launch } - before { service.executable_path = DriverFinder.path(Options.new, described_class) } after { service_manager.stop } it 'auto uses edgedriver' do + service.executable_path = DriverFinder.path(Options.new, described_class) + + 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 diff --git a/rb/spec/integration/selenium/webdriver/firefox/service_spec.rb b/rb/spec/integration/selenium/webdriver/firefox/service_spec.rb index 980b355b87cbd..cca6388d92e1d 100644 --- a/rb/spec/integration/selenium/webdriver/firefox/service_spec.rb +++ b/rb/spec/integration/selenium/webdriver/firefox/service_spec.rb @@ -26,14 +26,18 @@ module Firefox let(:service) { described_class.new } let(:service_manager) { service.launch } - before { service.executable_path = DriverFinder.path(Options.new, described_class) } after { service_manager.stop } it 'auto uses geckodriver' do - service_manager = service.launch + service.executable_path = DriverFinder.path(Options.new, described_class) + + 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 # Chrome + end # Firefox end # WebDriver end # Selenium