|
| 1 | +const { test, expect } = require('@playwright/test'); |
| 2 | + |
| 3 | +const DEMO_URL = 'https://demo.playwright.dev/todomvc'; |
| 4 | + |
| 5 | +test.describe('Assertion Basics', () => { |
| 6 | + test.beforeEach(async ({ page }) => { |
| 7 | + await page.goto(DEMO_URL); |
| 8 | + }); |
| 9 | + |
| 10 | + test('should assert page title', async ({ page }) => { |
| 11 | + await expect(page).toHaveTitle(/TodoMVC/); |
| 12 | + }); |
| 13 | + |
| 14 | + test('should assert element is visible', async ({ page }) => { |
| 15 | + await expect(page.locator('.new-todo')).toBeVisible(); |
| 16 | + }); |
| 17 | + |
| 18 | + test('should assert element has text', async ({ page }) => { |
| 19 | + await page.fill('.new-todo', 'Test Item'); |
| 20 | + await page.keyboard.press('Enter'); |
| 21 | + await expect(page.locator('.todo-list li')).toHaveText('Test Item'); |
| 22 | + }); |
| 23 | + |
| 24 | + test('should assert element count', async ({ page }) => { |
| 25 | + await page.fill('.new-todo', 'First'); |
| 26 | + await page.keyboard.press('Enter'); |
| 27 | + await page.fill('.new-todo', 'Second'); |
| 28 | + await page.keyboard.press('Enter'); |
| 29 | + await expect(page.locator('.todo-list li')).toHaveCount(2); |
| 30 | + }); |
| 31 | + |
| 32 | + test('should assert attribute value', async ({ page }) => { |
| 33 | + await expect(page.locator('.new-todo')).toHaveAttribute('placeholder', 'What needs to be done?'); |
| 34 | + }); |
| 35 | + |
| 36 | + test('should assert element is hidden', async ({ page }) => { |
| 37 | + await expect(page.locator('.footer')).toBeHidden(); // Footer is hidden until todos are added |
| 38 | + }); |
| 39 | +}); |
0 commit comments