Skip to content

Commit

Permalink
rb: Share Service#connect_until_stable
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed May 31, 2016
1 parent 5c63343 commit 29fc6d7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
8 changes: 2 additions & 6 deletions rb/lib/selenium/webdriver/chrome/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ def stop_server
connect_to_server { |http| http.get("/shutdown") }
end

def connect_until_stable
socket_poller = SocketPoller.new @host, @port, START_TIMEOUT

unless socket_poller.connected?
raise Error::WebDriverError, "unable to connect to chromedriver #{@host}:#{@port}"
end
def cannot_connect_error_text
"unable to connect to chromedriver #{@host}:#{@port}"
end

end # Service
Expand Down
14 changes: 14 additions & 0 deletions rb/lib/selenium/webdriver/common/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
module Selenium
module WebDriver

#
# Base class implementing default behavior of service object,
# responsible for starting and stopping driver implementations.
#
# Subclasses must implement the following private methods:
# * #start_process
# * #stop_server
# * #cannot_connect_error_text
#
# @api private
#
Expand Down Expand Up @@ -99,6 +107,12 @@ def stop_process
end

def connect_until_stable
socket_poller = SocketPoller.new @host, @port, START_TIMEOUT
return if socket_poller.connected?
raise Error::WebDriverError, cannot_connect_error_text
end

def cannot_connect_error_text
raise NotImplementedError, "subclass responsibility"
end

Expand Down
8 changes: 2 additions & 6 deletions rb/lib/selenium/webdriver/edge/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ def start_process
@process.start
end

def connect_until_stable
socket_poller = SocketPoller.new @host, @port, START_TIMEOUT

unless socket_poller.connected?
raise Error::WebDriverError, "unable to connect to MicrosoftWebDriver #{@host}:#{@port}"
end
def cannot_connect_error_text
"unable to connect to MicrosoftWebDriver #{@host}:#{@port}"
end

end # Service
Expand Down
8 changes: 2 additions & 6 deletions rb/lib/selenium/webdriver/firefox/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,8 @@ def stop_server
connect_to_server { |http| http.head("/shutdown") }
end

def connect_until_stable
@socket_poller = SocketPoller.new @host, @port, START_TIMEOUT

unless @socket_poller.connected?
raise Error::WebDriverError, "unable to connect to Mozilla Wires #{@host}:#{@port}"
end
def cannot_connect_error_text
"unable to connect to Mozilla Wires #{@host}:#{@port}"
end

end # Service
Expand Down
8 changes: 2 additions & 6 deletions rb/lib/selenium/webdriver/phantomjs/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ def stop_server
connect_to_server { |http| http.get("/shutdown") }
end

def connect_until_stable
socket_poller = SocketPoller.new @host, @port, START_TIMEOUT

unless socket_poller.connected?
raise Error::WebDriverError, "unable to connect to phantomjs @ #{uri} after #{START_TIMEOUT} seconds"
end
def cannot_connect_error_text
"unable to connect to phantomjs @ #{uri} after #{START_TIMEOUT} seconds"
end

end # Service
Expand Down

0 comments on commit 29fc6d7

Please sign in to comment.