Skip to content

Commit 29fc6d7

Browse files
committed
rb: Share Service#connect_until_stable
1 parent 5c63343 commit 29fc6d7

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

rb/lib/selenium/webdriver/chrome/service.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ def stop_server
5757
connect_to_server { |http| http.get("/shutdown") }
5858
end
5959

60-
def connect_until_stable
61-
socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
62-
63-
unless socket_poller.connected?
64-
raise Error::WebDriverError, "unable to connect to chromedriver #{@host}:#{@port}"
65-
end
60+
def cannot_connect_error_text
61+
"unable to connect to chromedriver #{@host}:#{@port}"
6662
end
6763

6864
end # Service

rb/lib/selenium/webdriver/common/service.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
module Selenium
2121
module WebDriver
2222

23+
#
24+
# Base class implementing default behavior of service object,
25+
# responsible for starting and stopping driver implementations.
26+
#
27+
# Subclasses must implement the following private methods:
28+
# * #start_process
29+
# * #stop_server
30+
# * #cannot_connect_error_text
2331
#
2432
# @api private
2533
#
@@ -99,6 +107,12 @@ def stop_process
99107
end
100108

101109
def connect_until_stable
110+
socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
111+
return if socket_poller.connected?
112+
raise Error::WebDriverError, cannot_connect_error_text
113+
end
114+
115+
def cannot_connect_error_text
102116
raise NotImplementedError, "subclass responsibility"
103117
end
104118

rb/lib/selenium/webdriver/edge/service.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ def start_process
5757
@process.start
5858
end
5959

60-
def connect_until_stable
61-
socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
62-
63-
unless socket_poller.connected?
64-
raise Error::WebDriverError, "unable to connect to MicrosoftWebDriver #{@host}:#{@port}"
65-
end
60+
def cannot_connect_error_text
61+
"unable to connect to MicrosoftWebDriver #{@host}:#{@port}"
6662
end
6763

6864
end # Service

rb/lib/selenium/webdriver/firefox/service.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,8 @@ def stop_server
7171
connect_to_server { |http| http.head("/shutdown") }
7272
end
7373

74-
def connect_until_stable
75-
@socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
76-
77-
unless @socket_poller.connected?
78-
raise Error::WebDriverError, "unable to connect to Mozilla Wires #{@host}:#{@port}"
79-
end
74+
def cannot_connect_error_text
75+
"unable to connect to Mozilla Wires #{@host}:#{@port}"
8076
end
8177

8278
end # Service

rb/lib/selenium/webdriver/phantomjs/service.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ def stop_server
7070
connect_to_server { |http| http.get("/shutdown") }
7171
end
7272

73-
def connect_until_stable
74-
socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
75-
76-
unless socket_poller.connected?
77-
raise Error::WebDriverError, "unable to connect to phantomjs @ #{uri} after #{START_TIMEOUT} seconds"
78-
end
73+
def cannot_connect_error_text
74+
"unable to connect to phantomjs @ #{uri} after #{START_TIMEOUT} seconds"
7975
end
8076

8177
end # Service

0 commit comments

Comments
 (0)