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

Dynamics 365 automation through RSAT

The Regression Suite Automation Tool (RSAT) significantly reduces the time and cost of user acceptance testing. It enables functional power users to record business tasks using the Finance and Operations task recorder and convert them into a suite of automated tests without the need to write source code.

Fluent CI/CD Pipeline – Not just a pipe dream any more thanks to GitHub actions

Automate, customize, and execute your software development workflows right in your repository with GitHub Actions. You can discover, create, and share actions to perform any job you’d like, including CI/CD, and combine actions in a completely customized workflow.