Puppetry
3.2.2
3.2.2
  • Welcome Puppetry
  • Getting Started
  • Project
  • Suite
  • Group
  • Target
    • Simple Target
    • iFrame Target
    • ShadowDOM Target
    • Chained Target
    • Shared Target
  • Test Case
  • Test Step / Action
    • Page Commands
    • Page Assertions
    • Target Commands
    • Target Assertions
  • Managing Records
  • Snippets
  • Running tests
    • Interactive Mode
    • Troubleshooting
  • Test Report
  • Export
    • Exporting as Jest Project (CI-friendly)
    • Exporting as Test Specification
  • Settings
  • Template Expressions
  • Testing Techniques
    • Testing Dynamic Content
    • Exhaustive Testing
    • Performance Testing
    • Visual Regression Testing
    • Testing Shadow DOM
    • Testing Google Analytics tracking code
    • Testing Chrome Extensions
    • Testing REST API
    • Mocking HTTP/S Requests
    • Testing Transactional Emails
      • Example with Restmail.net
      • Example with Mailinator
      • Example with IMAP bridge
      • Example with Google API
    • Testing Forms with Captcha
  • Version Control
  • Tips and Tricks
    • Embrace the Power of CSS
  • Command API
  • Test Application
Powered by GitBook
On this page
  • Template variables
  • Managing Variables
  • Template Syntax
  • Template Expressions
  • Environment Variables
  • Counter
  • Uniqid
  • Iterate
  • Random
  • HtmlOf
  • AttributeOf
  • PropertyOf
  • Faker
  • Eval

Was this helpful?

Template Expressions

PreviousSettingsNextTesting Techniques

Last updated 3 years ago

Was this helpful?

Many of command/assertion parameters accept templates. So you can use template variables and expressions. For example, page.goto("https://github.com/{{ USER }}/puppetry/") or TARGET.type("name{{ counter() }}")

Template variables

By using Settings/Template Variables panel we can define a set of variables per environment. For an instance, we can declare a separate target app URL for every environment (test.acme.com, stage.acme.com, www.acme.com). Before running/exporting test project we specify the desired environment and the corresponding template tags will be replaced with the value (URL) given for that environment.

Managing Variables

To edit template variables click on Project/Template variables in the main menu:

Under the table Template variables you will find a manageable table with variables (by default it's empty):

You can use this UI the same way to do with targets, suits, and test cases. The difference is that the displayed variables belong to the selected environment:

As you add a new variable let's say to test environment it appears in all available environments. But when you update it's value, the value stays unique per environment.

Also note the edit action link next to the environment selector. When you click it you get a modal window where you can manage the list of environments:

After we assigned the variables and running the tests (or exporting them for CI) in the modal window we can choose what environment we target:

Template Syntax

Syntax

{{ VARIABLE_NAME }}

The tag makes Puppetry injecting the variable value assigned for the selected environment into the container string

Examples

{{ BASE_URL }}/api/{{ API_VERSION }}/method

Template Expressions

Template expressions are basically functions that we may want to use for building template string.

Test step parameters supporting templates provided with a helper widget, which you can you to autofill the field:

Environment Variables

Syntax

{{ env( NAME ) }}

Examples

{{ env( "SECRET" ) }}

Counter

Syntax

{{ counter() }}

Function increments every time it called, but is unique per command/assertion

Examples

joe.{{ counter() }}@acme.com

This template resolves in email addresses joe.1@acme.com, joe.2@acme.com and so on

Uniqid

Syntax

{{ uniqid() }}

Function generates a unique id like 8fzk2g5fpkb

Examples

{{ uniqid() }}

Iterate

Syntax

{{ iterate( LIST ) }}

Function iterates through a given list. It starts from the beginning as it reaches the end

Examples

{{ iterate(["sansas@got.com", "yarag@got.com", "gendryb@got.com"]) }}

This template resolves in sansas@got.com, yarag@got.com, gendryb@got.com, sansas@got.com, ...

Random

Syntax

{{ random( LIST ) }}

Function picks a random value out of a given list.

Examples

{{ random(["sansas@got.com", "yarag@got.com", "gendryb@got.com"]) }}

HtmlOf

Syntax

{{ htmlOf( TARGET ) }}

Function extracts content (innerHTML) of a given TARGET.

Examples

{{ htmlOf("FOO") }}

AttributeOf

Syntax

{{ attributeOf( TARGET, ATTRIBUTE_NAME ) }}

Function retrieve attribute value of a given TARGET.

Examples

{{ attributeOf("FOO", "href") }}

PropertyOf

Syntax

{{ propertyOf( TARGET, PROPERTY_NAME ) }}

Function retrieve property value of a given TARGET.

Examples

{{ propertyOf("FOO", "checked") }}

Faker

Syntax

{{ fake( FAKER_METHOD, LOCALE ) }}

Examples

 {{ faker("address.streetSuffix", "en_GB") }}

Eval

Syntax

{{ eval( "JavaScript code" ) }}

Function injects the given JavaScript into the suite code forming the string.

Examples

{{ eval("process.cwd()") }}

resolves into

`${ process.cwd() }`

Quotation marks in the JavaScript code have to be escaped.

Template variables can be also assigned dynamically. E.g. you can use page.assignVar to define a variable by using expressions or page.assignVarRemotely to define a variable by using REST API ().

Function returns system by a given name

Function generates dummy data, by using

NPM modules "fs", "path" and "os" as well as Command API () are available for evaluation.

learn more
environment variable
Faker.js methods
https://docs.puppetry.app/command-api
Template variables in the Project menu
Template variables panel
Selecting destination environment
Editing environments
Destinating test run for a given environment
Template helper widget