Skip to main content

Inline javascript

Steps and variable definition can call inline javascript, with the {{foo()}} syntax.

Inline javascript is limited to a single line of code and is ran in isolation (they don't have access to the test browser). If you need to run bigger code blocks, or if you need to run in the test session, use javascript steps.

Inline javascript can access the following library:

  • faker, a popular library to generate random data
  • SSN to generate random social security numbers

Examples:

  • Type text {{faker.internet.email()}} on the email field
  • Type text {{faker.person.firstName()}} on the first name input
  • Click on the {{faker.helpers.arrayElement(['Pr.', 'Dr.', 'Mr.'])}} button in the title section
  • Type text a variable: {{var1}} and another variable: {{var2}} on the input field
Localizing faker

By default, faker is localized to generate US data. You can also use any supported localized faker:

{{new FakerModule.Faker({ locale: [FakerModule.de_CH] }).phone.number()}}