import pytest import asyncio from playwright.async_api import expect @pytest.mark.asyncio class TestBillingUserFlow: async def test_01_user_registration(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.click('text=Sign Up') await page.wait_for_timeout(500) await page.fill('#register-form input[name="username"]', 'billingtest') await page.fill('#register-form input[name="email"]', 'billingtest@example.com') await page.fill('#register-form input[name="password"]', 'password123') await page.click('#register-form button[type="submit"]') await page.wait_for_timeout(2000) await expect(page.locator('text=My Files')).to_be_visible() async def test_02_user_login(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.evaluate(""" navigator.serviceWorker.getRegistrations().then(function(registrations) { for(let registration of registrations) { registration.unregister(); } }); """) await page.reload() await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await expect(page.locator('text=My Files')).to_be_visible() async def test_03_navigate_to_billing_dashboard(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('billing-dashboard')).to_be_visible() async def test_04_view_current_usage(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('.usage-card')).to_be_visible() await expect(page.locator('text=Current Usage')).to_be_visible() await expect(page.locator('.usage-label:has-text("Storage")')).to_be_visible() await expect(page.locator('.usage-label:has-text("Bandwidth")')).to_be_visible() async def test_05_view_estimated_cost(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('.cost-card')).to_be_visible() await expect(page.locator('text=Estimated Monthly Cost')).to_be_visible() await expect(page.locator('.estimated-cost')).to_be_visible() cost_text = await page.locator('.estimated-cost').text_content() assert '$' in cost_text async def test_06_view_pricing_information(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('.pricing-card')).to_be_visible() await expect(page.locator('text=Current Pricing')).to_be_visible() await expect(page.locator('.pricing-item:has-text("Storage")')).to_be_visible() await expect(page.locator('.pricing-item:has-text("Bandwidth")')).to_be_visible() await expect(page.locator('.pricing-item:has-text("Free Tier")')).to_be_visible() async def test_07_view_invoice_history_empty(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('.invoices-section')).to_be_visible() await expect(page.locator('text=Recent Invoices')).to_be_visible() no_invoices = page.locator('.no-invoices') if await no_invoices.is_visible(): await expect(no_invoices).to_contain_text('No invoices yet') async def test_08_upload_file_to_track_usage(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.set_input_files('input[type="file"]', { 'name': 'test-file.txt', 'mimeType': 'text/plain', 'buffer': b'This is a test file for billing usage tracking.' }) await page.click('button:has-text("Upload")') await page.wait_for_timeout(2000) await expect(page.locator('text=test-file.txt')).to_be_visible() async def test_09_verify_usage_updated_after_upload(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(2000) storage_value = page.locator('.usage-item:has(.usage-label:has-text("Storage")) .usage-value') await expect(storage_value).to_be_visible() async def test_10_add_payment_method_button(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('.payment-methods-section')).to_be_visible() await expect(page.locator('text=Payment Methods')).to_be_visible() await expect(page.locator('#addPaymentMethod')).to_be_visible() async def test_11_click_add_payment_method(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) page.on('dialog', lambda dialog: dialog.accept()) await page.click('#addPaymentMethod') await page.wait_for_timeout(1000) async def test_12_view_subscription_status(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('.subscription-badge')).to_be_visible() badge_text = await page.locator('.subscription-badge').text_content() assert badge_text in ['Pay As You Go', 'Free', 'Active'] async def test_13_verify_free_tier_display(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('.usage-info:has-text("GB included free")')).to_be_visible() free_tier_info = await page.locator('.usage-info').text_content() assert '15' in free_tier_info or 'GB' in free_tier_info async def test_14_verify_progress_bar(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('.usage-progress')).to_be_visible() await expect(page.locator('.usage-progress-bar')).to_be_visible() async def test_15_verify_cost_breakdown(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'billingtest') await page.fill('#login-form input[name="password"]', 'password123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) await page.click('a.nav-link[data-view="billing"]') await page.wait_for_timeout(1000) await expect(page.locator('.cost-breakdown')).to_be_visible() await expect(page.locator('.cost-item:has-text("Storage")')).to_be_visible() await expect(page.locator('.cost-item:has-text("Bandwidth")')).to_be_visible()