@wernerthiago/teo
Version:
Test Execution Optimizer
53 lines (42 loc) • 2 kB
JavaScript
// Authentication tests
import { test, expect } from '@playwright/test'
test.describe('Authentication', () => {
test('should login with valid credentials', async ({ page }) => {
await page.goto('/login')
await page.fill('[data-testid="username"]', 'testuser')
await page.fill('[data-testid="password"]', 'password123')
await page.click('[data-testid="login-button"]')
await expect(page).toHaveURL('/dashboard')
await expect(page.locator('[data-testid="welcome-message"]')).toBeVisible()
})
test('should show error for invalid credentials', async ({ page }) => {
await page.goto('/login')
await page.fill('[data-testid="username"]', 'invalid')
await page.fill('[data-testid="password"]', 'wrong')
await page.click('[data-testid="login-button"]')
await expect(page.locator('[data-testid="error-message"]')).toBeVisible()
await expect(page.locator('[data-testid="error-message"]')).toContainText('Invalid credentials')
})
test('should handle account lockout after failed attempts', async ({ page }) => {
await page.goto('/login')
// Simulate multiple failed attempts
for (let i = 0; i < 3; i++) {
await page.fill('[data-testid="username"]', 'testuser')
await page.fill('[data-testid="password"]', 'wrong')
await page.click('[data-testid="login-button"]')
await page.waitForTimeout(1000)
}
await expect(page.locator('[data-testid="lockout-message"]')).toBeVisible()
await expect(page.locator('[data-testid="lockout-message"]')).toContainText('Account locked')
})
test('should logout successfully', async ({ page }) => {
// Login first
await page.goto('/login')
await page.fill('[data-testid="username"]', 'testuser')
await page.fill('[data-testid="password"]', 'password123')
await page.click('[data-testid="login-button"]')
// Then logout
await page.click('[data-testid="logout-button"]')
await expect(page).toHaveURL('/login')
})
})