how to do screenshots for each command?

794 views
Skip to first unread message

RobinsonZzz

unread,
Mar 7, 2016, 12:21:39 AM3/7/16
to NightwatchJs
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!

Andrei Rusu

unread,
Mar 7, 2016, 3:45:12 AM3/7/16
to nightw...@googlegroups.com
You can use the saveScreenshot command and call it whenever you need:
http://nightwatchjs.org/api#saveScreenshot.
> --
> You received this message because you are subscribed to the Google Groups
> "NightwatchJs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nightwatchjs...@googlegroups.com.
> To post to this group, send email to nightw...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nightwatchjs/200875e6-7a8c-4ca3-9bd4-a9863175158c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

RobinsonZzz

unread,
Mar 8, 2016, 12:43:52 AM3/8/16
to NightwatchJs
Hi Andrei,

Thanks for your answer.

However, what I expected is a basic function in the framework provide screenshot ability, rather than write many screenshots in the test case.
Because it will mess up the original logic of testcase self and also can not control easily.
The most important is it will bring more effort for each one, which means hard to control and hard to do the promotion.

I know maybe it's not a feature needed by everybody, so I just plan to do some modification and maintain by myself.

Since each protocol command is executed sepratedly, my plan is add screenshot in the command queue if the command is certain ones.
Could you give me some clue to fullfill the need?

1. How the command queue is filled from testcase? I did not find the logic do it.
2. Is the screenshot of on_error is response by selenium server self? Does it also can screenshot when scuess?

Really appreciate!

在 2016年3月7日星期一 UTC+8下午4:45:12,Andrei Rusu写道:

Andrei Rusu

unread,
Mar 8, 2016, 4:38:08 AM3/8/16
to nightw...@googlegroups.com
I see. Then feel free to submit a feature request on Github:
https://github.com/nightwatchjs/nightwatch/issues detailing your use
case and expectations, though it may be a while until it's picked up.
However if you need this feature right away you may look into using a
remote testing solution like BrowserStack/SauceLabs etc. Both of these
services provide screenshots for each command and even video
recordings of the test run I believe.
> https://groups.google.com/d/msgid/nightwatchjs/0f21ecb5-b769-43c5-ae27-1d0d8b440d57%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages