JavaScript errors
DrevOps\BehatSteps\Steps\Web\JavascriptTrait - Source, Example, Helpers
Automatically detect JavaScript errors during test execution.
- Collects JavaScript errors from
window.onerror,unhandledrejectionandconsole.error.- Automatically asserts no errors at end of scenarios with
@javascripttag.- Collects errors after every step and re-injects the collector when the URL changes.
- The
@js-errorstag bypasses error checking when errors are expected.Skip processing with tags:
@behat-steps-skip:JavascriptTrait
Special tags:
@js-errors- bypasses error assertion for a scenario.Automatic error detection:
@javascriptScenario: Navigation without JS errors (will fail if errors occur)Given I visit "/home"When I click on "About"Then I should see "About Us"
Bypassing error detection:@javascript @js-errorsScenario: Legacy page with known errors (will not fail)Given I visit "/legacy-page"
Options
| Option | Type | Default | Tag | Description |
|---|---|---|---|---|
javascript.enabled | boolean | TRUE | @behat-steps-skip:JavascriptTrait | If TRUE, collects the uncaught errors, unhandled promise rejections and console.error() calls of the pages a @javascript scenario visits. The collector is injected into a page after it loads, so errors thrown while the page loads aren't collected. If FALSE, nothing is collected and fail_on_errors has no effect. |
javascript.fail_on_errors | boolean | TRUE | @js-errors | If TRUE, a collected error fails the scenario. If FALSE, errors are still collected and don't fail it. |