When debugging a test, it is usefull to see why a test fail. It would be great to launch a test on a browser, and to run each test one by one (ex: press enter to continue).
It seems a good idea.
I used to use pause command with a long milliseconds and debug code.
Yes so do I, but with very long tests, it is a pain...
Good idea, +1
+1! It will be great to have this.
+1 Yes thats really great idea.
Yes, it could be, for instance, run with some --confirm option which will make nightwatch asking confirmation for each step.
Here is a quick snippet for custom debug command that will drop you into Node's debugger...
exports.command = function debug(callback) {
return this.perform(function() {
debugger;
});
};
+1
here is another really quick snippet derived from @johnboxall s snippet to allow stepping by pressing key. Note that this is not tested properly so use at your own risk!
exports.command = function debug(callback) {
return this.perform(function(client, done) {
console.log('press to continue');
var pressed = false;
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', listener);
pause();
function listener() {
process.stdin.removeListener('keypress', listener);
process.stdin.pause();
pressed = true
}
function pause() {
client.pause(10, function() {
if(!pressed) return pause();
done();
});
}
});
};
@villesau or @johnboxall, where would I add that these snippets and how would I call the methods?
@scoderp see this page: http://nightwatchjs.org/guide#extending
I'm not sure if the api still is 1:1 the same as a year ago.
@scoderp Inside your nightwatch.conf.js add something like:
module.exports = {
...
custom_commands_path: ['test/e2e/custom-commands']
Then save the code above into a file like debug.js in that directory. Then call in your test like:
browser
.url(devServer)
.waitForElementVisible('#app')
.debug()
.setValue('input#username', 'admin')
...
Thanks @cb109, that worked great
Note that this solution doesn't step by step. It only pauses once waiting for a key press. Once a key is pressed, the test continues on without stopping.
Most helpful comment
here is another really quick snippet derived from @johnboxall s snippet to allow stepping by pressing key. Note that this is not tested properly so use at your own risk!