Skip to content

Commit 37aaacd

Browse files
committed
[rb] ensure driver process is always stopped
1 parent 345bee3 commit 37aaacd

File tree

7 files changed

+26
-16
lines changed

7 files changed

+26
-16
lines changed

rb/lib/selenium/webdriver/chrome/driver.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ class Driver < Chromium::Driver
3131
include LocalDriver
3232

3333
def initialize(options: nil, service: nil, url: nil, **)
34-
caps, url = initialize_local_driver(options, service, url)
35-
super(caps: caps, url: url, **)
34+
initialize_local_driver(options, service, url) do |caps, driver_url|
35+
super(caps: caps, url: driver_url, **)
36+
end
3637
end
3738

3839
def browser

rb/lib/selenium/webdriver/common/driver.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,6 @@ def create_bridge(caps:, url:, http_client: nil)
326326
end
327327
end
328328

329-
def service_url(service)
330-
@service_manager = service.launch
331-
@service_manager.uri
332-
end
333-
334329
def screenshot
335330
bridge.screenshot
336331
end

rb/lib/selenium/webdriver/common/local_driver.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@ def initialize_local_driver(options, service, url)
2727
caps = process_options(options, service)
2828
url = service_url(service)
2929

30-
[caps, url]
30+
begin
31+
yield(caps, url) if block_given?
32+
rescue Selenium::WebDriver::Error::WebDriverError
33+
@service_manager&.stop
34+
raise
35+
end
36+
end
37+
38+
def service_url(service)
39+
@service_manager = service.launch
40+
@service_manager.uri
3141
end
3242

3343
def process_options(options, service)

rb/lib/selenium/webdriver/edge/driver.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ class Driver < Chromium::Driver
3131
include LocalDriver
3232

3333
def initialize(options: nil, service: nil, url: nil, **)
34-
caps, url = initialize_local_driver(options, service, url)
35-
super(caps: caps, url: url, **)
34+
initialize_local_driver(options, service, url) do |caps, driver_url|
35+
super(caps: caps, url: driver_url, **)
36+
end
3637
end
3738

3839
def browser

rb/lib/selenium/webdriver/firefox/driver.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ class Driver < WebDriver::Driver
3737
include LocalDriver
3838

3939
def initialize(options: nil, service: nil, url: nil, **)
40-
caps, url = initialize_local_driver(options, service, url)
41-
super(caps: caps, url: url, **)
40+
initialize_local_driver(options, service, url) do |caps, driver_url|
41+
super(caps: caps, url: driver_url, **)
42+
end
4243
end
4344

4445
def browser

rb/lib/selenium/webdriver/ie/driver.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class Driver < WebDriver::Driver
3232
include LocalDriver
3333

3434
def initialize(options: nil, service: nil, url: nil, **)
35-
caps, url = initialize_local_driver(options, service, url)
36-
super(caps: caps, url: url, **)
35+
initialize_local_driver(options, service, url) do |caps, driver_url|
36+
super(caps: caps, url: driver_url, **)
37+
end
3738
end
3839

3940
def browser

rb/lib/selenium/webdriver/safari/driver.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class Driver < WebDriver::Driver
3232
include LocalDriver
3333

3434
def initialize(options: nil, service: nil, url: nil, **)
35-
caps, url = initialize_local_driver(options, service, url)
36-
super(caps: caps, url: url, **)
35+
initialize_local_driver(options, service, url) do |caps, driver_url|
36+
super(caps: caps, url: driver_url, **)
37+
end
3738
end
3839

3940
def browser

0 commit comments

Comments
 (0)