Puppetry
Search…
Template Expressions
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:
Template variables in the Project menu
Under the table Template variables you will find a manageable table with variables (by default it's empty):
Template variables panel
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:
Selecting destination 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:
Editing 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:
Destinating test run for a given environment

Template Syntax

Syntax

1
{{ VARIABLE_NAME }}
Copied!
The tag makes Puppetry injecting the variable value assigned for the selected environment into the container string

Examples

1
{{ BASE_URL }}/api/{{ API_VERSION }}/method
Copied!
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 (learn more).

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:
Template helper widget

Environment Variables

Syntax

1
{{ env( NAME ) }}
Copied!
Function returns system environment variable by a given name

Examples

1
{{ env( "SECRET" ) }}
Copied!

Counter

Syntax

1
{{ counter() }}
Copied!
Function increments every time it called, but is unique per command/assertion

Examples

1
joe.{{ counter() }}@acme.com
Copied!
This template resolves in email addresses [email protected], [email protected] and so on

Uniqid

Syntax

1
{{ uniqid() }}
Copied!
Function generates a unique id like 8fzk2g5fpkb

Examples

1
{{ uniqid() }}
Copied!

Iterate

Syntax

1
{{ iterate( LIST ) }}
Copied!
Function iterates through a given list. It starts from the beginning as it reaches the end

Examples

Random

Syntax

1
{{ random( LIST ) }}
Copied!
Function picks a random value out of a given list.

Examples

HtmlOf

Syntax

1
{{ htmlOf( TARGET ) }}
Copied!
Function extracts content (innerHTML) of a given TARGET.

Examples

1
{{ htmlOf("FOO") }}
Copied!

AttributeOf

Syntax

1
{{ attributeOf( TARGET, ATTRIBUTE_NAME ) }}
Copied!
Function retrieve attribute value of a given TARGET.

Examples

1
{{ attributeOf("FOO", "href") }}
Copied!

PropertyOf

Syntax

1
{{ propertyOf( TARGET, PROPERTY_NAME ) }}
Copied!
Function retrieve property value of a given TARGET.

Examples

1
{{ propertyOf("FOO", "checked") }}
Copied!

Faker

Syntax

1
{{ fake( FAKER_METHOD, LOCALE ) }}
Copied!
Function generates dummy data, by using Faker.js methods

Examples

1
{{ faker("address.streetSuffix", "en_GB") }}
Copied!

Eval

Syntax

1
{{ eval( "JavaScript code" ) }}
Copied!
Function injects the given JavaScript into the suite code forming the string.

Examples

1
{{ eval("process.cwd()") }}
Copied!
resolves into
1
`${ process.cwd() }`
Copied!
NPM modules "fs", "path" and "os" as well as Command API (https://docs.puppetry.app/command-api) are available for evaluation.
Quotation marks in the JavaScript code have to be escaped.
Last modified 3mo ago