diff --git a/features/homepage.feature b/features/homepage.feature deleted file mode 100644 index baef5a9..0000000 --- a/features/homepage.feature +++ /dev/null @@ -1,10 +0,0 @@ -Feature: Home Page - - Scenario: Check title - Given I am on home page - Then I see in title "Playwright" - - Scenario: Check get started - Given I am on home page - When I click link "Get started" - Then I see in title "Installation" \ No newline at end of file diff --git a/features/todopage.feature b/features/todopage.feature index ca89b5f..2866c07 100644 --- a/features/todopage.feature +++ b/features/todopage.feature @@ -1,21 +1,33 @@ -@todo -Feature: Todo Page +Feature: Todo List Management - Background: - Given I am on todo page + Background: + Given I am on the Todo page - Scenario: Empty list - Then visible todos count is 0 - And page screenshot matches previous one + Scenario: Create a new todo item + When I create a new todo item with text "Buy groceries" + Then I should see the following todo items: + | Buy groceries | - Scenario: Add todos - When I add todo "foo" - And I add todo "bar" - Then visible todos count is 2 + Scenario: Complete a todo item + When I create a new todo item with text "Read a book" + And I complete the todo item with text "Read a book" + Then I should see the following todo items: + | Read a book | - Scenario: Complete todos - When I add todo "foo" - And I add todo "bar" - And I complete todo "bar" - And I filter todos as "Completed" - Then visible todos count is 1 + Scenario: Filter completed items + When I create a new todo item with text "Walk the dog" + And I create a new todo item with text "Water the plants" + And I complete the todo item with text "Walk the dog" + And I filter to see only completed items + Then I should see the following todo items: + | Walk the dog | + + Scenario: Filter completed items with multiple completed items + When I create a new todo item with text "Go for a run" + And I create a new todo item with text "Write code" + And I complete the todo item with text "Go for a run" + And I complete the todo item with text "Write code" + And I filter to see only completed items + Then I should see the following todo items: + | Go for a run | + | Write code | diff --git a/package.json b/package.json index 54c023d..e1e55ba 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "watch:pw": "playwright test --ui", "watch": "run-p watch:*", "report": "npx playwright show-report", - "steps": "npx bddgen export" + "export": "npx bddgen export" }, "devDependencies": { "nodemon": "^3.0.1", diff --git a/playwright.config.ts b/playwright.config.ts index cc94581..918eb45 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,29 +1,12 @@ -import { defineConfig, devices } from '@playwright/test'; +import { defineConfig } from '@playwright/test'; import { defineBddConfig } from 'playwright-bdd'; const testDir = defineBddConfig({ + paths: ['./features/todopage.feature'], importTestFrom: 'steps/fixtures.ts', - paths: ['./features'], - require: ['steps/*.ts'], - quotes: 'backtick', - featuresRoot: './features', }); export default defineConfig({ testDir, reporter: 'html', - use: { - screenshot: 'only-on-failure', - baseURL: 'http://localhost:3000', - }, - projects: [ - { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, - }, - { - name: 'firefox', - use: { ...devices['Desktop Firefox'] }, - }, - ] }); diff --git a/steps/TodoPage.ts b/steps/TodoPage.ts index 2b09ef5..3b67e9d 100644 --- a/steps/TodoPage.ts +++ b/steps/TodoPage.ts @@ -1,49 +1,37 @@ -import { Locator, Page, expect } from '@playwright/test'; -import { Fixture, Given, When, Then } from 'playwright-bdd/decorators'; -import type { test } from './fixtures'; +import { Page, expect } from '@playwright/test'; +import { Given, When, Then, Fixture } from 'playwright-bdd/decorators'; +import { DataTable } from '@cucumber/cucumber'; -export -@Fixture('todoPage') -class TodoPage { - readonly inputBox: Locator; - readonly todoItems: Locator; +export @Fixture('todoPage') class TodoPage { + private page: Page; - constructor(public page: Page) { - this.inputBox = this.page.locator('input.new-todo'); - this.todoItems = this.page.getByTestId('todo-item'); + constructor(page: Page) { + this.page = page; } - @Given('I am on todo page') - async open() { - await this.page.goto('https://demo.playwright.dev/todomvc/'); + @Given('I am on the Todo page') + async navigateToTodoPage() { + await this.page.goto('https://demo.playwright.dev/todomvc/#/'); } - @When('I add todo {string}') - async addToDo(text: string) { - await this.inputBox.fill(text); - await this.inputBox.press('Enter'); + @When('I create a new todo item with text {string}') + async createTodoItem(text: string) { + await this.page.getByPlaceholder('What needs to be done?').fill(text); + await this.page.getByPlaceholder('What needs to be done?').press('Enter'); } - @When('I complete todo {string}') - async completeTodo(hasText: string) { - const checkbox = this.todoItems.filter({ hasText }).getByRole('checkbox'); - if (!await checkbox.isChecked()) { - await checkbox.click(); - } + @When('I complete the todo item with text {string}') + async completeTodoItem(text: string) { + await this.page.getByTestId('todo-item').filter({ hasText: text }).getByLabel('Toggle Todo').check(); } - @When(/I filter todos as "(All|Completed)"/) - async filterTodos(name: 'All' | 'Completed') { - await this.page.getByRole('link', { name }).click(); + @When('I filter to see only completed items') + async filterCompletedItems() { + await this.page.getByRole('link', { name: 'Completed' }).click(); } - @Then('visible todos count is {int}') - async checkVisibleTodosCount(count: number) { - await expect(this.todoItems).toHaveCount(count); + @Then('I should see the following todo items:') + async verifyTodoItemsVisible(itemList: DataTable) { + await expect(this.page.getByTestId('todo-title')).toHaveText(itemList.raw().flat()); } - - @Then('page screenshot matches previous one') - async matchScreenshot() { - await expect(this.page).toHaveScreenshot(); - } -} +} \ No newline at end of file diff --git a/steps/index.ts b/steps/index.ts deleted file mode 100644 index 9b48f6c..0000000 --- a/steps/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { expect } from '@playwright/test'; -import { createBdd } from 'playwright-bdd'; -import { test } from './fixtures'; - -const { Given, When, Then } = createBdd(test); - -Given('I am on home page', async ({ page }) => { - await page.goto('https://playwright.dev'); -}); - -When('I click link {string}', async ({ page }, name: string) => { - await page.getByRole('link', { name }).click(); -}); - -Then('I see in title {string}', async ({ page }, text: string) => { - await expect(page).toHaveTitle(new RegExp(text)); -});