-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance and standardize capabilities between drivers
- Enables the ability to set capabilities by passing them as an option and using application configuration. - Implements default capabilities for Selenium. - Moves configuration options for using chrome headlessly, the chrome binary, and the chromedriver binary to the `:chromedriver` key in the `:wallaby` application config. - Moves documentation for Chrome and Selenium from the README and into their respective moduledocs.
- Loading branch information
Showing
9 changed files
with
533 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
defmodule Wallaby.Integration.CapabilitiesTest do | ||
use ExUnit.Case, async: true | ||
use Wallaby.DSL | ||
alias Wallaby.Integration.SessionCase | ||
alias Wallaby.Experimental.Selenium.WebdriverClient | ||
|
||
setup do | ||
on_exit fn -> | ||
Application.delete_env(:wallaby, :chromedriver) | ||
end | ||
end | ||
|
||
describe "capabilities" do | ||
test "reads default capabilities" do | ||
expected_capabilities = %{ | ||
javascriptEnabled: false, | ||
loadImages: false, | ||
version: "", | ||
rotatable: false, | ||
takesScreenshot: true, | ||
cssSelectorsEnabled: true, | ||
nativeEvents: false, | ||
platform: "ANY", | ||
unhandledPromptBehavior: "accept", | ||
loggingPrefs: %{ | ||
browser: "DEBUG" | ||
}, | ||
chromeOptions: %{ | ||
args: [ | ||
"--no-sandbox", | ||
"window-size=1280,800", | ||
"--disable-gpu", | ||
"--headless", | ||
"--fullscreen", | ||
"--user-agent=Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" | ||
] | ||
} | ||
} | ||
|
||
create_session_fn = fn url, capabilities -> | ||
assert capabilities == expected_capabilities | ||
|
||
WebdriverClient.create_session(url, capabilities) | ||
end | ||
|
||
{:ok, session} = SessionCase.start_test_session(create_session_fn: create_session_fn) | ||
|
||
session | ||
|> visit("page_1.html") | ||
|> assert_has(Query.text("Page 1")) | ||
|
||
assert :ok = Wallaby.end_session(session) | ||
end | ||
|
||
test "reads capabilities from application config" do | ||
expected_capabilities = %{chromeOptions: %{args: ["--headless"]}} | ||
Application.put_env(:wallaby, :chromedriver, capabilities: expected_capabilities) | ||
|
||
create_session_fn = fn url, capabilities -> | ||
assert capabilities == expected_capabilities | ||
|
||
WebdriverClient.create_session(url, capabilities) | ||
end | ||
|
||
{:ok, session} = SessionCase.start_test_session(create_session_fn: create_session_fn) | ||
|
||
session | ||
|> visit("page_1.html") | ||
|> assert_has(Query.text("Page 1")) | ||
|
||
assert :ok = Wallaby.end_session(session) | ||
end | ||
|
||
test "reads capabilities from opts when also using application config" do | ||
Application.put_env(:wallaby, :chromedriver, capabilities: %{}) | ||
expected_capabilities = %{chromeOptions: %{args: ["--headless"]}} | ||
|
||
create_session_fn = fn url, capabilities -> | ||
assert capabilities == expected_capabilities | ||
|
||
WebdriverClient.create_session(url, capabilities) | ||
end | ||
|
||
{:ok, session} = | ||
SessionCase.start_test_session( | ||
capabilities: expected_capabilities, | ||
create_session_fn: create_session_fn | ||
) | ||
|
||
session | ||
|> visit("page_1.html") | ||
|> assert_has(Query.text("Page 1")) | ||
|
||
assert :ok = Wallaby.end_session(session) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
defmodule Wallaby.Integration.CapabilitiesTest do | ||
use ExUnit.Case, async: true | ||
use Wallaby.DSL | ||
alias Wallaby.Integration.SessionCase | ||
alias Wallaby.Experimental.Selenium.WebdriverClient | ||
|
||
setup do | ||
on_exit(fn -> | ||
Application.delete_env(:wallaby, :selenium) | ||
end) | ||
end | ||
|
||
describe "capabilities" do | ||
test "reads default capabilities" do | ||
expected_capabilities = %{ | ||
javascriptEnabled: true, | ||
browserName: "firefox", | ||
"moz:firefoxOptions": %{ | ||
args: ["-headless"] | ||
} | ||
} | ||
|
||
create_session_fn = fn url, capabilities -> | ||
assert capabilities == expected_capabilities | ||
|
||
WebdriverClient.create_session(url, capabilities) | ||
end | ||
|
||
{:ok, session} = SessionCase.start_test_session(create_session_fn: create_session_fn) | ||
|
||
session | ||
|> visit("page_1.html") | ||
|> assert_has(Query.text("Page 1")) | ||
|
||
assert :ok = Wallaby.end_session(session) | ||
end | ||
|
||
test "reads capabilities from application config" do | ||
expected_capabilities = %{ | ||
browserName: "firefox", | ||
"moz:firefoxOptions": %{ | ||
args: ["-headless"] | ||
} | ||
} | ||
|
||
Application.put_env(:wallaby, :selenium, capabilities: expected_capabilities) | ||
|
||
create_session_fn = fn url, capabilities -> | ||
assert capabilities == expected_capabilities | ||
|
||
WebdriverClient.create_session(url, capabilities) | ||
end | ||
|
||
{:ok, session} = SessionCase.start_test_session(create_session_fn: create_session_fn) | ||
|
||
session | ||
|> visit("page_1.html") | ||
|> assert_has(Query.text("Page 1")) | ||
|
||
assert :ok = Wallaby.end_session(session) | ||
end | ||
|
||
test "reads capabilities from opts when also using application config" do | ||
Application.put_env(:wallaby, :selenium, capabilities: %{}) | ||
|
||
expected_capabilities = %{ | ||
browserName: "firefox", | ||
"moz:firefoxOptions": %{ | ||
args: ["-headless"] | ||
} | ||
} | ||
|
||
create_session_fn = fn url, capabilities -> | ||
assert capabilities == expected_capabilities | ||
|
||
WebdriverClient.create_session(url, capabilities) | ||
end | ||
|
||
{:ok, session} = | ||
SessionCase.start_test_session( | ||
capabilities: expected_capabilities, | ||
create_session_fn: create_session_fn | ||
) | ||
|
||
session | ||
|> visit("page_1.html") | ||
|> assert_has(Query.text("Page 1")) | ||
|
||
assert :ok = Wallaby.end_session(session) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.