Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chromedriver): Account for Chromium when doing the version matching #698

Merged
merged 2 commits into from
Jul 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions lib/wallaby/chrome.ex
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,16 @@ defmodule Wallaby.Chrome do
"HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome"
])

chrome_version = parse_version("Version", stdout)
chrome_version = parse_version(stdout)

{:ok, chrome_version}

_ ->
case find_chrome_executable() do
{:ok, chrome_executable} ->
{stdout, 0} = System.cmd(chrome_executable, ["--version"])
chrome_version = parse_version("Google Chrome", stdout)

chrome_version = parse_version(stdout)

{:ok, chrome_version}

Expand All @@ -198,7 +199,7 @@ defmodule Wallaby.Chrome do
case find_chromedriver_executable() do
{:ok, chromedriver_executable} ->
{stdout, 0} = System.cmd(chromedriver_executable, ["--version"])
chromedriver_version = parse_version("ChromeDriver", stdout)
chromedriver_version = parse_version(stdout)

{:ok, chromedriver_version}

Expand All @@ -210,24 +211,27 @@ defmodule Wallaby.Chrome do
@doc false
@spec find_chrome_executable :: {:ok, String.t()} | {:error, DependencyError.t()}
def find_chrome_executable do
default_chrome_path =
default_chrome_paths =
case :os.type() do
{:unix, :darwin} ->
"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
[
"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome",
"/Applications/Chromium.app/Contents/MacOS/Chromium"
]

{:unix, :linux} ->
"google-chrome"
["google-chrome", "chromium", "chromium-browser"]

{:win32, :nt} ->
"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
["C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"]
end

chrome_path =
:wallaby
|> Application.get_env(:chromedriver, [])
|> Keyword.get(:binary, default_chrome_path)
|> Keyword.get(:binary, [])

[Path.expand(chrome_path), default_chrome_path]
[Path.expand(chrome_path) | default_chrome_paths]
|> Enum.find(&System.find_executable/1)
|> case do
path when is_binary(path) ->
Expand Down Expand Up @@ -312,9 +316,9 @@ defmodule Wallaby.Chrome do
{:error, exception}
end

defp parse_version(prefix, body) do
defp parse_version(body) do
result =
case Regex.run(~r/\b#{prefix}\b.*?(\d+\.\d+(\.\d+)?)/, body) do
case Regex.run(~r/.*?(\d+\.\d+(\.\d+)?)/, body) do
[_, version, _] ->
String.split(version, ".")

Expand Down