Skip to content

Commit

Permalink
Chrome headless and binary opts can be passed in @sessions (#736)
Browse files Browse the repository at this point in the history
* Chrome headless and binary opts can be passed in @sessions

* New options are documented
  • Loading branch information
dvic authored Jul 12, 2023
1 parent a7f7380 commit 389d416
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions lib/wallaby/chrome.ex
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ defmodule Wallaby.Chrome do
:wallaby
|> Application.get_env(:chromedriver, [])
|> Keyword.get(:capabilities, default_capabilities(opts))
|> put_headless_config()
|> put_binary_config()
|> put_headless_config(opts)
|> put_binary_config(opts)
end

@spec wait_until_ready!(timeout) :: :ok | no_return
Expand Down Expand Up @@ -576,8 +576,8 @@ defmodule Wallaby.Chrome do
}
end

defp put_headless_config(capabilities) do
headless? = Application.get_env(:wallaby, :chromedriver, []) |> Keyword.get(:headless)
defp put_headless_config(capabilities, opts) do
headless? = resolve_opt(opts, :headless)

capabilities
|> update_unless_nil(:args, headless?, fn args ->
Expand All @@ -590,15 +590,22 @@ defmodule Wallaby.Chrome do
end)
end

defp put_binary_config(capabilities) do
binary_path = Application.get_env(:wallaby, :chromedriver, []) |> Keyword.get(:binary)
defp put_binary_config(capabilities, opts) do
binary_path = resolve_opt(opts, :binary)

capabilities
|> update_unless_nil(:binary, binary_path, fn _ ->
binary_path
end)
end

defp resolve_opt(opts, key) do
case Keyword.fetch(opts, key) do
{:ok, value} -> value
:error -> Application.get_env(:wallaby, :chromedriver, []) |> Keyword.get(key)
end
end

defp update_unless_nil(capabilities, _key, nil, _updater), do: capabilities

defp update_unless_nil(capabilities, key, _, updater) do
Expand Down
4 changes: 2 additions & 2 deletions lib/wallaby/feature.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ defmodule Wallaby.Feature do
end
```
If you need to change the capabilities sent to the session for a specific feature, you can assign `@sessions` to a list of keyword lists of the options to be passed to `Wallaby.start_session/1`. This will start the number of sessions equal to the size of the list.
If you need to change the headless mode, binary path, or capabilities sent to the session for a specific feature, you can assign `@sessions` to a list of keyword lists of the options to be passed to `Wallaby.start_session/1`. This will start the number of sessions equal to the size of the list.
```
@sessions [
[capabilities: %{}]
[headless: false, binary: "some_path", capabilities: %{}]
]
feature "test with different capabilities", %{session: session} do
# ...
Expand Down

0 comments on commit 389d416

Please sign in to comment.