|
| 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