Open thienphuong opened 11 months ago
import { test, expect, type Page } from '@playwright/test'; // pure playwright
--> import { describe, it } from '@serenity-js/playwright-test' // playwright is wrapper by serenityJS
// Junit5: @BeforeEach
test.beforeEach(async ({ page }) => {
await page.goto('https://demo.playwright.dev/todomvc');
});
const TODO_ITEMS = [
'buy some cheese',
'feed the cat',
'book a doctors appointment'
];
.....
// One or more nested:
test.describe('Mark all as completed', () => {
test.beforeEach(async ({ page }) => {
await createDefaultTodos(page);
await checkNumberOfTodosInLocalStorage(page, 3);
});
test.afterEach(async ({ page }) => {
await checkNumberOfTodosInLocalStorage(page, 3);
});
// @Test - serenityJS syntax
it('ishould allow me to mark all items as completed', async ({ actor }) => {
await actor.attemptsTo(
Send.a(GetRequest.to('/todos/1')),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body<TodoItem>().id, equals(1)),
);
});
// @Test: playwright syntax
test('should allow me to mark all items as completed', async ({ page }) => {
// Complete all todos.
await page.getByLabel('Mark all as complete').check();
// Ensure all todos have 'completed' class.
await expect(page.getByTestId('todo-item')).toHaveClass(['completed', 'completed', 'completed']);
await checkNumberOfCompletedTodosInLocalStorage(page, 3);
});
});
1/ Import a package, class or interface
TypeScript
Java