@qavajs/playwright-runner-adapter
v1.0.1
Published
adapter for playwright test runner
Downloads
266
Keywords
Readme
@qavajs/playwright-runner-adapter
Adapter to run cucumber tests via playwright test runner
Installation
npm install @qavajs/playwright-runner-adapter
Basic Configuration
Create cucumber config file
Set paths and require properties
export default {
paths: ['test/features/*.feature'],
require: ['test/step_definitions/*.ts']
}
Set testDir
Set testDir to adapter
import { defineCucumber } from '@qavajs/playwright-runner-adapter';
export default defineConfig({
testDir: defineCucumber({
config: 'test/cucumber.ts',
profile: 'default'
})
});
Advanced Configuration
Customizing test instance
Custom test instance can be passed to world constructor as test property. And then fixtures can be connected with world instance via init property.
import { test as base, expect as baseExpect } from '@playwright/test';
import { SettingsPage } from './settings-page';
import { setWorldConstructor } from '@cucumber/cucumber';
import { PlaywrightWorld } from '@qavajs/playwright-runner-adapter/PlaywrightWorld';
type MyFixtures = {
settingsPage: SettingsPage;
};
const customTest = base.extend<MyFixtures>({
settingsPage: async ({ page }, use) => {
await use(new SettingsPage(page));
},
});
const customExpect = baseExpect.extend({
async customMatcher() {
// implementation
}
});
class ExtendedPlaywrightWorld extends PlaywrightWorld {
settingsPage: SettingsPage;
constructor(options: any) {
super(options);
}
// set test property with extened one
test = customTest;
expect = customExpect;
// init arrow function connects fixtures with Cucumber world instance
init = ({ settingsPage }) => {
this.settingsPage = settingsPage;
}
}
Limitation
- ES modules are not supported (at least for node <= 22, where experimental ESM require is introduced)