Skip to main content
Version: 9.0.0

Controller

What is the Controller ?

The controller(full api here) is the interface that sits between you and the Adapter used to run Actions you require for testing your Application. It is really the heart of your day to day writing of tests with Test Maker.

Basic Usage

Controller example :

  • Visiting Google page search page
  • Typing a search query
  • Execute the search query
 await I.goto(`https://google.com/`)
.fillField(`[name="q"]`, `knowledge expert`)
.pressEnterKey();

Example of importing the Controller directly in a help function and use that helper function in our Step in a feature.

project-folder/src/helpers/search-google.ts

import { I } from "test-maker";

export async function searchGoogle(searchQuery: string): Promise<void> {
await I.fillField(`[name="q"]`, searchQuery)
.pressEnterKey();
}

project-folder/src/specs/example-spec.ts

 .When(`We Search For Query`, async (I) => {
const firstResult = Selector(`h3`).withText(`Knowledge Expert - Digital Transformation`);

await I.expect(firstResult.innerText).toEqual(`Knowledge Expert - Digital Transformation`);
})
Feature(`Example Feature`)
.adapters(['unit'])
.Scenario(`Example Scenario`)
.Given(`We Visit google search page`, async (I: Controller) => {
await I.goto(`https://google.com/`);

//uncomment the code below if from your location google shows a popup asking for user's consent for data and cookies
const dialogModal = Selector(`button[id="L2AGLb"]`, { timeout: 2000 });
if (await dialogModal.exists) {
await I.focus(dialogModal);
await I.pressEnterKey();
}
})
.When(`We Search For Query`, async (I: Controller) => {
await I.fillField(`[name="q"]`, `knowledge expert`)
.pressEnterKey();
})
.Then(`We Get result`, async (I: Controller) => {

const firstResult = Selector(`h3`).withText(`Knowledge Expert - Digital Transformation`);

await I.expect(firstResult.innerText).toEqual(`Knowledge Expert - Digital Transformation`);

});