Wednesday 25 May 2016

testing - Nightwatch pipe all console messages to a file

I'm using nightwatch to run some QA tests on code I have little control over. The app consists of multiple windows being opened through the use of popups. Because it is difficult to know exactly when to try and grab the console within my tests, I'd like a way of piping all console messages from any window that is running within the context of selenium, to an output file so I can sift through it.



Right now I have this in my test



.getLog('browser', function (result) {
console.log(typeof result)
fs.writeFile("browser.log", JSON.stringify(result), function(err) {
if(err) {
return console.log(err);

}
console.log("Log Saved");
});
});


This may work for some cases, but sometimes the code I am hoping to catch happens on an unload event. In a situation like that, catching the error at the correct time proves challenging. I was hoping that nightwatch might expose some sort of event listener api where I could observe the browser.log file for example, and update the contents of the file automatically. Does such a feature exist? Is there a better way to do this?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...