如何在测试用例失败时在量角器中截取屏幕截图

时间:2023-02-09 01:21:06

I am new to the protractor and would like to take screenshots of my failed test cases in browsers.

我是量角器的新手,想在浏览器中截取我失败的测试用例的截图。

Can you please help me out by advising how should I go about it?

你能告诉我该如何解决这个问题,请你帮帮我吗?

Thank you :)

谢谢 :)

2 个解决方案

#1


7  

You can use protractor-jasmine2-screenshot-reporter module for this, it has some good features which would serve your purpose.

你可以使用protractor-jasmine2-screenshot-reporter模块,它有一些很好的功能可以满足你的需要。

 var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');

 var reporter = new HtmlScreenshotReporter({
 dest: 'target/screenshots',
 filename: 'my-report.html',
 captureOnlyFailedSpecs: true
});

This will capture screenshots when your specs have failed, you have many more options, you can checkout this link : https://www.npmjs.com/package/protractor-jasmine2-screenshot-reporter

这将捕获您的规格失败时的屏幕截图,您有更多选项,您可以查看此链接:https://www.npmjs.com/package/protractor-jasmine2-screenshot-reporter

#2


2  

Please have a look on this chunk of code. In this code we are registering screenshot function properly with jasmine reporter. Its works for me.

请看一下这段代码。在这段代码中,我们正在与茉莉花记者正确地注册截图功能。它适合我。

onPrepare: function() {
jasmine.getEnv().addReporter({
  specDone: function(result) {
    browser.takeScreenshot().then(function(screenShot) {

      //    Saving File.
      //    Param filePath : where you want to store screenShot
      //    Param screenShot : Screen shot file which you want to store. 

      fs.writeFile(filePath, screenShot, 'base64', function (err) {
      if (err) throw err;
      console.log('File saved.');
      });

    });
  }
});
}

I hope it helps! :)

我希望它有所帮助! :)

Reference link

#1


7  

You can use protractor-jasmine2-screenshot-reporter module for this, it has some good features which would serve your purpose.

你可以使用protractor-jasmine2-screenshot-reporter模块,它有一些很好的功能可以满足你的需要。

 var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');

 var reporter = new HtmlScreenshotReporter({
 dest: 'target/screenshots',
 filename: 'my-report.html',
 captureOnlyFailedSpecs: true
});

This will capture screenshots when your specs have failed, you have many more options, you can checkout this link : https://www.npmjs.com/package/protractor-jasmine2-screenshot-reporter

这将捕获您的规格失败时的屏幕截图,您有更多选项,您可以查看此链接:https://www.npmjs.com/package/protractor-jasmine2-screenshot-reporter

#2


2  

Please have a look on this chunk of code. In this code we are registering screenshot function properly with jasmine reporter. Its works for me.

请看一下这段代码。在这段代码中,我们正在与茉莉花记者正确地注册截图功能。它适合我。

onPrepare: function() {
jasmine.getEnv().addReporter({
  specDone: function(result) {
    browser.takeScreenshot().then(function(screenShot) {

      //    Saving File.
      //    Param filePath : where you want to store screenShot
      //    Param screenShot : Screen shot file which you want to store. 

      fs.writeFile(filePath, screenShot, 'base64', function (err) {
      if (err) throw err;
      console.log('File saved.');
      });

    });
  }
});
}

I hope it helps! :)

我希望它有所帮助! :)

Reference link