|
| 1 | +import { Given, Then, When } from "@cucumber/cucumber"; |
| 2 | +import { expect } from "@playwright/test"; |
| 3 | +import type { PlaywrightWorld } from "../support/world"; |
| 4 | + |
| 5 | +Given("I am on {string}", async function (this: PlaywrightWorld, path: string) { |
| 6 | + await this.page.goto(`${this.baseUrl}${path}`); |
| 7 | +}); |
| 8 | + |
| 9 | +When( |
| 10 | + "I click the {string} button", |
| 11 | + async function (this: PlaywrightWorld, label: string) { |
| 12 | + await this.page.getByRole("button", { name: label }).click(); |
| 13 | + }, |
| 14 | +); |
| 15 | + |
| 16 | +Then( |
| 17 | + "I should see the text {string}", |
| 18 | + async function (this: PlaywrightWorld, text: string) { |
| 19 | + await expect(this.page.getByText(text)).toBeVisible(); |
| 20 | + }, |
| 21 | +); |
| 22 | + |
| 23 | +Then( |
| 24 | + "I should see a heading {string}", |
| 25 | + async function (this: PlaywrightWorld, heading: string) { |
| 26 | + await expect( |
| 27 | + this.page.getByRole("heading", { name: heading }), |
| 28 | + ).toBeVisible(); |
| 29 | + }, |
| 30 | +); |
| 31 | + |
| 32 | +Then( |
| 33 | + "I should be on {string}", |
| 34 | + async function (this: PlaywrightWorld, path: string) { |
| 35 | + await expect(this.page).toHaveURL( |
| 36 | + new RegExp( |
| 37 | + `${this.baseUrl}${path.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")}$`, |
| 38 | + ), |
| 39 | + ); |
| 40 | + }, |
| 41 | +); |
0 commit comments