Skip to content

Commit 03d08ba

Browse files
committed
chore(e2e): introduce user login case
1 parent 31e8752 commit 03d08ba

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

e2e/test/e2e/ui/example_user_test.exs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule E2E.UI.ExampleUserTest do
2+
use E2E.UI.UserTestCase
3+
4+
describe "Dashboard" do
5+
test "User can view dashboard elements", %{session: session, organization: organization, base_domain: base_domain} do
6+
# Test starts with already logged-in user because of UserTestCase setup
7+
8+
# Navigate to dashboard
9+
dashboard_url = "https://#{organization}.#{base_domain}/dashboard"
10+
11+
session
12+
|> Wallaby.Browser.visit(dashboard_url)
13+
|> Wallaby.Browser.assert_has(Wallaby.Query.css(".dashboard-content"))
14+
15+
# Take a screenshot of dashboard
16+
Wallaby.Browser.take_screenshot(session)
17+
end
18+
end
19+
end

e2e/test/support/ui_test_case.ex

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
defmodule E2E.UI.UserTestCase do
2+
@moduledoc """
3+
A custom ExUnit case for UI tests requiring a logged-in user.
4+
5+
This module automatically:
6+
- Tags tests with :user and :browser
7+
- Sets up Wallaby browser session
8+
- Performs user login before each test
9+
"""
10+
11+
use ExUnit.CaseTemplate
12+
13+
using do
14+
quote do
15+
use ExUnit.Case, async: false
16+
use Wallaby.DSL
17+
18+
@moduletag :user
19+
@moduletag :browser
20+
@moduletag timeout: 300_000
21+
end
22+
end
23+
24+
setup_all do
25+
Application.put_env(:wallaby, :js_errors, false)
26+
:ok
27+
end
28+
29+
setup do
30+
{:ok, session} = Wallaby.start_session(js_errors: false)
31+
32+
base_domain = Application.get_env(:e2e, :semaphore_base_domain)
33+
root_email = Application.get_env(:e2e, :semaphore_root_email)
34+
root_password = Application.get_env(:e2e, :semaphore_root_password)
35+
organization = Application.get_env(:e2e, :semaphore_organization)
36+
37+
login_url = "https://id.#{base_domain}/login"
38+
39+
logged_in_session =
40+
session
41+
|> Wallaby.Browser.visit(login_url)
42+
|> Wallaby.Browser.fill_in(Wallaby.Query.text_field("username"), with: root_email)
43+
|> Wallaby.Browser.fill_in(Wallaby.Query.text_field("password"), with: root_password)
44+
|> Wallaby.Browser.click(Wallaby.Query.css("#kc-login"))
45+
|> Wallaby.Browser.assert_has(
46+
Wallaby.Query.css("h1.f2.f1-m.lh-title.mb1",
47+
text: "Here's what's going on",
48+
timeout: 10_000
49+
)
50+
)
51+
52+
{:ok, session: logged_in_session, organization: organization, base_domain: base_domain}
53+
end
54+
end

0 commit comments

Comments
 (0)