Skip to content

Commit 4fee08a

Browse files
authored
Merge pull request #186 from janbiedermann/win_win
Windows support
2 parents 761365c + d235da8 commit 4fee08a

File tree

8 files changed

+29
-3
lines changed

8 files changed

+29
-3
lines changed

lib/ferrum/browser/options/base.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def except(*keys)
2626
def detect_path
2727
if Ferrum.mac?
2828
self.class::MAC_BIN_PATH.find { |n| File.exist?(n) }
29+
elsif Ferrum.windows?
30+
self.class::WINDOWS_BIN_PATH.find { |path| File.exist?(path) }
2931
else
3032
self.class::LINUX_BIN_PATH.find do |name|
3133
path = Cliver.detect(name) and break(path)

lib/ferrum/browser/options/chrome.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class Chrome < Base
4949
LINUX_BIN_PATH = %w[chromium google-chrome-unstable google-chrome-beta
5050
google-chrome chrome chromium-browser
5151
google-chrome-stable].freeze
52+
WINDOWS_BIN_PATH = [
53+
"C:/Program Files/Google/Chrome Dev/Application/chrome.exe",
54+
"C:/Program Files/Google/Chrome/Application/chrome.exe"
55+
].freeze
5256

5357
def merge_required(flags, options, user_data_dir)
5458
port = options.fetch(:port, BROWSER_PORT)

lib/ferrum/browser/options/firefox.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class Firefox < Base
1212
"/Applications/Firefox.app/Contents/MacOS/firefox-bin"
1313
].freeze
1414
LINUX_BIN_PATH = %w[firefox].freeze
15+
WINDOWS_BIN_PATH = [
16+
"C:/Program Files/Firefox Developer Edition/firefox.exe",
17+
"C:/Program Files/Mozilla Firefox/firefox.exe"
18+
].freeze
1519

1620
def merge_required(flags, options, user_data_dir)
1721
port = options.fetch(:port, BROWSER_PORT)

lib/ferrum/browser/process.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def self.process_killer(pid)
3434
proc do
3535
begin
3636
if Ferrum.windows?
37-
::Process.kill("KILL", pid)
37+
# Process.kill is unreliable on Windows
38+
::Process.kill("KILL", pid) unless system("taskkill /f /t /pid #{pid} >NUL 2>NUL")
3839
else
3940
::Process.kill("USR1", pid)
4041
start = Ferrum.monotonic_time
@@ -88,7 +89,7 @@ def start
8889
@xvfb = Xvfb.start(@command.options)
8990
ObjectSpace.define_finalizer(self, self.class.process_killer(@xvfb.pid))
9091
end
91-
92+
9293
@pid = ::Process.spawn(Hash(@xvfb&.to_env), *@command.to_a, process_options)
9394
ObjectSpace.define_finalizer(self, self.class.process_killer(@pid))
9495

lib/ferrum/page.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ def position
113113
@browser.command("Browser.getWindowBounds", windowId: window_id).fetch("bounds").values_at("left", "top")
114114
end
115115

116-
def position=(left:, top:)
116+
def position=(*args)
117+
if args.size == 1
118+
left = args[0][:left]
119+
top = args[0][:top]
120+
else
121+
raise "Use like: browser.position = { left: 1, right: 2}"
122+
end
117123
@browser.command("Browser.setWindowBounds", windowId: window_id, bounds: { left: left, top: top })
118124
end
119125

spec/support/broken_chrome.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "Broken Chrome error message"
2+
echo %0
3+
exit 1

spec/support/custom_chrome.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set DIRPATH=%~dp0
2+
type nul >> %DIRPATH%\custom_chrome_called
3+
set /p CHROME=<%DIRPATH%\chrome_path
4+
rem echo %CHROME% %* > %DIRPATH%\chrome_executed
5+
"%CHROME%" %*

spec/support/no_chrome.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dir

0 commit comments

Comments
 (0)