We recommend using a coding agent with Playmatic’s configuration to speed up test creation.
Test structure
Playmatic tests are written using natural language and code. This gives you control in the speed and flexibility of self-healing at runtime. Every test starts with a goal, can be configured to run in different environments, and is broken down into test steps. Each test step is always written in natural language, and you can optionally add a cache function using Playwright compatible code to speed up execution and force determinism.Playwright is included with the Playmatic SDK, so you don’t need to install it separately to use the cache functions.
The test()
function
Test Goal
Each Playmatic test starts with a goal that is described as the first parameter in thetest()
function. This goal is used to capture the intent behind the test and is used during self-healing and maintenance when tests fail.
A good test goal will read like a user story that clearly states what success looks like. It should include the core verification and the high level flow that is used to reach the verification.
test
goal along with the natural language descriptor in the testStep
and the visual interface to make determinations about test failures and recovery.
Test Environment (env)
For flexibility, each test can be configured to run inside a test environment. Each environment has a unique name, a base URL, and variables that can be accessed at any time inside a test. These test environments are configured in theplaymatic.config.ts
file and can be selected at run-time.
playmatic.config.ts
env
object. The baseURL can be referenced via env.baseUrl
, and any variables can be referenced using env.vars.variableName
.
The testStep()
function
The basis of each Playmatic test is a testStep
. Each testStep
has three parameters: a step intent, an optional cache function, and optional configuration options.
Step intent
The first parameter is a natural language description that captures the user action or intent. This description is used for self-healing when the cache function fails.testStep("click the submit button")
will be self-healing even if the selector drifts or the UI changes. However, testStep("click the blue submit button on the right sidebar")
will not.
We recommend the following best practices for writing natural language steps:
- Be specific but natural: “Click the submit button” vs “Click the blue button on the right.”
- Describe the purpose: Reference elements by their purpose and not just their appearance
- Break down complex actions: Split multi-step operations into multiple steps that are path deterministic
Cache function
The second parameter is an optional execution function that provides cache functionality to improve speed and accuracy. The cache function is Playwright compatible - Playwright is included with the Playmatic SDK, so you can use any Playwright functions without additional installation.async () => {...}
is always executed first. If the code executes successfully, the computer-use agent will not be invoked at runtime. Whenever the code execution fails, the computer-use agent will be invoked for self-healing.
Cache functions are great for actions that have stable selectors to improve speed.
We recommend adding a cache function to every action where you believe there is a stable selector.
Parameters of the cache function
The cache function receives a destructured object with these parameters:page
- Playwright Page objectbrowser
- Playwright Browser objectcontext
- Playwright BrowserContext object
Test step options
The third parameter is an optional configuration object for testStep behavior:cacheOnly
Use{ cacheOnly: true }
when you want to disable self-healing for a specific step. If you do not want to use the computer-use agent for a cache function at run time, you can toggle it off with this parameter.