|
| 1 | +defmodule E2E.UI.ProjectCreationFlowTest do |
| 2 | + use E2E.UI.UserTestCase |
| 3 | + require Logger |
| 4 | + |
| 5 | + describe "Project Creation Flow" do |
| 6 | + @tag timeout: 600_000 |
| 7 | + test "complete project creation flow", %{session: session} do |
| 8 | + Logger.info("Starting Project Creation Flow test") |
| 9 | + |
| 10 | + # Step 1: Navigate to project creation page |
| 11 | + Logger.info("Step 1: Navigating to project creation page") |
| 12 | + session = click(session, Wallaby.Query.link("Create new")) |
| 13 | + |
| 14 | + # Verify we're on the project creation page |
| 15 | + Logger.info("Verifying project creation page") |
| 16 | + session = assert_has(session, Wallaby.Query.css("h1", text: "Project type")) |
| 17 | + |
| 18 | + # Step 2: Select GitHub integration using a specific CSS selector |
| 19 | + Logger.info("Step 2: Selecting GitHub integration") |
| 20 | + session = click(session, Wallaby.Query.css(".f3.b", text: "GitHub")) |
| 21 | + |
| 22 | + # Take screenshot to see what happened |
| 23 | + take_screenshot(session, name: "after_github_click") |
| 24 | + |
| 25 | + # Verify we're on the repository selection page |
| 26 | + Logger.info("Verifying repository selection page") |
| 27 | + session = assert_has(session, Wallaby.Query.css("h2", text: "Repository")) |
| 28 | + |
| 29 | + # Step 3: Search for repositories |
| 30 | + Logger.info("Step 3: Searching for repositories") |
| 31 | + |
| 32 | + session = |
| 33 | + fill_in(session, Wallaby.Query.fillable_field("Search repositories..."), with: "e2e-tests") |
| 34 | + |
| 35 | + # Give the search some time to complete |
| 36 | + :timer.sleep(1000) |
| 37 | + |
| 38 | + session = assert_has(session, Wallaby.Query.css(".option")) |
| 39 | + |
| 40 | + # Try to find and click the "Choose" button if available |
| 41 | + Logger.info("Clicking 'Choose' button") |
| 42 | + session = click(session, Wallaby.Query.css(".green", text: "Choose")) |
| 43 | + |
| 44 | + # Take screenshot after repository selection |
| 45 | + take_screenshot(session, name: "after_repository_selection") |
| 46 | + # Give some time to check for duplicates |
| 47 | + :timer.sleep(1000) |
| 48 | + take_screenshot(session, name: "after_repository_selection_with_duplicates") |
| 49 | + |
| 50 | + session = maybe_enable_duplicate(session) |
| 51 | + |
| 52 | + Logger.info("Clicking create project button") |
| 53 | + session = wait_for(session, Wallaby.Query.css("button.btn.btn-primary"), 30_000) |
| 54 | + click(session, Wallaby.Query.button("✓")) |
| 55 | + |
| 56 | + # Take screenshot after clicking continue |
| 57 | + take_screenshot(session, name: "after_continue") |
| 58 | + |
| 59 | + :timer.sleep(15_000) |
| 60 | + # Verify we moved to the analysis page and check for the analysis steps checklist |
| 61 | + take_screenshot(session, name: "analysis_page") |
| 62 | + |
| 63 | + # wait for project creation to complete (until webhook readonly input is visible) |
| 64 | + # This can take up to 15 seconds |
| 65 | + Logger.info("Waiting for project creation to complete (up to 15 seconds)...") |
| 66 | + |
| 67 | + # click continue button |
| 68 | + session = click(session, Wallaby.Query.link("Continue")) |
| 69 | + |
| 70 | + # Click on the "I want to configure this project from scratch" link |
| 71 | + Logger.info("Clicking 'I want to configure this project from scratch' link") |
| 72 | + |
| 73 | + session = |
| 74 | + click(session, Wallaby.Query.link("I want to configure this project from scratch")) |
| 75 | + |
| 76 | + # Take a screenshot after clicking the link |
| 77 | + take_screenshot(session, name: "configure_from_scratch") |
| 78 | + |
| 79 | + # Click continue button again after selecting "configure from scratch" |
| 80 | + Logger.info("Clicking Continue button again") |
| 81 | + session = assert_has(session, Wallaby.Query.button("Continue")) |
| 82 | + session = click(session, Wallaby.Query.button("Continue")) |
| 83 | + |
| 84 | + # Take a screenshot after clicking continue again |
| 85 | + take_screenshot(session, name: "after_second_continue") |
| 86 | + |
| 87 | + # Click "Looks good, start →" button |
| 88 | + Logger.info("Clicking 'Looks good, start →' button") |
| 89 | + session = assert_has(session, Wallaby.Query.button("Looks good, start →")) |
| 90 | + session = click(session, Wallaby.Query.button("Looks good, start →")) |
| 91 | + |
| 92 | + # Take a screenshot after clicking the start button |
| 93 | + take_screenshot(session, name: "after_start_button") |
| 94 | + |
| 95 | + Logger.info("Waiting 15 seconds for page transition...") |
| 96 | + :timer.sleep(15_000) |
| 97 | + |
| 98 | + # Verify the URL path starts with "/workflows/" |
| 99 | + Logger.info("Verifying we are on the workflows page") |
| 100 | + current_url = current_url(session) |
| 101 | + |
| 102 | + assert String.contains?(current_url, "/workflows/"), |
| 103 | + "Expected URL to contain '/workflows/', but got: #{current_url}" |
| 104 | + |
| 105 | + # Take a final screenshot of the workflows page |
| 106 | + take_screenshot(session, name: "workflows_page") |
| 107 | + |
| 108 | + Logger.info("Project Creation completed successfully, flow test is complete") |
| 109 | + end |
| 110 | + end |
| 111 | + |
| 112 | + defp maybe_enable_duplicate(session) do |
| 113 | + duplicate_button = Wallaby.Query.button("Make a duplicate project") |
| 114 | + |
| 115 | + if has?(session, duplicate_button) do |
| 116 | + click(session, duplicate_button) |
| 117 | + else |
| 118 | + session |
| 119 | + end |
| 120 | + end |
| 121 | + |
| 122 | + defp wait_for(session, query, timeout_ms, interval_ms \\ 200) |
| 123 | + defp wait_for(session, query, timeout_ms, _interval_ms) when timeout_ms <= 0 do |
| 124 | + assert_has(session, query) |
| 125 | + end |
| 126 | + |
| 127 | + defp wait_for(session, query, timeout_ms, interval_ms) do |
| 128 | + if has?(session, query) do |
| 129 | + session |
| 130 | + else |
| 131 | + Process.sleep(interval_ms) |
| 132 | + wait_for(session, query, timeout_ms - interval_ms, interval_ms) |
| 133 | + end |
| 134 | + end |
| 135 | + |
| 136 | +end |
0 commit comments