@serenity-js/playwright-test
Advanced tools
Comparing version 3.2.1 to 3.3.0
@@ -6,2 +6,22 @@ # Change Log | ||
# [3.3.0](https://github.com/serenity-js/serenity-js/compare/v3.2.1...v3.3.0) (2023-06-01) | ||
### Bug Fixes | ||
* **playwright-test:** corrected synchronisation of the `platform` fixture ([7156f84](https://github.com/serenity-js/serenity-js/commit/7156f840dc8fe5688d25aca5ba87d925158e9c7d)), closes [#1717](https://github.com/serenity-js/serenity-js/issues/1717) | ||
* **playwright:** support for Playwright 1.34.0 ([5d591c7](https://github.com/serenity-js/serenity-js/commit/5d591c71e89ac4cfd41b8f7e3a1c9017f962d9e3)) | ||
* **playwright:** updated Playwright to 1.34.2 ([c944031](https://github.com/serenity-js/serenity-js/commit/c94403199a349d59bb777b981897039c102f243f)) | ||
* **playwright:** upgraded to Playwright 1.34.3 ([0ded19e](https://github.com/serenity-js/serenity-js/commit/0ded19e8ef3aea74307ab3bbd69ff5f7b3c9f78b)) | ||
### Features | ||
* **playwright-test:** improved integration with Playwright Test ([45b324f](https://github.com/serenity-js/serenity-js/commit/45b324f4b2e2992dc2df78c18013f2f235ff91b9)), closes [#1717](https://github.com/serenity-js/serenity-js/issues/1717) | ||
* **playwright-test:** much more detailed Playwright Test reports ([5980a1e](https://github.com/serenity-js/serenity-js/commit/5980a1e37047d71199cc169271fa11869e98355b)), closes [#1717](https://github.com/serenity-js/serenity-js/issues/1717) | ||
## [3.2.1](https://github.com/serenity-js/serenity-js/compare/v3.2.0...v3.2.1) (2023-05-15) | ||
@@ -8,0 +28,0 @@ |
@@ -36,2 +36,3 @@ "use strict"; | ||
const reporter_1 = require("../reporter"); | ||
const PerformActivitiesAsPlaywrightSteps_1 = require("./PerformActivitiesAsPlaywrightSteps"); | ||
/** | ||
@@ -96,3 +97,5 @@ * Declares a single test scenario. | ||
actors: [ | ||
({ browser, contextOptions }, use) => use(core_1.Cast.where(actor => actor.whoCan(playwright_1.BrowseTheWebWithPlaywright.using(browser, contextOptions), core_1.TakeNotes.usingAnEmptyNotepad()))), | ||
async ({ browser, contextOptions, serenity }, use) => { | ||
await use(core_1.Cast.where(actor => actor.whoCan(new PerformActivitiesAsPlaywrightSteps_1.PerformActivitiesAsPlaywrightSteps(actor, serenity, exports.it), playwright_1.BrowseTheWebWithPlaywright.using(browser, contextOptions), core_1.TakeNotes.usingAnEmptyNotepad()))); | ||
}, | ||
{ option: true }, | ||
@@ -119,3 +122,3 @@ ], | ||
// eslint-disable-next-line no-empty-pattern | ||
platform: ({}, use) => { | ||
platform: async ({}, use) => { | ||
const platform = os.platform(); | ||
@@ -126,3 +129,3 @@ // https://nodejs.org/api/process.html#process_process_platform | ||
: (platform === 'darwin' ? 'macOS' : 'Linux'); | ||
use({ name, version: os.release() }); | ||
await use({ name, version: os.release() }); | ||
}, | ||
@@ -129,0 +132,0 @@ serenity: async ({ crew, cueTimeout, interactionTimeout, platform }, use, info) => { |
@@ -7,11 +7,9 @@ import { TestInfo } from '@playwright/test'; | ||
private stage?; | ||
private readonly steps; | ||
constructor(testInfo: TestInfo, stage?: Stage); | ||
assignedTo(stage: Stage): StageCrewMember; | ||
notifyOf(event: DomainEvent): void; | ||
private isAPhotoAttempt; | ||
private indicatesCompletionOfAnAsyncOperation; | ||
private attachPhotoFrom; | ||
private createStep; | ||
private shouldAddTag; | ||
private addTag; | ||
} | ||
//# sourceMappingURL=PlaywrightStepReporter.d.ts.map |
@@ -5,7 +5,3 @@ "use strict"; | ||
const events_1 = require("@serenity-js/core/lib/events"); | ||
const io_1 = require("@serenity-js/core/lib/io"); | ||
const model_1 = require("@serenity-js/core/lib/model"); | ||
const web_1 = require("@serenity-js/web"); | ||
const tiny_types_1 = require("tiny-types"); | ||
const genericPathToPhotographer = io_1.Path.from(require.resolve('@serenity-js/web')); | ||
class PlaywrightStepReporter { | ||
@@ -15,3 +11,2 @@ constructor(testInfo, stage) { | ||
this.stage = stage; | ||
this.steps = new Map(); | ||
} | ||
@@ -23,48 +18,9 @@ assignedTo(stage) { | ||
notifyOf(event) { | ||
(0, tiny_types_1.match)(event) | ||
.when(events_1.TaskStarts, (e) => { | ||
this.steps.set(e.activityId.value, this.createStep(e.details, 'task')); | ||
}) | ||
.when(events_1.InteractionStarts, (e) => { | ||
this.steps.set(e.activityId.value, this.createStep(e.details, 'interaction')); | ||
}) | ||
.when(events_1.AsyncOperationAttempted, (e) => { | ||
if (this.isAPhotoAttempt(e)) { | ||
this.steps.set(e.correlationId.value, this.createStep(new model_1.ActivityDetails(new model_1.Name(`${web_1.Photographer.name}: ${e.description.value}`), new io_1.FileSystemLocation(genericPathToPhotographer)), 'crew')); | ||
} | ||
}) | ||
.when(events_1.ActivityFinished, (e) => { | ||
const error = e.outcome instanceof model_1.ProblemIndication | ||
? e.outcome.error | ||
: undefined; | ||
this.steps.get(e.activityId.value).complete({ error }); | ||
}) | ||
.when(events_1.ActivityRelatedArtifactGenerated, (e) => { | ||
if (e.artifact instanceof model_1.Photo) { | ||
this.attachPhotoFrom(e); | ||
} | ||
}) | ||
.when(events_1.SceneTagged, (e) => { | ||
// don't include platform and browser tags as Playwright already includes them | ||
if (!(e.tag instanceof model_1.PlatformTag || e.tag instanceof model_1.BrowserTag)) { | ||
this.testInfo.annotations.push({ type: e.tag.type, description: e.tag.name }); | ||
} | ||
}) | ||
.else(e => { | ||
if (this.indicatesCompletionOfAnAsyncOperation(e) && this.steps.has(e.correlationId.value)) { | ||
const error = event instanceof events_1.AsyncOperationFailed | ||
? event.error | ||
: undefined; | ||
this.steps.get(e.correlationId.value).complete({ error }); | ||
} | ||
}); | ||
if (event instanceof events_1.ActivityRelatedArtifactGenerated && event.artifact instanceof model_1.Photo) { | ||
this.attachPhotoFrom(event); | ||
} | ||
if (event instanceof events_1.SceneTagged && this.shouldAddTag(event.tag)) { | ||
this.addTag(event.tag); | ||
} | ||
} | ||
isAPhotoAttempt(event) { | ||
return event.name.value.startsWith(web_1.Photographer.name); | ||
} | ||
indicatesCompletionOfAnAsyncOperation(event) { | ||
return event instanceof events_1.AsyncOperationCompleted | ||
|| event instanceof events_1.AsyncOperationAborted | ||
|| event instanceof events_1.AsyncOperationFailed; | ||
} | ||
attachPhotoFrom(event) { | ||
@@ -78,16 +34,11 @@ const id = model_1.CorrelationId.create(); | ||
} | ||
createStep(activityDetails, type) { | ||
// https://github.com/microsoft/playwright/blob/04f77f231981780704a3a5e2cea93e3c420809a0/packages/playwright-test/src/expect.ts#L200-L206 | ||
return this.testInfo._addStep({ | ||
location: activityDetails.location | ||
? { file: activityDetails.location.path.value, line: activityDetails.location.line, column: activityDetails.location.column } | ||
: undefined, | ||
category: `serenity-js:${type}`, | ||
title: activityDetails.name.value, | ||
canHaveChildren: true, | ||
forceNoParent: false, | ||
}); | ||
shouldAddTag(tag) { | ||
// don't include platform and browser tags as Playwright already includes them | ||
return !(tag instanceof model_1.PlatformTag || tag instanceof model_1.BrowserTag); | ||
} | ||
addTag(tag) { | ||
this.testInfo.annotations.push({ type: tag.type, description: tag.name }); | ||
} | ||
} | ||
exports.PlaywrightStepReporter = PlaywrightStepReporter; | ||
//# sourceMappingURL=PlaywrightStepReporter.js.map |
{ | ||
"name": "@serenity-js/playwright-test", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Serenity/JS reporter and test APIs for Playwright Test", | ||
@@ -47,6 +47,6 @@ "author": { | ||
"dependencies": { | ||
"@playwright/test": "^1.33.0", | ||
"@serenity-js/core": "3.2.1", | ||
"@serenity-js/playwright": "3.2.1", | ||
"@serenity-js/web": "3.2.1", | ||
"@playwright/test": "^1.34.3", | ||
"@serenity-js/core": "3.3.0", | ||
"@serenity-js/playwright": "3.3.0", | ||
"@serenity-js/web": "3.3.0", | ||
"deepmerge": "^4.3.1", | ||
@@ -65,3 +65,3 @@ "tiny-types": "^1.19.1" | ||
}, | ||
"gitHead": "9a5a77e6e966c827c0331699bef34326905c16b6" | ||
"gitHead": "c4a2bb6aef7b087dc9bc37269fd999d1cdc15088" | ||
} |
@@ -11,2 +11,3 @@ import { test as base, TestInfo } from '@playwright/test'; | ||
import { DomainEventBuffer, PlaywrightStepReporter, SERENITY_JS_DOMAIN_EVENTS_ATTACHMENT_CONTENT_TYPE } from '../reporter'; | ||
import { PerformActivitiesAsPlaywrightSteps } from './PerformActivitiesAsPlaywrightSteps'; | ||
import { SerenityFixtures } from './SerenityFixtures'; | ||
@@ -76,7 +77,10 @@ import { SerenityOptions } from './SerenityOptions'; | ||
actors: [ | ||
({ browser, contextOptions }, use) => | ||
use(Cast.where(actor => actor.whoCan( | ||
async ({ browser, contextOptions, serenity }, use) => { | ||
await use(Cast.where(actor => actor.whoCan( | ||
new PerformActivitiesAsPlaywrightSteps(actor, serenity, it), | ||
BrowseTheWebWithPlaywright.using(browser, contextOptions), | ||
TakeNotes.usingAnEmptyNotepad(), | ||
))), | ||
))) | ||
}, | ||
{ option: true }, | ||
@@ -108,3 +112,3 @@ ], | ||
// eslint-disable-next-line no-empty-pattern | ||
platform: ({}, use) => { | ||
platform: async ({}, use) => { | ||
const platform = os.platform(); | ||
@@ -117,3 +121,3 @@ | ||
use({ name, version: os.release() }); | ||
await use({ name, version: os.release() }); | ||
}, | ||
@@ -120,0 +124,0 @@ |
import { TestInfo } from '@playwright/test'; | ||
import { Location, TestError } from '@playwright/test/reporter'; | ||
import { Stage, StageCrewMember } from '@serenity-js/core'; | ||
import { | ||
ActivityFinished, | ||
ActivityRelatedArtifactGenerated, | ||
AsyncOperationAborted, | ||
AsyncOperationAttempted, | ||
AsyncOperationCompleted, | ||
AsyncOperationFailed, | ||
DomainEvent, | ||
InteractionStarts, | ||
SceneTagged, | ||
TaskStarts, | ||
} from '@serenity-js/core/lib/events'; | ||
import { FileSystemLocation, Path } from '@serenity-js/core/lib/io'; | ||
import { ActivityDetails, BrowserTag, CorrelationId, Description, Name, Photo, PlatformTag, ProblemIndication } from '@serenity-js/core/lib/model'; | ||
import { Photographer } from '@serenity-js/web'; | ||
import { match } from 'tiny-types'; | ||
import { BrowserTag, CorrelationId, Description, Name, Photo, PlatformTag } from '@serenity-js/core/lib/model'; | ||
import { Tag } from '@serenity-js/core/src/model'; | ||
const genericPathToPhotographer = Path.from(require.resolve('@serenity-js/web')) | ||
// https://github.com/microsoft/playwright/blob/04f77f231981780704a3a5e2cea93e3c420809a0/packages/playwright-test/src/types.ts#L30 | ||
interface TestStepInternal { | ||
complete(result: { error?: Error | TestError }): void; | ||
title: string; | ||
category: string; | ||
canHaveChildren: boolean; | ||
forceNoParent: boolean; | ||
location?: Location; | ||
refinedTitle?: string; | ||
} | ||
export class PlaywrightStepReporter implements StageCrewMember { | ||
private readonly steps: Map<string, TestStepInternal> = new Map(); | ||
constructor( | ||
@@ -53,56 +29,11 @@ private readonly testInfo: TestInfo, | ||
match<DomainEvent, void>(event) | ||
.when(TaskStarts, (e: TaskStarts) => { | ||
this.steps.set(e.activityId.value, this.createStep(e.details, 'task')) | ||
}) | ||
.when(InteractionStarts, (e: InteractionStarts) => { | ||
this.steps.set(e.activityId.value, this.createStep(e.details, 'interaction')); | ||
}) | ||
.when(AsyncOperationAttempted, (e: AsyncOperationAttempted) => { | ||
if (this.isAPhotoAttempt(e)) { | ||
this.steps.set(e.correlationId.value, this.createStep(new ActivityDetails( | ||
new Name(`${ Photographer.name }: ${ e.description.value }`), | ||
new FileSystemLocation(genericPathToPhotographer) | ||
), 'crew')); | ||
} | ||
}) | ||
.when(ActivityFinished, (e: ActivityFinished) => { | ||
const error = e.outcome instanceof ProblemIndication | ||
? e.outcome.error | ||
: undefined; | ||
if (event instanceof ActivityRelatedArtifactGenerated && event.artifact instanceof Photo) { | ||
this.attachPhotoFrom(event); | ||
} | ||
this.steps.get(e.activityId.value).complete({ error }); | ||
}) | ||
.when(ActivityRelatedArtifactGenerated, (e: ActivityRelatedArtifactGenerated) => { | ||
if (e.artifact instanceof Photo) { | ||
this.attachPhotoFrom(e); | ||
} | ||
}) | ||
.when(SceneTagged, (e: SceneTagged) => { | ||
// don't include platform and browser tags as Playwright already includes them | ||
if (! (e.tag instanceof PlatformTag || e.tag instanceof BrowserTag)) { | ||
this.testInfo.annotations.push({ type: e.tag.type, description: e.tag.name }); | ||
} | ||
}) | ||
.else(e => { | ||
if (this.indicatesCompletionOfAnAsyncOperation(e) && this.steps.has(e.correlationId.value)) { | ||
const error = event instanceof AsyncOperationFailed | ||
? event.error | ||
: undefined; | ||
this.steps.get(e.correlationId.value).complete({ error }) | ||
} | ||
}) | ||
if (event instanceof SceneTagged && this.shouldAddTag(event.tag)) { | ||
this.addTag(event.tag); | ||
} | ||
} | ||
private isAPhotoAttempt(event: AsyncOperationAttempted): event is AsyncOperationAttempted { | ||
return event.name.value.startsWith(Photographer.name); | ||
} | ||
private indicatesCompletionOfAnAsyncOperation(event: DomainEvent): event is AsyncOperationCompleted | AsyncOperationAborted | AsyncOperationFailed { | ||
return event instanceof AsyncOperationCompleted | ||
|| event instanceof AsyncOperationAborted | ||
|| event instanceof AsyncOperationFailed | ||
} | ||
private attachPhotoFrom(event: ActivityRelatedArtifactGenerated) { | ||
@@ -127,14 +58,10 @@ const id = CorrelationId.create(); | ||
private createStep(activityDetails: ActivityDetails, type: 'task' | 'interaction' | 'crew'): TestStepInternal { | ||
// https://github.com/microsoft/playwright/blob/04f77f231981780704a3a5e2cea93e3c420809a0/packages/playwright-test/src/expect.ts#L200-L206 | ||
return (this.testInfo as any)._addStep({ | ||
location: activityDetails.location | ||
? { file: activityDetails.location.path.value, line: activityDetails.location.line, column: activityDetails.location.column } | ||
: undefined, | ||
category: `serenity-js:${ type }`, | ||
title: activityDetails.name.value, | ||
canHaveChildren: true, | ||
forceNoParent: false, | ||
}) as TestStepInternal; | ||
private shouldAddTag(tag: Tag): boolean { | ||
// don't include platform and browser tags as Playwright already includes them | ||
return ! (tag instanceof PlatformTag || tag instanceof BrowserTag) | ||
} | ||
private addTag(tag: Tag): void { | ||
this.testInfo.annotations.push({ type: tag.type, description: tag.name }); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71
154307
2332
+ Added@noble/hashes@1.6.0(transitive)
+ Added@serenity-js/assertions@3.3.0(transitive)
+ Added@serenity-js/core@3.3.0(transitive)
+ Added@serenity-js/playwright@3.3.0(transitive)
+ Added@serenity-js/web@3.3.0(transitive)
- Removed@noble/hashes@1.6.1(transitive)
- Removed@serenity-js/assertions@3.2.1(transitive)
- Removed@serenity-js/core@3.2.1(transitive)
- Removed@serenity-js/playwright@3.2.1(transitive)
- Removed@serenity-js/web@3.2.1(transitive)
Updated@playwright/test@^1.34.3
Updated@serenity-js/core@3.3.0
Updated@serenity-js/web@3.3.0