Skip to main content
Version: 9.0.0

CTX

The controller method ctx allows you to store information and to have it carried with Test Maker controller. Let's use some example to demonstrate how it can be used.

Usage example

        I.ctx.a = 0;
console.log(I.ctx.a); //will print out 0

Example with dynamic steps

Model file where I create a dynamic step.

import { When, I } from "test-maker";
let sharedTestStep;

export class DemoAppModel {

capturePersonalInfo() {

sharedTestStep = When(`the user provides the Personal Information`, async (I) => {
let currentCustomer = I.ctx.currentCustomer
console.log(currentCustomer)
await I.fillField('#FirstName',currentCustomer.FirstName);

return sharedTestStep;
}


}

export const demoApp = new DemoAppModel();

Spec file where the step will be used


import {Feature} from "test-maker";
import { demoApp } from "../../model/demo-app-model";

Feature(`Demo`)
.Scenario(`Collect details information form`)
.Given("The user is logged in", async (I, runInfo) => {
I.ctx.currentCustomer = {
"FirstName": "RandomName",
}
})
.dynamicSteps([
demoApp.capturePersonalInfo(),
])


This how you are able to use external values with your dynamic steps.