Skip to content
Permalink
Browse files
fix(protractor): photographer will not try to capture the screenshot …
…if the actor has no browser

In multi-actor scenarios it is possible to have an actor with no BrowseTheWeb ability set up the
test environment before another actor interacts with it via their web browser. If in such scenario
the Photographer is configured to TakePhotosOfInteractions, it will no longer attempt to capture
screenshots of an actor who doesn't have the ability to BrowseTheWeb, and therefore doesn't have
access to the browser.
  • Loading branch information
jan-molak committed Jun 10, 2020
1 parent 1c0bec7 commit f1491bf979732c56d1b0f3734bad2c33106b0748
Showing 6 changed files with 41 additions and 5 deletions.
@@ -1,3 +1,5 @@
import 'mocha';

import { expect, givenFollowingEvents } from '@integration/testing-tools';
import { AssertionError, ImplementationPendingError, LogicError } from '@serenity-js/core';
import { SceneFinished, SceneStarts, TaskFinished, TaskStarts, TestRunFinished } from '@serenity-js/core/lib/events';
@@ -6,7 +6,14 @@ import { BrowseTheWeb } from '../../../../src/screenplay/abilities';

class UIActors implements Cast {
prepare(actor: Actor): Actor {
return actor.whoCan(BrowseTheWeb.using(protractor.browser));
switch (actor.name) {
case 'Adam':
return actor;

case 'Betty':
default:
return actor.whoCan(BrowseTheWeb.using(protractor.browser));
}
}
}

@@ -1,3 +1,5 @@
import 'mocha';

import { EventRecorder, expect, PickEvent } from '@integration/testing-tools';
import { Duration } from '@serenity-js/core';
import { ActivityFinished, ActivityRelatedArtifactGenerated, ActivityStarts, ArtifactGenerated, DomainEvent } from '@serenity-js/core/lib/events';
@@ -1,3 +1,5 @@
import 'mocha';

import { EventRecorder, expect, PickEvent } from '@integration/testing-tools';
import { ActivityRelatedArtifactGenerated, ActivityStarts } from '@serenity-js/core/lib/events';
import { CorrelationId, Photo } from '@serenity-js/core/lib/model';
@@ -1,5 +1,7 @@
import 'mocha';

import { EventRecorder, expect, PickEvent } from '@integration/testing-tools';
import { ActivityRelatedArtifactGenerated, ActivityStarts } from '@serenity-js/core/lib/events';
import { ActivityRelatedArtifactGenerated, ActivityStarts, InteractionFinished, InteractionStarts } from '@serenity-js/core/lib/events';
import { CorrelationId, Photo } from '@serenity-js/core/lib/model';
import { Stage } from '@serenity-js/core/lib/stage';
import { protractor } from 'protractor';
@@ -49,7 +51,7 @@ describe('Photographer', () => {
});
})));

it('correlates the photo with the activity it\'s concerning', () =>
it(`correlates the photo with the activity it's concerning`, () =>
expect(stage.theActorCalled('Betty').attemptsTo(
Perform.interactionThatFailsWith(Error),
)).to.be.rejected.then(() => stage.waitForNextCue().then(() => {
@@ -112,5 +114,17 @@ describe('Photographer', () => {
);
});
})));

it(`does not attempt to take a photo if the actor in the spotlight can't BrowseTheWeb`, () =>
expect(stage.theActorCalled('Adam').attemptsTo(
Perform.interactionThatSucceeds(1),
)).to.be.fulfilled.then(() => stage.waitForNextCue().then(() => {

expect(recorder.events.length).to.equal(2);
expect(recorder.events[0]).to.be.instanceOf(InteractionStarts);
expect(recorder.events[1]).to.be.instanceOf(InteractionFinished);

// no artifacts generated for an actor with no ability to BrowseTheWeb
})));
});
});
@@ -34,10 +34,19 @@ export abstract class PhotoTakingStrategy {
*/
considerTakingPhoto(event: ActivityStarts | ActivityFinished, stage: Stage): void {
if (this.shouldTakeAPhotoOf(event)) {
let browseTheWeb: BrowseTheWeb;

try {
browseTheWeb = BrowseTheWeb.as(stage.theActorInTheSpotlight());
} catch (error) {
return void 0;
}

const
id = CorrelationId.create(),
nameSuffix = this.photoNameFor(event),
browseTheWeb = BrowseTheWeb.as(stage.theActorInTheSpotlight());
nameSuffix = this.photoNameFor(event);

// fixme: check if the actor can browse the web!

stage.announce(new AsyncOperationAttempted(
new Description(`[Photographer:${ this.constructor.name }] Taking screenshot of '${ nameSuffix }'...`),

0 comments on commit f1491bf

Please sign in to comment.