playwright-bdd: TypeError: Cannot read properties of undefined (reading 'goto')
Hi, not sure if this is the right place but I am stuck. Can you please help with this ? I’m using the playwright-bdd 6.4.0 in my playwright.config.ts file.
//
My error:
TypeError: Cannot read properties of undefined (reading 'goto')
at ..\tests\steps\Homepage.steps.ts:5
3 |
4 | Given("Homepage: Navigate to LinkedIn website", async function () {
> 5 | await pageFixture.page.goto("https://linkedin.com");
| ^
6 | });
Why is my pageFixture undefined and how to fix it ?
Here is my code:
//pageFixture.ts:
import { Page } from '@playwright/test'
export const pageFixture = {
// @ts-ignore
page: undefined as Page
}
//hooks.ts:
import { Before, After } from "@cucumber/cucumber";
import { chromium, Browser, Page } from "@playwright/test";
import { pageFixture } from "./pageFixture";
let page: Page;
let browser: Browser;
Before(async function () {
browser = await chromium.launch();
page = await browser.newPage();
pageFixture.page = page;
});
After(async function () {
await pageFixture.page.close();
await browser.close();
});
//
//Homepage.steps.ts:
import { Given, When, Then } from "@cucumber/cucumber";
import { pageFixture } from "../hooks/pageFixture";
Given("Homepage: Navigate to LinkedIn website", async function () {
await pageFixture.page.goto("https://linkedin.com");
});
//playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
import { defineBddConfig } from 'playwright-bdd'
export default defineConfig({
timeout: 200000,
testDir: defineBddConfig({
paths: ['tests/features/*.feature'],
require: ['tests/steps/*.ts', 'tests/hooks/*.ts'],
tags: "@mytest",
}),
Thanks for helping, Silviu
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (10 by maintainers)
Yes here is my fixtures.ts
And it’s working. Thanks to you 🥇
Still I will try your apprach again as I’ve seen 6.4.0 is deprecated.