refactoring integration tests
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import pytest
|
||||
from playwright.sync_api import Page, expect
|
||||
|
||||
from e2e.e2e_constants import Login
|
||||
from e2e.e2e_helper import locate, fill, debug, check_not_in_content
|
||||
from playwright_config import BASE_URL
|
||||
|
||||
|
||||
@@ -149,63 +151,18 @@ class TestAuthentication:
|
||||
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']")
|
||||
email_input = locate(page, Login.email)
|
||||
password_input = locate(page, Login.password)
|
||||
submit_button = locate(page, Login.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()
|
||||
fill(email_input, admin_user["email"])
|
||||
fill(password_input, admin_user["password"])
|
||||
|
||||
# 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"
|
||||
debug(page, "after_login")
|
||||
check_not_in_content(page, ["sign in", "login", "authenticate"])
|
||||
|
||||
page.pause()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user