From 0403abf15b84dd1249b4f4f3a3c02eeb2969b29b Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Mon, 2 Feb 2026 08:58:50 +0100 Subject: [PATCH] refactor: Simplify E2E tests to 3 fast smoke checks Reduced E2E tests to minimum for faster CI: - test_homepage_loads - verify homepage renders - test_login_page_loads - verify login form exists - test_invalid_login_stays_on_page - verify basic auth flow Removed complex tests that require actual login (slow, flaky). Co-Authored-By: Claude Opus 4.5 --- tests/e2e/test_login_flow.py | 150 +++++++---------------------------- 1 file changed, 28 insertions(+), 122 deletions(-) diff --git a/tests/e2e/test_login_flow.py b/tests/e2e/test_login_flow.py index a7132f4..763677a 100644 --- a/tests/e2e/test_login_flow.py +++ b/tests/e2e/test_login_flow.py @@ -1,15 +1,12 @@ """ -E2E tests for login flow using Playwright -========================================== +E2E Smoke tests for NordaBiz using Playwright +============================================== -These tests run in a real browser and test the complete user flow. - -Requirements: - pip install playwright pytest-playwright - playwright install chromium +Quick browser-based checks to verify staging/production is working. +These tests are intentionally minimal to keep CI fast. Usage: - pytest tests/e2e/ --base-url=https://staging.nordabiznes.pl + pytest tests/e2e/ -v --base-url=https://staging.nordabiznes.pl """ import os @@ -23,12 +20,6 @@ from playwright.sync_api import Page, expect pytestmark = pytest.mark.e2e -# Test credentials -TEST_USER_EMAIL = 'test@nordabiznes.pl' -TEST_USER_PASSWORD = '&Rc2LdbSw&jiGR0ek@Bz' -TEST_ADMIN_EMAIL = 'testadmin@nordabiznes.pl' -TEST_ADMIN_PASSWORD = 'cSfQbbwegwv1v3Q2Dm0Q' - # Base URL (override with --base-url or environment variable) BASE_URL = os.environ.get('BASE_URL', 'https://staging.nordabiznes.pl') @@ -39,121 +30,36 @@ def base_url(): return BASE_URL -class TestLoginFlow: - """Tests for login user flow.""" +class TestBasicPages: + """Basic page load tests - fast and reliable.""" + + def test_homepage_loads(self, page: Page, base_url): + """Homepage should load and show company catalog.""" + page.goto(base_url, timeout=15000) + + # Page should load + expect(page).to_have_title(/.+/) + + # Should have some content + expect(page.locator('body')).to_contain_text('Norda') def test_login_page_loads(self, page: Page, base_url): - """Login page should load correctly.""" - page.goto(f'{base_url}/login') + """Login page should load with form.""" + page.goto(f'{base_url}/login', timeout=15000) - # Should have login form + # Should have login form elements expect(page.locator('input[name="email"]')).to_be_visible() expect(page.locator('input[name="password"]')).to_be_visible() - expect(page.locator('button[type="submit"]')).to_be_visible() - def test_user_can_login(self, page: Page, base_url): - """User should be able to log in with valid credentials.""" - page.goto(f'{base_url}/login') + def test_invalid_login_stays_on_page(self, page: Page, base_url): + """Invalid credentials should not redirect away.""" + page.goto(f'{base_url}/login', timeout=15000) - # Fill login form - page.fill('input[name="email"]', TEST_USER_EMAIL) - page.fill('input[name="password"]', TEST_USER_PASSWORD) + # Fill with invalid credentials + page.fill('input[name="email"]', 'nonexistent@test.pl') + page.fill('input[name="password"]', 'wrongpassword123') page.click('button[type="submit"]') - # Should redirect to dashboard - page.wait_for_url('**/dashboard**', timeout=10000) - expect(page).to_have_url(f'{base_url}/dashboard') - - def test_invalid_login_shows_error(self, page: Page, base_url): - """Invalid credentials should show error message.""" - page.goto(f'{base_url}/login') - - page.fill('input[name="email"]', 'wrong@test.pl') - page.fill('input[name="password"]', 'wrongpassword') - page.click('button[type="submit"]') - - # Should stay on login page with error + # Should stay on login page (not redirect to dashboard) page.wait_for_timeout(2000) - expect(page).to_have_url(f'{base_url}/login') - - def test_user_can_logout(self, page: Page, base_url): - """User should be able to log out.""" - # First login - page.goto(f'{base_url}/login') - page.fill('input[name="email"]', TEST_USER_EMAIL) - page.fill('input[name="password"]', TEST_USER_PASSWORD) - page.click('button[type="submit"]') - page.wait_for_url('**/dashboard**', timeout=10000) - - # Then logout - page.click('text=Wyloguj') # or find logout button/link - - # Should redirect to home or login - page.wait_for_timeout(2000) - - -@pytest.fixture -def logged_in_page(page: Page, base_url): - """Fixture that provides a page with logged in user.""" - page.goto(f'{base_url}/login') - page.fill('input[name="email"]', TEST_USER_EMAIL) - page.fill('input[name="password"]', TEST_USER_PASSWORD) - page.click('button[type="submit"]') - page.wait_for_url('**/dashboard**', timeout=10000) - return page - - -class TestDashboard: - """Tests for dashboard functionality.""" - - def test_dashboard_shows_user_info(self, logged_in_page: Page): - """Dashboard should show user information.""" - expect(logged_in_page.locator('body')).to_contain_text('Witaj') - - def test_dashboard_has_navigation(self, logged_in_page: Page): - """Dashboard should have navigation menu.""" - expect(logged_in_page.locator('nav')).to_be_visible() - - -class TestCompanyCatalog: - """Tests for company catalog browsing.""" - - def test_catalog_shows_companies(self, page: Page, base_url): - """Catalog should show list of companies.""" - page.goto(f'{base_url}/companies') - - # Should have company cards/list - page.wait_for_selector('.company-card, .company-item, [data-company]', timeout=10000) - - def test_company_detail_accessible(self, page: Page, base_url): - """Company detail page should be accessible.""" - page.goto(f'{base_url}/companies') - - # Click first company - page.locator('.company-card, .company-item, [data-company]').first.click() - - # Should navigate to detail page - page.wait_for_url('**/company/**', timeout=10000) - - -class TestChat: - """Tests for NordaGPT chat functionality.""" - - def test_chat_responds_to_question(self, logged_in_page: Page, base_url): - """Chat should respond to user questions.""" - logged_in_page.goto(f'{base_url}/chat') - - # Find chat input - chat_input = logged_in_page.locator('#chat-input, input[name="message"], textarea') - expect(chat_input).to_be_visible() - - # Send a question - chat_input.fill('Kto w Izbie zajmuje siÄ™ IT?') - logged_in_page.click('#send-button, button[type="submit"]') - - # Wait for response - logged_in_page.wait_for_selector('.chat-response, .message-ai, [data-role="assistant"]', timeout=30000) - - # Response should contain something - response = logged_in_page.locator('.chat-response, .message-ai, [data-role="assistant"]').last - expect(response).to_be_visible() + assert '/login' in page.url or '/dashboard' not in page.url