File tree Expand file tree Collapse file tree 4 files changed +32
-7
lines changed
rb/lib/selenium/webdriver/safari Expand file tree Collapse file tree 4 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ def camel_case(str)
104
104
105
105
def prepare_connect_file
106
106
# TODO: use tempfile?
107
- path = File . join ( Dir . tmpdir , "safaridriver-#{ Time . now . to_i } .html" )
107
+ path = File . join ( Dir . tmpdir , "safaridriver-#{ Time . now . usec } .html" )
108
108
109
109
File . open ( path , 'w' ) do |io |
110
110
io << "<!DOCTYPE html><script>window.location = '#{ @server . uri } ';</script>"
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ module Safari
23
23
24
24
class Browser
25
25
def start ( *args )
26
+ Platform . exit_hook { stop } # make sure we don't leave the browser running
27
+
26
28
@process = ChildProcess . new ( Safari . path , *args )
27
29
@process . io . inherit! if $DEBUG
28
30
@process . start
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ module Selenium
21
21
module WebDriver
22
22
module Safari
23
23
class Options
24
+ DEFAULT_PORT = 56485
25
+
24
26
attr_accessor :port , :data_dir , :skip_extension_installation
25
27
26
28
def initialize ( opts = { } )
@@ -40,16 +42,16 @@ def to_capabilities
40
42
41
43
def as_json
42
44
{
43
- 'port' => port ,
44
- 'dataDir' => data_dir ,
45
- 'cleanSession' => clean_session? ,
45
+ 'port' => port ,
46
+ 'dataDir' => data_dir ,
47
+ 'cleanSession' => clean_session? ,
46
48
}
47
49
end
48
50
49
51
private
50
52
51
53
def extract_options ( opts )
52
- @port = Integer ( opts [ :port ] || PortProber . random )
54
+ @port = Integer ( opts [ :port ] || DEFAULT_PORT )
53
55
@data_dir = opts [ :custom_data_dir ] || opts [ :data_dir ]
54
56
@clean_session = opts [ :clean_session ]
55
57
end
Original file line number Diff line number Diff line change @@ -22,13 +22,20 @@ module WebDriver
22
22
module Safari
23
23
24
24
class Server
25
+ SOCKET_LOCK_TIMEOUT = 45
26
+
25
27
def initialize ( port , command_timeout )
26
- @port = port
28
+ @port = port
27
29
@command_timeout = command_timeout
28
30
end
29
31
30
32
def start
31
- @server = TCPServer . new ( Platform . localhost , @port )
33
+ Platform . exit_hook { stop } # make sure we don't leave the server running
34
+
35
+ socket_lock . locked do
36
+ find_free_port
37
+ start_server
38
+ end
32
39
end
33
40
34
41
def stop
@@ -158,6 +165,20 @@ def encode_form_component(str)
158
165
end
159
166
end
160
167
168
+ private
169
+
170
+ def start_server
171
+ @server = TCPServer . new ( Platform . localhost , @port )
172
+ end
173
+
174
+ def find_free_port
175
+ @port = PortProber . above @port
176
+ end
177
+
178
+ def socket_lock
179
+ @socket_lock ||= SocketLock . new ( @port - 1 , SOCKET_LOCK_TIMEOUT )
180
+ end
181
+
161
182
end # Server
162
183
end # Safari
163
184
end # WebDriver
You can’t perform that action at this time.
0 commit comments