Skip to main content
Version: 9.0.0

Dynamic steps

In order to optimize your code and to facilitate code abstraction, Test Maker allows you to abstract whole steps to be reused across your project.

Her is an example of dynamic steps:

import {Controller, Given, Scenario, Then, When} from "test-maker";
let counter = 0;

let data = {
args:``
}

export function getSharedGiven(data:any){
return Given(`My dynamic GIVEN step is executed successfully`, async(I:Controller) => {
counter++;
await I.click(data.args)
})
}

export const sharedGivenStep = Given(`My dynamic GIVEN step is executed successfully`, async() => {
counter++;
})

export const sharedWhenStep = When(`My dynamic WHEN step is executed successfully`, async() => {
counter++;
})

export const sharedThenStep = Then(`My dynamic THEN step is executed successfully`, async(I:Controller) => {
await I.expect(counter).toEqual(2);
})

export const sharedScenario = {scenario: Scenario(`Shared Scenario Test`),
steps: [sharedGivenStep, getSharedGiven(data), sharedWhenStep, sharedThenStep]}
import {Controller, Feature, When} from 'test-maker';
import {getSharedGiven, sharedScenario} from "../../assets/test-data/shared-scenario-steps";

let counter = 0;

export const sharedScenarioStep = When(`My dynamic step is executed successfully`, async() => {
counter++;
})

Feature(`Example Feature`)
.Scenario(`Example Scenario`)
.Given(`Counter is increased by 1`, async () => {
counter++;
})
.dynamicSteps([sharedScenarioStep])

.Then(`The counter should be equal 2`, async (I: Controller) => {
await I.expect(counter).toEqual(2);
})
.dynamicScenariosWithSteps([sharedScenario])
.dynamicSteps([getSharedGiven(`a`)])