Composing Steps
Custom Steps
qavajs is based on @cucumber/cucumber
package so you can use Given
, When
, Then
functions
enhanced by qavajs parameter types.
- JavaScript
- TypeScript
const { When } = require('@qavajs/core');
When('I select {value} option from {playwrightLocator}', async function(option, locator) {
await locator.selectOption(await option.value());
});
import { When } from '@qavajs/core';
import type { Locator } from '@playwright/test';
When('I select {value} option from {playwrightLocator}', async function(option: MemoryValue, locator: Locator) {
await locator.selectOption(await option.value());
});
executeStep
Framework provides capability to implement complex logic via executeStep
world method
that allow to call gherkin definitions programmatically
- JavaScript
- TypeScript
const { When, DataTable } = require('@qavajs/core');
When('I do smth complex', async function() {
await this.executeStep(`I type 'username' to 'Username Input'`);
await this.executeStep(`I type 'password' to 'Password Input'`);
await this.executeStep(`I click 'Login Button'`);
await this.executeStep(`I fill following fields`, new DataTable([
[ 'Order', '123' ],
[ 'Delivery Location', 'New York' ]
]));
});
import { IQavajsWorld, When, DataTable } from '@qavajs/core';
When('I do smth complex', async function(this: IQavajsWorld) {
await this.executeStep(`I type 'username' to 'Username Input'`);
await this.executeStep(`I type 'password' to 'Password Input'`);
await this.executeStep(`I click 'Login Button'`);
await this.executeStep(`I fill following fields`, new DataTable([
[ 'Order', '123' ],
[ 'Delivery Location', 'New York' ]
]));
});
Template
Template
provides a way to define step definition using Gherkin language
import { When, Template } from '@qavajs/core';
When('I click {string} and verify {string}', Template((locator, expected) => `
I click '${locator}'
I expect '${locator} > Value' to equal '${expected}'
`));