Skip to main content

JavaScript errors

DrevOps\BehatSteps\Steps\Web\JavascriptTrait - Source, Example, Helpers

Automatically detect JavaScript errors during test execution.

  • Collects JavaScript errors from window.onerror, unhandledrejection and console.error.
  • Automatically asserts no errors at end of scenarios with @javascript tag.
  • Collects errors after every step and re-injects the collector when the URL changes.
  • The @js-errors tag 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:

@javascript
Scenario: 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-errors
Scenario: Legacy page with known errors (will not fail)
Given I visit "/legacy-page"

Options​

OptionTypeDefaultTagDescription
javascript.enabledbooleanTRUE@behat-steps-skip:JavascriptTraitIf 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_errorsbooleanTRUE@js-errorsIf TRUE, a collected error fails the scenario. If FALSE, errors are still collected and don't fail it.