It looks it's only possible to log something on the out with callback functions
.setValue("#login","[email protected]")
.setValue("#password","1233asdf")
.submitForm("form[name='loginForm']", function(){ console.log("login with [email protected]")})
Could you please add the direct way, like
.setValue("#login","[email protected]")
.setValue("#password","1233asdf")
.submitForm("form[name='loginForm']")
.log("login with [email protected]")
?
Why do u want to make a browser console output in the first place?
To see the "big console dump" in case of an error?
If you want, on the other hand, to make a terminal output you can have something like this:
browser
.setValue("#login","[email protected]")
.setValue("#password","1233asdf")
.submitForm("form[name='loginForm']");
console.log("login with [email protected]");
browser
.setValue("#login","[email protected]")
.setValue("#password","1233asdf")
.submitForm("form[name='loginForm']");
.end();
No not dumps, but to add some informative text (but not checks) in the logging, but not to break the flow :).
Almost any framework has some king of print/log/console output function.
@vinogradoff, if you use console.log as I did in the example above, it will produce the terminal output:

Yes, I know, but then i must break the flow of
browser
.cmd1
.cmd2
which is visually unpretty.
Oh. Sugar. Now I get it.
Seems I am a little late to the conversation, but this can be solved by adding a custom command:
// Put this in <custom commands dir>/log.js
exports.command = function (message) {
return this.perform(function () {
console.log(message);
});
};
@RPDeshaies the perform (or any command, though perform is probably the cleanest) is needed for command function-style commands to allow them to complete. See #1024 for more info.
@kevinkir According to the documentation, you need to call the done() callback once the perform has finished its job.
So this :
exports.command = function (message) {
return this.perform(function (browser, done) {
console.log('\033[34m 隆 \033[0m' + message);
done();
});
};
// somewhere in your code ..
this.log(`${selector} is enabled`)
Will generate this :

The '\033[34m 隆 \033[0m' is only a way to add some style to the log so that it's like the rest of the logs generated by nightwatch
@RPDeshaies The perform documentation wasn't very clear. I added a change to make it more clear which included showing how a call to done() isn't needed if your perform callback has no parameters:
https://github.com/nightwatchjs/nightwatch/blob/master/lib/api/client-commands/perform.js#L6
The site hasn't been rebuilt so its not yet visible on http://nightwatchjs.org
Is there a way to pull console.logs from the test app? That would really help debug some issues on travis?
Most helpful comment
@kevinkir According to the documentation, you need to call the done() callback once the
performhas finished its job.So this :
Will generate this :
The
'\033[34m 隆 \033[0m'is only a way to add some style to the log so that it's like the rest of the logs generated by nightwatch