-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Taking a screenshot of any failing test #368
Comments
FYI, we tried to do this with a reporter a while back, but reporters currently have to run synchronously, so we couldn't do it that way. (We'd request that a screenshot be taken, but the test would have been cleared down and the next test running by the time the screenshot happened.) As a workaround, we ended up wrapping and intercepting 'bdd.js' with our own custom version that wraps all tests with an extra handler that takes a screenshot when erroring. (That can work with, and return, promises, so we can block the teardown and next test until the screenshot completes.) |
This is a pretty frequently asked question, see the following links for some suggestions: |
@dylans yeah I did come across both of them however, the soultions mean you have to write the screenshot for every test whereas really it would be better to add it to |
So I have done this @RoystonS you may be interested, this needs doing in every place you set up a suite but is much more desirable than writing the code for every test. var counter = -1,
suite = {
beforeEach: function () {
counter++;
},
afterEach: function () {
var currentTest = this.tests[counter];
if (!currentTest.error) {
return;
}
this.remote
.takeScreenshot().then(function (buffer) {
if (!fs.existsSync(path)) {
fs.mkdirSync(path);
}
fs.writeFileSync('/tmp/' + currentTest.name + '.png', buffer);
});
}
}; |
@nwhite89 I also mentioned it as I'm hoping someone will be inspired to work on a patch / pull request, in case we don't have time to get to it soon! |
I see @dylans, would you see this as a top configuration of intern passing the location you wish to write the screenshots? because I could try look at it at some point to do a PR into intern. |
@nwhite89 The workaround we have means we don't touch any of our tests except for having all our test files bring in our own version of the 'bdd.js' interface file. In that, we provide an alternative version of 'it' which delegates onto the real bdd it function, but wraps the function passed to take screenshots where errors are occurring. We definitely didn't want to have to add afterEach calls to all of our suites. (We were using an alternative bdd.js file anyway in order to provide ourselves with useful 'xit/xdescribe' functions (like Jasmine provides) which makes it easy to disable individual tests.) But yes, ideally Intern would provide its own first class support for this directly, especially as it's not possible to do this with the existing reporter APIs. |
@nwhite89 yes, a configuration setting for the location would be great |
@dylans ok cool sounds good to me I'll try take a look at it next week 👍 |
Reporters in Intern 3 will be able to asynchronously pause the flow of the test system in order to do things like request screenshots when a test fails! |
It would be nice if it is possible to setup intern to take and save a screenshot when ever a single test fails and not have to write it within the test is this currently possible or could this be a possible add-on for the future?
The text was updated successfully, but these errors were encountered: