javascript 为 Protractor 设置 Screenshot Reporter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27866147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting up Screenshot Reporter for Protractor
提问by andrepm
Since I'm a newbie with automated tests and protractor, I'm having some trouble setting this up in my tests.
由于我是自动化测试和量角器的新手,因此在我的测试中设置它时遇到了一些麻烦。
According to the guide, every time that I create a new instance of screenshot reporter, I have to pass a directory path. Right, this means that every time I create a new instance in my specfile?
根据指南,每次创建屏幕截图报告器的新实例时,我都必须传递一个目录路径。是的,这意味着每次我在我的规范文件中创建一个新实例?
Also, there are functions to take screenshots of my skipped and my failed tests. Where i supposed to use takeScreenShotsForSkippedSpecs
and takeScreenShotsOnlyForFailedSpecs
? In my config file?
此外,还有一些功能可以截取我跳过和失败的测试。我应该在哪里使用 takeScreenShotsForSkippedSpecs
和takeScreenShotsOnlyForFailedSpecs
?在我的配置文件中?
This is my onPrepare:
这是我的 onPrepare:
onPrepare: function () {
browser.driver.manage().window().maximize();
global.dvr = browser.driver;
global.isAngularSite = function (flag) {
browser.ignoreSynchronization = !flag;
}
jasmine.getEnv().addReporter(new ScreenShotReporter({
baseDirectory: '/tmp/screenshots',
takeScreenShotsForSkippedSpecs: true,
takeScreenShotsOnlyForFailedSpecs: true
}));
回答by alecxe
Note: If you are using jasmine2
, use protractor-jasmine2-screenshot-reporter
.
注意:如果您使用的是jasmine2
,请使用protractor-jasmine2-screenshot-reporter
.
For jasmine1
:
对于jasmine1
:
I've been using successfully using protractor-html-screenshot-reporter
package. It is based on protractor-screenshot-reporter
, but also provides a nice HTML report.
我一直在成功使用 usingprotractor-html-screenshot-reporter
包。它基于protractor-screenshot-reporter
,但也提供了一个不错的 HTML 报告。
Here is what I have in the protractor config:
这是我在量角器配置中的内容:
var HtmlReporter = require("protractor-html-screenshot-reporter");
exports.config = {
...
onPrepare: function () {
// screenshot reporter
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: "test-results/screenshots"
}));
},
...
}
After running tests, you would get an HTML file containing (example):
运行测试后,您将获得一个 HTML 文件,其中包含(示例):
You can click "view" to see the test-case specific screenshot in the browser.
您可以单击“查看”以在浏览器中查看特定于测试用例的屏幕截图。
回答by hankduan
The readme in the library is pretty self explanatory. After installing the library, add it onto protractor's onPrepare
in your protractor config file.
图书馆中的自述文件是不言自明的。安装库后,将其添加到onPrepare
量角器配置文件中的量角器中。
i.e. protractorConf.js:
即量角器Conf.js:
var ScreenShotReporter = require('protractor-screenshot-reporter');
exports.config = {
// your config here ...
onPrepare: function() {
// Add a screenshot reporter and store screenshots to `/tmp/screnshots`:
jasmine.getEnv().addReporter(new ScreenShotReporter({
baseDirectory: '/tmp/screenshots',
takeScreenShotsForSkippedSpecs: true
}));
}
}
then protractor protractorConf.js
to run protractor.
然后protractor protractorConf.js
运行量角器。
回答by Andrej
Just recently I published a brand new plugin called protractor-screenshoter-pluginthat captures for each browser instancea screenshotand console logs. The snapshot is made optionally for each expector spec. It comes with a beautiful angular and bootstrap based analytics toolto visually check and fix tests results.
就在最近,我发表了一篇名为一个全新的插件量角器-screenshoter-插件来捕捉每一个浏览器实例一个屏幕截图和控制台日志。快照是为每个expect或spec可选的。它带有一个漂亮的基于角度和引导的分析工具,可以直观地检查和修复测试结果。
Check it out at https://github.com/azachar/protractor-screenshoter-plugin.
在https://github.com/azachar/protractor-screenshoter-plugin 上查看。
Also, I created a list of all available alternatives, so if you find something else, please do not hesitate to add it there.
另外,我创建了一个所有可用替代品的列表,所以如果你发现其他的东西,请不要犹豫,把它添加到那里。