When there are some testcases already, we want to make some data anlysis for testcase.
One idea is to caculate how many steps "real user" need to do and what are they(screenshot every step).
So what I want is simple, adding an option in config file, and when enabled, nightwatch will screenshot certain commands(like click) even it's scucess.
Question:
How can I do that?
I think it shall be similar with on_faliure in config file, but I did not find which code handle screenshot on failure, only find on_error handlers.
"screenshots" : {
"enabled" : true,
"on_failure" : true,
"on_error" : false,
"path" : ""
}
After looking at into the source code, I found in lib\index.js, there're a function for each protocol command error to do screenshot:
.on('success', function(result, response) {
if (result.status && result.status !== 0) {
result = self.handleTestError(result);
}
request.emit('result', result, response);
})
.on('error', function(result, response, screenshotContent) {
result = self.handleTestError(result);
if (screenshotContent && self.options.screenshots.on_error) {
var fileNamePath = Utils.getScreenshotFileName(self.api.currentTest, true, self.options.screenshots.path);
self.saveScreenshotToFile(fileNamePath, screenshotContent);
result.lastScreenshotFile = fileNamePath;
}
request.emit('result', result, response);
});
However, the screenshotContent is passed when send HTTP request by selenium sever, in lib\http.js:
response.on('end', function () {
var screenshotContent;
var result, errorMessage = '';
if (flushed) {
result = parseResult(flushed);
if (result.value) {
if (result.value.screen) {
screenshotContent = result.value.screen;
delete result.value.screen;
}
...
It seems selenium will response with screen base64 if error happens, am I right?
If yes, is there any similar logic for success command in selenium?
Thanks for your help, really appreciate!