JavaScript returns true
Command value: assertEval
Runs JavaScript in the page and passes when it returns a truthy value.
Fields
| Field | JSON property | Description |
|---|---|---|
| JavaScript Code | value | Code that runs in the page. Use return to send a value back. |
Usage
- Use it for checks no other assertion covers, such as counts, attributes or computed styles.
- Use return to send the result back. Code without a return statement returns nothing, which fails the step.
Example step (JSON)
{
"command": "assertEval",
"value": "return document.querySelectorAll('.product').length >= 3;"
}Playwright equivalent
expect(await page.evaluate(() => {
return document.querySelectorAll('.product').length >= 3;
})).toBeTruthy();Common options
- Make this step optional (Continue on failure): when checked, a failure in this step is recorded and the test continues with the next step.
- Execute step when JavaScript returns true: runs the step only when the JavaScript condition returns true. Otherwise the step is skipped.
See conditional steps and variables for details.