@@ -34,88 +34,33 @@ def bin_path
3434 @bin_path ||= '../../../../../bin'
3535 end
3636
37- # @param [Options] options browser options.
38- # @return [String] the path to the correct driver.
39- def driver_path ( options )
40- command = generate_command ( binary , options )
41-
42- output = run ( *command )
43-
44- browser_path = Platform . cygwin? ? Platform . cygwin_path ( output [ 'browser_path' ] ) : output [ 'browser_path' ]
45- driver_path = Platform . cygwin? ? Platform . cygwin_path ( output [ 'driver_path' ] ) : output [ 'driver_path' ]
46- Platform . assert_executable driver_path
47-
48- if options . respond_to? ( :binary ) && browser_path && !browser_path . empty?
49- options . binary = browser_path
50- options . browser_version = nil
51- end
52-
53- driver_path
37+ # @param [Array] arguments what gets sent to to Selenium Manager binary.
38+ # @return [Hash] paths to the requested assets.
39+ def binary_paths ( *arguments )
40+ arguments += %w[ --language-binding ruby ]
41+ arguments += %w[ --output json ]
42+ arguments << '--debug' if WebDriver . logger . debug?
43+
44+ run ( binary , *arguments )
5445 end
5546
5647 private
5748
58- def generate_command ( binary , options )
59- command = [ binary , '--browser' , options . browser_name ]
60- if options . browser_version
61- command << '--browser-version'
62- command << options . browser_version
63- end
64- if options . respond_to? ( :binary ) && !options . binary . nil?
65- command << '--browser-path'
66- command << options . binary . gsub ( '\\' , '\\\\\\' )
67- end
68- if options . proxy
69- command << '--proxy'
70- command << ( options . proxy . ssl || options . proxy . http )
71- end
72- command
73- end
74-
7549 # @return [String] the path to the correct selenium manager
7650 def binary
7751 @binary ||= begin
78- location = ENV . fetch ( 'SE_MANAGER_PATH' , begin
79- directory = File . expand_path ( bin_path , __FILE__ )
80- if Platform . windows?
81- "#{ directory } /windows/selenium-manager.exe"
82- elsif Platform . mac?
83- "#{ directory } /macos/selenium-manager"
84- elsif Platform . linux?
85- "#{ directory } /linux/selenium-manager"
86- elsif Platform . unix?
87- WebDriver . logger . warn ( 'Selenium Manager binary may not be compatible with Unix; verify settings' ,
88- id : %i[ selenium_manager unix_binary ] )
89- "#{ directory } /linux/selenium-manager"
90- end
91- rescue Error ::WebDriverError => e
92- raise Error ::WebDriverError , "Unable to obtain Selenium Manager binary for #{ e . message } "
93- end )
52+ if ( location = ENV . fetch ( 'SE_MANAGER_PATH' , nil ) )
53+ WebDriver . logger . debug ( "Selenium Manager set by ENV['SE_MANAGER_PATH']: #{ location } " )
54+ end
55+ location ||= platform_location
9456
95- validate_location ( location )
96- location
97- end
98- end
99-
100- def validate_location ( location )
101- begin
102- Platform . assert_file ( location )
10357 Platform . assert_executable ( location )
104- rescue TypeError
105- raise Error ::WebDriverError ,
106- "Unable to locate or obtain Selenium Manager binary; #{ location } is not a valid file object"
107- rescue Error ::WebDriverError => e
108- raise Error ::WebDriverError , "Selenium Manager binary located, but #{ e . message } "
58+ WebDriver . logger . debug ( "Selenium Manager binary found at #{ location } " , id : :selenium_manager )
59+ location
10960 end
110-
111- WebDriver . logger . debug ( "Selenium Manager binary found at #{ location } " , id : :selenium_manager )
11261 end
11362
11463 def run ( *command )
115- command += %w[ --language-binding ruby ]
116- command += %w[ --output json ]
117- command << '--debug' if WebDriver . logger . debug?
118-
11964 WebDriver . logger . debug ( "Executing Process #{ command } " , id : :selenium_manager )
12065
12166 begin
@@ -124,16 +69,34 @@ def run(*command)
12469 raise Error ::WebDriverError , "Unsuccessful command executed: #{ command } ; #{ e . message } "
12570 end
12671
127- json_output = stdout . empty? ? { } : JSON . parse ( stdout )
128- ( json_output [ 'logs' ] || [ ] ) . each do |log |
72+ json_output = stdout . empty? ? { 'logs' => [ ] , 'result' => { } } : JSON . parse ( stdout )
73+ json_output [ 'logs' ] . each do |log |
12974 level = log [ 'level' ] . casecmp ( 'info' ) . zero? ? 'debug' : log [ 'level' ] . downcase
13075 WebDriver . logger . send ( level , log [ 'message' ] , id : :selenium_manager )
13176 end
13277
13378 result = json_output [ 'result' ]
134- return result unless status . exitstatus . positive?
79+ return result unless status . exitstatus . positive? || result . nil?
13580
136- raise Error ::WebDriverError , "Unsuccessful command executed: #{ command } \n #{ result } #{ stderr } "
81+ raise Error ::WebDriverError ,
82+ "Unsuccessful command executed: #{ command } - Code #{ status . exitstatus } \n #{ result } \n #{ stderr } "
83+ end
84+
85+ def platform_location
86+ directory = File . expand_path ( bin_path , __FILE__ )
87+ if Platform . windows?
88+ "#{ directory } /windows/selenium-manager.exe"
89+ elsif Platform . mac?
90+ "#{ directory } /macos/selenium-manager"
91+ elsif Platform . linux?
92+ "#{ directory } /linux/selenium-manager"
93+ elsif Platform . unix?
94+ WebDriver . logger . warn ( 'Selenium Manager binary may not be compatible with Unix' ,
95+ id : %i[ selenium_manager unix_binary ] )
96+ "#{ directory } /linux/selenium-manager"
97+ else
98+ raise Error ::WebDriverError , "unsupported platform: #{ Platform . os } "
99+ end
137100 end
138101 end
139102 end # SeleniumManager
0 commit comments