-
Notifications
You must be signed in to change notification settings - Fork 2.3k
How to take screen shot of the application whenever expect fails #114
Comments
I have defined a custom expect function in jasmine.js file and called the same function in my protractor test case file. In this jasmine function I am throwing exception but it not getting caught in try catch block in the protractor test case file. Not sure whats going on here.Does the expect function called in separate thread. Here is what i am doing. |
This doesn't quite do what you want, because it screenshots on each failing test instead of each failing expectation. However, this could be added to your test file easily. Jasmine currently provides no way to hook in to do something on each expectation. You could also write a custom matcher which takes a screenshot on failure - e.g. I'm going to hold off on trying to add anything to each // Take a screenshot automatically after each failing test.
afterEach(function() {
var passed = jasmine.getEnv().currentSpec.results().passed();
if (!passed) {
browser.takeScreenshot().then(function(png) {
// Do something with the png...
};
}
}); |
Hi Julie, Is there a way to add this to the conf file so I don't have to add it to every test file? similar to onPrepare thanks |
@gsastry you can add it to every test by adding a generic "spec-helper.js" file and add the afterEach function there, outside the context of a specific describe block. Then have your conf file load the spec helper into the browser together with the specs. |
@eitanp461 How do I have the conf file load the helper file together with the spec? |
Ah got it. Just add it to the list of files in the specs. =) |
You might be interested in this code when it comes to creating the file from the string that |
@mcalthrop me too. I suppose you just have to base64decode the string you get and save it wie nodes fs.
Doesn't work for me though. |
Here's the exact code I am using: var fs = require('fs');
Utils = {
/**
* @name screenShotDirectory
* @description The directory where screenshots will be created
* @type {String}
*/
screenShotDirectory: 'test/results/',
/**
* @name writeScreenShot
* @description Write a screenshot string to file.
* @param {String} data The base64-encoded string to write to file
* @param {String} filename The name of the file to create (do not specify directory)
*/
writeScreenShot: function (data, filename) {
var stream = fs.createWriteStream(this.screenShotDirectory + filename);
stream.write(new Buffer(data, 'base64'));
stream.end();
}
};
/**
* Automatically store a screenshot for each test.
*/
afterEach(function () {
var currentSpec = jasmine.getEnv().currentSpec,
passed = currentSpec.results().passed();
browser.takeScreenshot().then(function (png) {
browser.getCapabilities().then(function (capabilities) {
var browserName = capabilities.caps_.browserName,
passFail = (passed) ? 'pass' : 'FAIL',
filename = browserName + ' ' + passFail + ' - ' + currentSpec.description + '.png';
Utils.writeScreenShot(png, filename);
});
});
}); You don't actually need the You can also see that the screen grab file name contains the name of the specific test. HTH! Matt |
based on @mcalthrop initial |
Excellent! Thanks @swissmanu . |
I think this is now just a documentation issue, so switching the labels. |
Documented with fca9c5f |
I have written a Protractor plug in , that takes screenshot for every 'expect' failure and spec failure as well. Screenshot names are meaningful too. Note: It is compatible with Jasmine2 only. |
@abhishekswain You want me to add your plugin to the community plugins list? |
@sjelin Yes please , if it is possible. :) |
Any way to take screenshot of the screen while (and including) Javascript alert open captured ? |
Hi there! I have forked and improved @abhishekswain tool. Now the brand new fork called protractor-screenshoter-plugin captures for each browser instance a screenshot and console logs. The snapshot is made optionally for each expect or spec. It comes with a beautiful angular and bootstrap based analytics tool to visually check and fix tests results. Check it out at 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. |
Hi all! Could you help me to investigate jasmine-allure for fails screens?
But I also get all screens after every steps |
Hi there,
Feel free to use https://github.com/azachar/protractor-screenshoter-plugin <https://github.com/azachar/protractor-screenshoter-plugin> instead (disclaimer: I am the maintainer of it).
Cheers,
Andrej
… On 19 Feb 2018, at 13:16, Sereda-Fazen ***@***.***> wrote:
Hi all! Could you help me to investigate jasmine-allure for fails screens?
I got next
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
var AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
resultsDir: 'reports/allure-results'
}));
var pass = jasmine.getEnv().afterEach(function(done){
if(!pass)
browser.takeScreenshot().then(function (png) {
allure.createAttachment('Screenshot', function () {
return new Buffer(png, 'base64')
}, 'image/png')();
done();
})
})
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#114 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AEcXS0P9OD0okl6K9yL6xo46tQj40WI4ks5tWWYfgaJpZM4BCbS3>.
|
Is there any wait to capture screen shot of the application whenever expect fails. Idea it to capture all points of failure. Selenium driver supports some feature like this.Is there any kind of switch in protractor also .
The text was updated successfully, but these errors were encountered: