diff --git a/integration_test/chrome/capabilities_test.exs b/integration_test/chrome/capabilities_test.exs index 396eac6c..d9afa13b 100644 --- a/integration_test/chrome/capabilities_test.exs +++ b/integration_test/chrome/capabilities_test.exs @@ -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, @@ -27,6 +29,7 @@ defmodule Wallaby.Integration.CapabilitiesTest do browser: "DEBUG" }, chromeOptions: %{ + binary: chrome_binary, args: [ "--no-sandbox", "window-size=1280,800", @@ -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 diff --git a/lib/wallaby/chrome.ex b/lib/wallaby/chrome.ex index 7dd3a514..d3173381 100644 --- a/lib/wallaby/chrome.ex +++ b/lib/wallaby/chrome.ex @@ -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} @@ -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} @@ -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, @@ -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)