Search code examples
javascriptdebuggingtestingtestcafebrowser-automation

--skip-js-errors on specific test cases


I'm testing functionality that includes redirecting to an external page which I do not control. This page is throwing errors causing the test to fail.

Is there a way to ignore js errors for one specific test only? (I want errors on my site to cause a test fail)


Solution

  • I'm happy to announce that TestCafe of version 2.0 and above provides a variety of options to skip JS errors on the testing pages conditionally at different levels (a whole test run, fixture, a whole test, etc.). To achieve this, you can use all TestCafe's interfaces CLI, a program API, and the config file. Here is a small feature example for skipping errors with a specified message and page URL:

    fixture(**"My tests"**)
        .skipJsErrors({
            **message**: /Some expected message/ig
            **pageUrl**: /some-ads-site/
        });
    

    Read more about this functionality in the Docs.