-
-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathselenium4_capabilities_test.exs
More file actions
137 lines (111 loc) · 3.73 KB
/
Copy pathselenium4_capabilities_test.exs
File metadata and controls
137 lines (111 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
defmodule Wallaby.Integration.Selenium4CapabilitiesTest do
use ExUnit.Case, async: false
use Wallaby.DSL
import Wallaby.SettingsTestHelpers
alias Wallaby.Integration.SessionCase
setup do
ensure_setting_is_reset(:wallaby, :selenium4)
end
describe "capabilities" do
test "reads default capabilities" do
expected_capabilities = %{
capabilities: %{
alwaysMatch: %{
browserName: "firefox",
"moz:firefoxOptions": %{
binary: System.find_executable("firefox"),
args: ["-headless"],
prefs: %{
"general.useragent.override" =>
"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 config, capabilities ->
assert capabilities == expected_capabilities
WebDriverClient.start_session(config, 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 = %{
capabilities: %{
alwaysMatch: %{
browserName: "firefox",
"moz:firefoxOptions": %{
binary: System.find_executable("firefox"),
args: ["-headless"]
}
}
}
}
Application.put_env(:wallaby, :selenium4, capabilities: expected_capabilities)
create_session_fn = fn config, capabilities ->
assert capabilities == expected_capabilities
WebDriverClient.start_session(config, 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 "adds the beam metadata when it is present" do
user_agent = "Mozilla/5.0"
defined_capabilities = %{
capabilities: %{
alwaysMatch: %{
browserName: "firefox",
"moz:firefoxOptions": %{
binary: System.find_executable("firefox"),
args: ["-headless"],
prefs: %{
"general.useragent.override" => user_agent
}
}
}
}
}
metadata =
if Version.compare(System.version(), "1.16.0") in [:eq, :gt] do
"g2gCdwJ2MXQAAAABbQAAAARzb21lbQAAAAhtZXRhZGF0YQ=="
else
"g2gCZAACdjF0AAAAAW0AAAAEc29tZW0AAAAIbWV0YWRhdGE="
end
expected_capabilities = %{
capabilities: %{
alwaysMatch: %{
browserName: "firefox",
"moz:firefoxOptions": %{
binary: System.find_executable("firefox"),
args: ["-headless"],
prefs: %{
"general.useragent.override" => "#{user_agent}/BeamMetadata (#{metadata})"
}
}
}
}
}
Application.put_env(:wallaby, :selenium4, capabilities: defined_capabilities)
create_session_fn = fn config, capabilities ->
assert capabilities == expected_capabilities
WebDriverClient.start_session(config, capabilities)
end
{:ok, session} =
SessionCase.start_test_session(
create_session_fn: create_session_fn,
metadata: %{"some" => "metadata"}
)
session
|> visit("page_1.html")
|> assert_has(Query.text("Page 1"))
assert :ok = Wallaby.end_session(session)
end
end
end