Continuing Test Execution After a Failed Verification in Nightwatch
The article explains how to mark a failed verification point in Nightwatch without halting subsequent test scripts, using verify instead of assert, and provides example code demonstrating conditional handling of test results.
In automated testing, it is often necessary to record a failure while allowing the remaining test scripts to continue executing. In Nightwatch, this can be achieved by using client.verify rather than client.assert , which does not abort the test run.
The following example checks whether the body element of the home page is visible. If the element is found, the verification point is set to false, causing the test report to show a failure but the script proceeds:
home.waitForElementVisible('@body', 3000, true, function(result) {
if (result.value) {
// Test report will show failure, but execution continues
client.verify.equal(result.value, false);
} else {
// Verification passed
console.log('Pass');
}
});Note that using client.assert.equal would interrupt execution:
client.assert.equal(result.value, false);This approach ensures that failures are logged without stopping the test flow, which is useful for comprehensive test suites.
DevOps Engineer
DevOps engineer, Pythonista and FOSS contributor. Created cpp-linter, commit-check, etc.; contributed to PyPA.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.