Skip to content

takeScreenshot ​

Capture a screenshot and save it to the test output directory.

The takeScreenshot command saves a screenshot of the current screen as a PNG file.

Parameters ​

The takeScreenshot command accepts the path parameter:

ParameterDescription
pathThe filename for the screenshot, without the extension. May include subdirectories. See Artifact paths for info about where it's saved.
cropOnOptional. A selector to narrow the screenshot to just an element or container that you care about. Often used with assertScreenshot. For a complete list of all available selectors, see the Selectors documentation.
labelOptional. A message to display when executing the evaluation.

Usage examples ​

The following example saves a screenshot as LoginScreen.png.

yaml
- takeScreenshot:
    path: LoginScreen

This next example is the same login screen, but crops to the area containing the login controls

yaml
- takeScreenshot:
    path: LoginScreen
    cropOn:
      id: LoginFormContainer
    label: Take a screenshot of the login form

You can also use a shorthand syntax. The following example saves a screenshot as MainScreen.png.

yaml
- takeScreenshot: MainScreen

You can also group screenshots into subdirectories of the artifact folder.

yaml
- takeScreenshot:
    path: checkout/PaymentScreen

Artifact paths ​

Astra Scout writes this command's output into the takeScreenshot folder of the Flow's artifact bundle. See the run's artifacts folder in the report.

The path must name a file, and must not attempt to escape the artifacts folder. Astra Scout rejects the command with an Invalid path error (and will fail the flow) if the value:

  • names a directory rather than a file
  • climbs out of the command's output folder using .., such as ../escape
  • is an empty string, which happens when a variable in the path resolves to ""

An absolute path is allowed as long as it still points at the correct directory.

A variable that was never defined does not fail the command. It resolves to undefined, and the screenshot is silently written to undefined.png.

If the file cannot be written (e.g. full disk or read-only destination), the Flow fails with Cannot write takeScreenshot output to ....