fix and add som usecases
This commit is contained in:
61
tests/test_login/test_login.py
Normal file
61
tests/test_login/test_login.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import pytest
|
||||
from page_objects.login_page import LoginPage
|
||||
from page_objects.home_page import HomePage
|
||||
|
||||
@pytest.mark.regression
|
||||
class TestLogin:
|
||||
"""
|
||||
Test suite for the Login page, covering authentication scenarios.
|
||||
"""
|
||||
|
||||
def test_successful_login(self, driver, base_url):
|
||||
"""
|
||||
Tests that a user can successfully log in with valid credentials
|
||||
and is redirected to the home page.
|
||||
"""
|
||||
login_page = LoginPage(driver)
|
||||
home_page = HomePage(driver)
|
||||
|
||||
login_page.open(base_url)
|
||||
|
||||
# Use the hardcoded credentials from auth.tsx
|
||||
login_page.login("poop@shenjianl.cn", "shenjianZ")
|
||||
|
||||
# Explicitly wait for the URL to change to '/home'
|
||||
login_page.wait_for_url_contains("/home")
|
||||
|
||||
# Assert against the hardcoded user name
|
||||
welcome_message = home_page.get_welcome_message()
|
||||
assert "Welcome, Test User!" in welcome_message, \
|
||||
f"Welcome message was '{welcome_message}', but expected it to contain 'Welcome, Test User!'."
|
||||
|
||||
@pytest.mark.smoke
|
||||
@pytest.mark.parametrize("email, password, expected_error", [
|
||||
("user@example.com", "wrongpassword", "Invalid email or password"),
|
||||
("wronguser@example.com", "password123", "Invalid email or password"),
|
||||
])
|
||||
def test_login_with_invalid_credentials(self, driver, base_url, email, password, expected_error):
|
||||
"""
|
||||
Tests that login fails with various invalid credentials and the correct
|
||||
error message is displayed.
|
||||
"""
|
||||
login_page = LoginPage(driver)
|
||||
login_page.open(base_url)
|
||||
|
||||
login_page.login(email, password)
|
||||
|
||||
assert expected_error in login_page.get_error_message()
|
||||
assert "login" in driver.current_url
|
||||
|
||||
def test_accessing_protected_route_redirects_to_login(self, driver, base_url):
|
||||
"""
|
||||
Tests that attempting to access a protected page (e.g., /home) without
|
||||
being logged in redirects the user to the login page.
|
||||
"""
|
||||
login_page = LoginPage(driver)
|
||||
|
||||
home_url = base_url.rstrip('/') + "/home"
|
||||
driver.get(home_url)
|
||||
|
||||
assert "login" in driver.current_url
|
||||
assert login_page.is_login_form_visible(), "Login form should be visible after redirect"
|
||||
Reference in New Issue
Block a user