New to Telerik Test Studio? Download free 30-day trial

Check for JavaScript Errors

The Check for JS errors feature allows you to verify if there are any JS errors generated on the current page.

This article demonstrates how to add this type of step into the test and how it works.

Add Check for JS Errors Step

Choose the Check for JS errors option from the Step Builder and click on the Add Step button in the lower right corner of the pane.

Add Check for JS errors step

How Check for JS Errors Works?

Note!

The page in the current example does not actually contain JavaScript errors. These were generated on purpose to demonstrate the feature.

The default added step checks for any JS errors and passes if there are none. In case any errors are detected, the step fails and lists in the step failure details the errors counting these per their text.

Failed JSErrors Step Details

The failure details are also listed in the execution log.

Execution Log with Failed JS Errors Step

Exclude Specific JS Errors

The ExcludedErrors property of the Check for JS Errors step allows you to filter the errors and exclude some of them if you expect these. Insert the text to identify the errors that shouldn't be counted. Let's use "test" and execute the same sample test again.

ExcludedErrors Field in JSErrors Step

The test checks if there are any JS errors on the page and excludes these which contain the text from the ExcludedErrors property. Expected, the result shows there are no errors on the page, which don't contain "test" in their message.

Execution Log of Excluded Errors Step Passed

Exclude Multiple Different Errors

Multiple errors can be also excluded - separate the errors' text with '|'.

ExcludedErrors Field in JSErrors Step with Multiple Errors Excluded

The execution log from running the test lists details which are the excluded errors and if there are any other.

Exexution Log of Excluded Multiple Errors Step Passed

Single space character is also taken into account and if it is added by mistake, it could cause false positive results.

ExcludedErrors Field in JSErrors Step

The execution log can help in identifying if any additional character is present.

Exexution Log of Excluded Errors Step Failed

Note!

The Check for JS Errors step detects only JavaScript errors. Any errors related to not loaded resources will not be detected. An example for such console error is listed below:

Failed to load resource: the server responded with a status of 404 (Not Found)

In this article