Skip to content

Commit

Permalink
fix: use detected chrome binary path as default (#740)
Browse files Browse the repository at this point in the history
Fixes #739
  • Loading branch information
dvic authored Jul 25, 2023
1 parent cdff788 commit 1b164ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
5 changes: 4 additions & 1 deletion integration_test/chrome/capabilities_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ defmodule Wallaby.Integration.CapabilitiesTest do

describe "capabilities" do
test "reads default capabilities" do
assert {:ok, chrome_binary} = Wallaby.Chrome.find_chrome_executable()

expected_capabilities = %{
javascriptEnabled: false,
loadImages: false,
Expand All @@ -27,6 +29,7 @@ defmodule Wallaby.Integration.CapabilitiesTest do
browser: "DEBUG"
},
chromeOptions: %{
binary: chrome_binary,
args: [
"--no-sandbox",
"window-size=1280,800",
Expand All @@ -39,7 +42,7 @@ defmodule Wallaby.Integration.CapabilitiesTest do
}

create_session_fn = fn url, capabilities ->
assert capabilities == expected_capabilities
assert ^expected_capabilities = capabilities

WebdriverClient.create_session(url, capabilities)
end
Expand Down
34 changes: 22 additions & 12 deletions lib/wallaby/chrome.ex
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ defmodule Wallaby.Chrome do
|> Keyword.get(:binary, [])

[Path.expand(chrome_path) | default_chrome_paths]
|> Enum.find(&System.find_executable/1)
|> Enum.find_value(&System.find_executable/1)
|> case do
path when is_binary(path) ->
{:ok, path}
Expand All @@ -257,7 +257,7 @@ defmodule Wallaby.Chrome do
|> Keyword.get(:path, "chromedriver")

[Path.expand(chromedriver_path), chromedriver_path]
|> Enum.find(&System.find_executable/1)
|> Enum.find_value(&System.find_executable/1)
|> case do
path when is_binary(path) ->
{:ok, path}
Expand Down Expand Up @@ -550,6 +550,18 @@ defmodule Wallaby.Chrome do
opts[:metadata]
)

chrome_options =
maybe_put_chrome_executable(%{
args: [
"--no-sandbox",
"window-size=1280,800",
"--disable-gpu",
"--headless",
"--fullscreen",
"--user-agent=#{user_agent}"
]
})

%{
javascriptEnabled: false,
loadImages: false,
Expand All @@ -563,19 +575,17 @@ defmodule Wallaby.Chrome do
loggingPrefs: %{
browser: "DEBUG"
},
chromeOptions: %{
args: [
"--no-sandbox",
"window-size=1280,800",
"--disable-gpu",
"--headless",
"--fullscreen",
"--user-agent=#{user_agent}"
]
}
chromeOptions: chrome_options
}
end

defp maybe_put_chrome_executable(chrome_options) do
case find_chrome_executable() do
{:ok, chrome_binary} -> Map.put(chrome_options, :binary, chrome_binary)
_ -> chrome_options
end
end

defp put_headless_config(capabilities, opts) do
headless? = resolve_opt(opts, :headless)

Expand Down

0 comments on commit 1b164ec

Please sign in to comment.