Skip to content

Commit 5c63343

Browse files
committed
rb: Share method to communicate to running service
1 parent a60cd4d commit 5c63343

File tree

5 files changed

+13
-24
lines changed

5 files changed

+13
-24
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ def start_process
5454
end
5555

5656
def stop_server
57-
Net::HTTP.start(@host, @port) do |http|
58-
http.open_timeout = STOP_TIMEOUT / 2
59-
http.read_timeout = STOP_TIMEOUT / 2
60-
61-
http.get("/shutdown")
62-
end
57+
connect_to_server { |http| http.get("/shutdown") }
6358
end
6459

6560
def connect_until_stable

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ def uri
7171

7272
private
7373

74+
def connect_to_server
75+
Net::HTTP.start(@host, @port) do |http|
76+
http.open_timeout = STOP_TIMEOUT / 2
77+
http.read_timeout = STOP_TIMEOUT / 2
78+
79+
yield http
80+
end
81+
end
82+
7483
def find_free_port
7584
@port = PortProber.above(@port)
7685
end

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ def self.default_service(*extra_args)
4646
private
4747

4848
def stop_server
49-
Net::HTTP.start(@host, @port) do |http|
50-
http.open_timeout = STOP_TIMEOUT / 2
51-
http.read_timeout = STOP_TIMEOUT / 2
52-
53-
http.head("/shutdown")
54-
end
49+
connect_to_server { |http| http.head("/shutdown") }
5550
end
5651

5752
def start_process

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ def stop_process
6868
end
6969

7070
def stop_server
71-
Net::HTTP.start(@host, @port) do |http|
72-
http.open_timeout = STOP_TIMEOUT / 2
73-
http.read_timeout = STOP_TIMEOUT / 2
74-
75-
http.head("/shutdown")
76-
end
71+
connect_to_server { |http| http.head("/shutdown") }
7772
end
7873

7974
def connect_until_stable

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,7 @@ def stop_process
6767
end
6868

6969
def stop_server
70-
Net::HTTP.start(@host, @port) do |http|
71-
http.open_timeout = STOP_TIMEOUT / 2
72-
http.read_timeout = STOP_TIMEOUT / 2
73-
74-
http.get("/shutdown")
75-
end
70+
connect_to_server { |http| http.get("/shutdown") }
7671
end
7772

7873
def connect_until_stable

0 commit comments

Comments
 (0)