How to automatically pause your Selenium WebDriver (Node.js) tests on every failure for debugging

by: Aswin Chembath


At Testing Mavens, we maintain a number of large end to end testing frameworks in JavaScript, developed using either protractor or WebdriverIO with jasmine. These tests are run in the CI/CD pipeline and monitored daily. To analyze the failures, we run the tests locally, set breakpoints for debugging and fix the failures.


When the test suite is large and there are multiple failures, deciding where to put the breakpoints itself is a tedious task. Won’t it be nice if the test script can pause automatically for debugging when a failure occurs? Then you can closely look at the application under test, make necessary changes to the test script and finally continue running the tests. This will help us in saving a lot of time while doing the script maintenance. 


We can achieve the behavior (of pausing the script execution on failure) by making simple changes to the configuration files to call the JavaScript debugger on failure.

For Protractor – Jasmine framework,

Add the below lines of code inside the onPrepare() method in your Protractor config

    specDone: async function (spec) {
        if (spec.status === "failed") {
            console.log("Error Occurred, pausing script for debugging");

For WebdriverIO – Jasmine framework,

We can use the expectationResultHandler() method in the wdio.conf file

expectationResultHandler: function (passed, assertion) {
    if (!passed) {
        console.log(`Error Occurred, pausing script for debugging`);

Note :

We need to run the script in Node.js debugging mode for this to work. We use Visual Studio Code editor which has a built-in JavaScript Debug Terminal.

Relevant posts

Mobile App Testing Using BrowserStack

The number of smartphone users worldwide is growing exponentially. As this trend continues, it’s not surprising that companies are investing heavily in developing their own apps to better serve the needs of customers and fans alike! Businesses like Financial Institutions have seen great success with mobile app downloads increasing at an average 7%-8% YOY basis according to Statista.

Streaming Success with OTT Testing

It is evident that future technological advancements will make it possible for higher bandwidth networks like 4G and 5G resulting in increased on-demand video consumption. This article will enlighten you about various OTT testing techniques, but before that let’s dive into the basics of OTT.