问题
I am using protractor to automate a hybrid mobile app, I am using the Protractor-HTML-screenshot-reporter, but it is not displaying any report after successful test execution.
Here's my code below:
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter=new HtmlReporter({
baseDirectory: 'C:\\Users\\bhawani.prasad\\Desktop\\Protractor\\PageObject\\report', // a location to store screen shots.
docTitle: 'Protractor Demo Reporter',
docName: 'protractor-demo-tests-report.html'
});
onPrepare: function() {
jasmine.getEnv().addReporter(reporter);
} ,
回答1:
For those who are wondering why there are no screenshots generated by protactor-html-screenshot-reporter
and, if you are using jasmine2
:
protractor-html-screenshot-reporter is not compatible with jasmine 2
Switch to protractor-jasmine2-screenshot-reporter.
回答2:
There's not much to go on here. I'd recommend just ditching a screenshot library and roll your own. Here's what we use internally to grab a screenshot and html after a failed test.
function setupScreenGrabber() {
jasmine.getEnv().afterEach(function() {
if (jasmine.getEnv().currentSpec.results_.failedCount > 0) {
var filename = 'target/screenshots/failed-' + jasmine.getEnv().currentSpec.getFullName() + '-' + Date.now();
browser.takeScreenshot().then(function(png) {
var stream = fs.createWriteStream(filename + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
});
element(by.css('html')).getOuterHtml().then(function(html) {
fs.writeFile(filename + '.html', html);
});
}
});
}
Just call this method from inside of onPrepare
. You will need to require(fs)
. Also, since you want to capture only on passing tests, then change > 0
to === 0
. But, this should get you started.
来源:https://stackoverflow.com/questions/27924115/protractor-html-screenshot-reporter-not-showing-any-report-after-test-execution