-
Notifications
You must be signed in to change notification settings - Fork 2.3k
browser.takeScreenshot not working when called from 'specDone' (jasmine2 reporter) #1753
Comments
This is likely related to the fact that |
I just tried this, and it works for me (reaches My simple config looks like: exports.config = {
directConnect:true,
capabilities: ...,
specs: ...,
framework: 'jasmine2',
onPrepare: function() {
jasmine.getEnv().addReporter({
specDone: function(result) {
browser.takeScreenshot().then(function(png) {
console.dir(png); // This will get output to the console as expected.
});
}
});
}
} edit: fix function |
Is there a way how to setup screenshoting of failing expectation using jasmine2? I don't think that taking screenshots in the end of the spec is not good for me. |
@juliemr I'm seeing the same problem. The thing is that the callback will indeed be called, but not before suiteDone / jasmineDone. Basically in my case, the order in which they finish is roughly this: specDone (triggers screenshot) -> suiteDone -> jasmineDone -> screenshot callback triggers. This happens to be a problem only if you require some information from the screenshot callback in the following step (specDone / jasmineDone). |
I haven't heard from the initial reporter on the issue, but I think it boils down to this: #1938 Closing to continue discussion there. |
If anyone else comes to this issue, I found that adding an afterAll(function(done){
process.nextTick(done);
}); |
Apologies for going quiet - not sure why I missed the helpful responses to my initial query. My issue does relate to it not waiting for async work to complete before quitting. If I just take the screenshot, then it does work. Before taking the screenshot, I was using browser.getCapabilities and then also making the directory using mkdirp. Turns out the mkdirp step wasn't needed, and I now call getCapabilities during startup, so screenshots on fail now working as hoped :) |
OK - I lied. It appeared to work locally, but the above fails when running on codeship, and mkdirp is definitely needed on local as well. Trying the process.nextTick hack :( (:( because it feels hacky and because I'll need to add it to every spec file?) |
Have refactored code to take the screenshot immediately rather than waiting for mkdirp and browser.getCapabilities to run. Now works fine, no process.nextTick hack needed. Here's my screenshot.js component:
This is triggered by |
@PaddyMann Thanks for sharing!! Worked like a charm |
Hello, As you can see in our fork of class Reporter {
_asyncFlow: Promise<any>;
jasmineStarted() {
/* Wait for async tasks triggered by `specDone`. */
beforeEach(async () => {
await this._asyncFlow;
this._asyncFlow = null;
});
}
specDone(result) {
this._asyncFlow = this._asyncSpecDone(result);
}
async _asyncSpecDone(result) {
// @todo: Do your async stuff here depending on `result.status`, take screenshots etc...
// await takeScreenshot();
}
} |
I am setting up my tests to take screenshots when tests fail, as well as at other times that I specify.
The code for taking a screenshot is very standard, with some wrapping around it to specify where the screenshots go.
When I call this from within a spec, it works perfectly.
However, I have tried to call it from within 'specDone' and while it reaches browser.takeScreenshot(), the promise never calls then() and the screenshot is not produced. No error is displayed in console either.
Here is my very simple reporter:
Any insights into what's happening and how to overcome it would be appreciated :)
The text was updated successfully, but these errors were encountered: