Permalink
Browse files

fix(reporting): JSON report is generated even if we couldn't capture …

…a screenshot

The synchronisation of capturing screenshots and writing the json report to disk is now improved, so

that Serenity will not allow Protractor to finish before the reports are saved.
  • Loading branch information...
jan-molak committed Jan 19, 2017
1 parent 294ad24 commit f230239e7a20214034b451b8ca36ea7e04ef3ebb
@@ -131,6 +131,18 @@ describe('Photographer', () => {
return expect(photoAttempted.value.photo).to.eventually.be.rejectedWith(unknownError);
});
it('Notifies the Stage Manager of any work in progress', () => {
fileSystem.store.withArgs(photoName, imageBuffer).returns(photoPath);
thePhotographer.notifyOf(new ActivityStarts(activity, now));
return expect(stageManager.allDone()).to.eventually.be.fulfilled.then(tasks => {
expect(tasks).to.have.length(1);
expect(tasks.pop()).to.be.instanceOf(Photo);
});
});
});
describe('When the Actor in the spotlight finished to perform an Activity', () => {
@@ -15,7 +15,13 @@ export class SerenityProtractorPlugin /* implements ProtractorPlugin */ {
}
teardown() {
return Serenity.stageManager().allDone();
return Serenity.stageManager().allDone().then(
_ => _,
error => {
console.error('[SerenityProtractorPlugin] An error occurred during teardown', error); // tslint:disable-line:no-console
return Promise.reject(error);
},
);
}
private crewMembers(): StageCrewMember[] {
@@ -125,19 +125,24 @@ export class Photographer implements StageCrewMember {
let saveScreenshot = data => this.fs.store(this.naming.nameFor(data), new Buffer(data, 'base64'));
let ignoreInactiveBrowserButReportAnyOther = (error: Error) => {
if (error.message.indexOf('does not have a valid session ID') > -1) {
// todo: this needs further investigation; sometimes webdriver session dies before we can take a screenshot
if (~error.message.indexOf('does not have a valid session ID') || ~error.message.indexOf('Session ID is null')) {
// tslint:disable-next-line:no-console
console.warn(`[Photographer] Looks like there was a problem with taking a photo of ${ actor }: `, error.message);
return undefined;
}
throw error;
};
return BrowseTheWeb.as(actor).takeScreenshot()
.then(saveScreenshot)
.then(
path => new Photo(path),
return this.stage.manager.informOfWorkInProgress(
BrowseTheWeb.as(actor).takeScreenshot()
.then(saveScreenshot).then(
path => new Photo(path),
error => ignoreInactiveBrowserButReportAnyOther(error),
);
),
);
}
}
@@ -12,7 +12,7 @@ export interface StageCrewMember {
export class StageManager {
private listeners: CrewMembersCommunicationChannel[] = [];
private wip: Array<Promise<any>> = [];
private wip: Array<PromiseLike<any>> = [];
constructor(private journal: Journal) {
}
@@ -30,11 +30,13 @@ export class StageManager {
}
}
informOfWorkInProgress<T>(promise: Promise<T>): void {
informOfWorkInProgress<T>(promise: PromiseLike<T>): PromiseLike<T> {
this.wip.push(promise);
return promise;
}
allDone(): Promise<any[]> {
allDone(): PromiseLike<any[]> {
return Promise.all(this.wip);
}

0 comments on commit f230239

Please sign in to comment.