Skip to content

[rb] ensure driver process is always stopped #15635

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class Driver < Chromium::Driver
include LocalDriver

def initialize(options: nil, service: nil, url: nil, **opts)
caps, url = initialize_local_driver(options, service, url)
super(caps: caps, url: url, **opts)
initialize_local_driver(options, service, url) do |caps, driver_url|
super(caps: caps, url: driver_url, **opts)
end
end

def browser
Expand Down
5 changes: 0 additions & 5 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,6 @@ def create_bridge(caps:, url:, http_client: nil)
end
end

def service_url(service)
@service_manager = service.launch
@service_manager.uri
end

def screenshot
bridge.screenshot
end
Expand Down
12 changes: 11 additions & 1 deletion rb/lib/selenium/webdriver/common/local_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ def initialize_local_driver(options, service, url)
caps = process_options(options, service)
url = service_url(service)

[caps, url]
begin
yield(caps, url) if block_given?
rescue Selenium::WebDriver::Error::WebDriverError
@service_manager&.stop
raise
end
end

def service_url(service)
@service_manager = service.launch
@service_manager.uri
end

def process_options(options, service)
Expand Down
5 changes: 3 additions & 2 deletions rb/lib/selenium/webdriver/edge/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class Driver < Chromium::Driver
include LocalDriver

def initialize(options: nil, service: nil, url: nil, **opts)
caps, url = initialize_local_driver(options, service, url)
super(caps: caps, url: url, **opts)
initialize_local_driver(options, service, url) do |caps, driver_url|
super(caps: caps, url: driver_url, **opts)
end
end

def browser
Expand Down
5 changes: 3 additions & 2 deletions rb/lib/selenium/webdriver/firefox/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class Driver < WebDriver::Driver
include LocalDriver

def initialize(options: nil, service: nil, url: nil, **opts)
caps, url = initialize_local_driver(options, service, url)
super(caps: caps, url: url, **opts)
initialize_local_driver(options, service, url) do |caps, driver_url|
super(caps: caps, url: driver_url, **opts)
end
end

def browser
Expand Down
5 changes: 3 additions & 2 deletions rb/lib/selenium/webdriver/ie/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class Driver < WebDriver::Driver
include LocalDriver

def initialize(options: nil, service: nil, url: nil, **opts)
caps, url = initialize_local_driver(options, service, url)
super(caps: caps, url: url, **opts)
initialize_local_driver(options, service, url) do |caps, driver_url|
super(caps: caps, url: driver_url, **opts)
end
end

def browser
Expand Down
5 changes: 3 additions & 2 deletions rb/lib/selenium/webdriver/safari/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class Driver < WebDriver::Driver
include LocalDriver

def initialize(options: nil, service: nil, url: nil, **opts)
caps, url = initialize_local_driver(options, service, url)
super(caps: caps, url: url, **opts)
initialize_local_driver(options, service, url) do |caps, driver_url|
super(caps: caps, url: driver_url, **opts)
end
end

def browser
Expand Down
Loading