Skip to content

minimal reproduction of issue https://github.com/vitalets/playwright-bdd/issues/163 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions steps/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test as base } from 'playwright-bdd';
import { MyFixture} from "./my-fixture";

export const test = base.extend({
// add your fixtures here
});
export const test = base.extend<{ myFixture: MyFixture}>({
myFixture: async ({ page }, use) => await use(new MyFixture(page)),
});
3 changes: 2 additions & 1 deletion steps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { test } from './fixtures';

const { Given, When, Then } = createBdd(test);

Given('I am on Playwright home page', async ({ page }) => {
Given('I am on Playwright home page', async ({ page, myFixture }) => {
await page.goto('https://playwright.dev');
await myFixture.page.goto('https://playwright.dev');
});

When('I click link {string}', async ({ page }, name: string) => {
Expand Down
8 changes: 8 additions & 0 deletions steps/my-fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Page } from "@playwright/test";

export class MyFixture {
public page: Page;
constructor(page: Page) {
this.page = page;
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "es2021",
"module": "commonjs",
"strict": true,
"strict": false,
"noEmit": true,
"useUnknownInCatchVariables": false,
"forceConsistentCasingInFileNames": true,
Expand Down