Open lakshmanp21 opened 4 years ago
I think this is an issue with timing of beforeAll
/ beforeEach
and landing_page
getting called to declare your given
step. It would probably work better if you declare an object reference like scenarioContext
below, and then pass that object into your shared step. That way, you can create and destroy the properties of the top-level object as you like in your hooks, but the shared step will always have a reference to the top-level object that won't be changing.
The docs and examples need to be updated, since the currently recommended pattern can be problematic. Implementing #61 would be ideal, I suppose.
for (const browserType of BrowserTypes) {
defineFeature(feature, (test) => {
const scenarioContext = {};
beforeAll(async () => {
scenarioContext.browser = await playwright[browserType].launch({ headless: false }).catch((log: any) => console.log(log));
scenarioContext.page = await browser.newPage().catch((log: any) => console.log(log));
});
afterAll(() => {
// scenarioContext.browser.close().catch((log: any) => console.log(log))
});
afterEach(async () => {
// await scenarioContext.page.waitFor(3000)
});
beforeEach(async () => {
await scenarioContext.page.goto('xxxx.com/', {
waitUntil: 'networkidle0',
});
});
test('I can try common steps', async ({ given }) => {
landing_page(given, scenarioContext);
});
});
}
unable to identify the step_definition from shared file, calling the function in steps file @bencompton
@bencompton , tried the above example, didn't work. Any update or insight on this please ?
@lakshmanp21 you should check out cucumber-jest. it's a transformer for jest that allows you to use the cucumber api with jest. Because it's using the cucumber js api, it supports declaring step definitions once and they can be used in any feature file.
@lakshmanp21 you should check out cucumber-jest. it's a transformer for jest that allows you to use the cucumber api with jest. Because it's using the cucumber js api, it supports declaring step definitions once and they can be used in any feature file.
I am using cucumber-jest as suggested, though the issue (above) exists
"dependencies": { "allure-jasmine": "^2.0.0-beta.8", "allure-js-commons": "^2.0.0-beta.8", "codeceptjs": "^2.6.10", "jest": "^26.6.1", "jest-cucumber": "^3.0.0", "playwright": "1.4.0", "ts-jest": "^26.4.3", "typescript": "^3.9.7" }, "devDependencies": { "@fast-csv/parse": "^4.3.3", "@testing-library/jasmine-dom": "^1.1.0", "@types/faker": "^4.1.12", "@types/jest": "^26.0.15", "@types/node": "^14.14.6", "csv-writer": "^1.6.0", "faker": "^4.1.0", "jest-allure": "^0.1.3", "jest-allure2": "^1.2.3", "moment": "^2.28.0" }