Asynchronous Step Definitions
The callbacks for Feature
, Scenario
, Background
etc do not allow for async functions so this should be avoided:
Feature(async ({ Scenario }) => {
Scenario('', async () => {});
});
Steps however can be async or return a promise.
The following is allowed:
Feature(({ Scenario }) => {
Scenario('', ({ Given }) => {
Given('', async () => {
await someActionAsync();
});
});
});
With Promises
You can avoid making a callback async by simply returning a promise directly at the end of the step
Feature(({ Scenario }) => {
Scenario('', ({ Given }) => {
Given('', () => {
return someActionAsync();
});
});
});
You can also declare functions which can be used directly by the step
async function someAsyncFunction(){
const response = await HTTP.getThing('something')
const updated = modifyResponse(response);
return updated
}
Feature(({ Scenario }) => {
Scenario('', ({ Given }) => {
Given('', someActionAsyncFunction);
});
});