diff --git a/Makefile b/Makefile index 2133d13..a98b7ce 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,9 @@ test-e2e: test-e2e-headed: pytest -m "e2e" --browser chromium --headed +test-e2e-headed-slowmo: + pytest -m "priority1" --browser chromium --headed --slowmo=2000 + test-regression: pytest tests/test_e2e_regression.py -m "regression" --browser chromium diff --git a/tests/conftest.py b/tests/conftest.py index 89cb6dc..9ca35cc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -132,6 +132,7 @@ def browser_context_args(browser_context_args): **BROWSER_CONFIG, "record_video_dir": "test-results/videos/", "record_har_path": "test-results/har/trace.har", + "record_video_size": {"width": 1280, "height": 720}, } diff --git a/tests/test_e2e_authentication.py b/tests/test_e2e_authentication.py index 413c13b..fb1be90 100644 --- a/tests/test_e2e_authentication.py +++ b/tests/test_e2e_authentication.py @@ -80,7 +80,6 @@ class TestAuthentication: submit_button = page.locator("button[type='submit'], input[type='submit']") expect(submit_button.first).to_be_visible() - @pytest.mark.e2e def test_page_loads_without_errors(self, app_server, page: Page): """Test that the login page loads without console errors""" console_errors = [] @@ -121,3 +120,136 @@ class TestAuthentication: assert "test_mmt_" in test_database, "Database path should contain test prefix" print(f"✅ Test database isolation confirmed: {test_database}") + + # ============================================================================= + # PRIORITY 1 TESTS - CRITICAL AUTHENTICATION FLOWS + # ============================================================================= + + @pytest.mark.e2e + @pytest.mark.priority1 + @pytest.mark.smoke + def test_successful_login_with_valid_credentials(self, app_server, test_users, page: Page): + """ + Priority 1 Test: Validate complete successful login flow with valid credentials + + This test ensures that: + 1. User can access the login page + 2. User can enter valid credentials + 3. Form submission works correctly + 4. User is redirected to home page after successful authentication + 5. User session is properly established + """ + admin_user = test_users["admin"] + + # Step 1: Navigate to login page + page.goto(BASE_URL) + page.wait_for_load_state("networkidle") + + # Verify we're on the login page + expect(page).to_have_url(f"{BASE_URL}/authlogin/login") + + # Step 2: Locate form elements + email_input = page.locator("input[type='email'], input[name='email']") + password_input = page.locator("input[type='password'], input[name='password']") + submit_button = page.locator("button[type='submit']") + + # Verify all required elements are present and visible + expect(email_input).to_be_visible() + expect(password_input).to_be_visible() + expect(submit_button).to_be_visible() + + # Step 3: Fill in valid credentials + email_input.fill(admin_user["email"]) + password_input.fill(admin_user["password"]) + + # Verify credentials were entered correctly + expect(email_input).to_have_value(admin_user["email"]) + expect(password_input).to_have_value(admin_user["password"]) + + # Step 4: Submit the login form + # Use click with wait for navigation to handle the redirect + with page.expect_navigation(wait_until="networkidle"): + submit_button.click() + + # DEBUGGING BLOCK - Add this + print(f"🔍 Current URL: {page.url}") + print(f"🔍 Page title: {page.title()}") + + # Take screenshot + page.screenshot(path="debug_after_login.png") + + # Save full HTML for inspection + with open("debug_page.html", "w", encoding="utf-8") as f: + f.write(page.content()) + + # Check specific content that's causing the failure + page_content = page.content().lower() + login_keywords = ["sign in", "login", "authenticate"] + + print("🔍 Checking for login keywords:") + for keyword in login_keywords: + if keyword in page_content: + print(f" ❌ Found '{keyword}' in page content") + # Find exactly where this keyword appears + occurrences = page.get_by_text(keyword, exact=False) + count = occurrences.count() + print(f" Found in {count} elements:") + for i in range(min(count, 3)): # Show first 3 occurrences + element = occurrences.nth(i) + try: + print(f" - Element {i}: '{element.inner_text()[:50]}...' (visible: {element.is_visible()})") + except: + print(f" - Element {i}: Could not get text") + else: + print(f" ✅ '{keyword}' NOT found") + + # Your original assertion (will still fail, but now you have debug info) + has_login_content = any(keyword in page_content for keyword in login_keywords) + assert not has_login_content, "Login content still visible after successful authentication" + + page.pause() + + # Step 5: Verify successful authentication and redirect + # Should be redirected to the home page + expect(page).to_have_url(BASE_URL + "/") + + # Step 6: Verify we're actually authenticated (not redirected back to login) + # The page should load without being redirected back to login + page.wait_for_load_state("networkidle") + current_url = page.url + assert not current_url.endswith("/authlogin/login"), f"User was redirected back to login page: {current_url}" + + # Step 7: Verify authenticated content is present + # Check that we don't see login-related content anymore + page_content = page.content().lower() + login_keywords = ["sign in", "login", "authenticate"] + + # Should not see login form elements on authenticated page + has_login_content = any(keyword in page_content for keyword in login_keywords) + assert not has_login_content, "Login content still visible after successful authentication" + + # Step 8: Verify no error messages are displayed + # Look for common error message containers + error_selectors = [ + ".error", + ".alert-error", + ".bg-error", + "[class*='error']", + ".text-red", + "[class*='text-red']" + ] + + for error_selector in error_selectors: + error_elements = page.locator(error_selector) + if error_elements.count() > 0: + # If error elements exist, they should not be visible or should be empty + for i in range(error_elements.count()): + element = error_elements.nth(i) + if element.is_visible(): + element_text = element.inner_text().strip() + assert not element_text, f"Error message found after successful login: {element_text}" + + # Step 9: Verify the page has expected title + expect(page).to_have_title("My Managing Tools") + + print(f"✅ Successful login test completed - User {admin_user['email']} authenticated successfully")