Skip to content
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

Closed
nwhite89 opened this issue Mar 26, 2015 · 10 comments
Closed

Taking a screenshot of any failing test #368

nwhite89 opened this issue Mar 26, 2015 · 10 comments
Milestone

Comments

@nwhite89
Copy link

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?

@RoystonS
Copy link

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.)

@nwhite89
Copy link
Author

@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 afterEach for the registered suite, or even better being able to have something in the overall intern configuration

@nwhite89
Copy link
Author

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);
                });
        }
    };

@dylans
Copy link

dylans commented Mar 26, 2015

@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!

@nwhite89
Copy link
Author

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.

@RoystonS
Copy link

@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.

@dylans
Copy link

dylans commented Mar 26, 2015

@nwhite89 yes, a configuration setting for the location would be great

@nwhite89
Copy link
Author

@dylans ok cool sounds good to me I'll try take a look at it next week 👍

@csnover csnover added this to the 3.0 milestone Apr 1, 2015
@csnover
Copy link
Member

csnover commented Apr 1, 2015

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants