Skip to content

Commit

Permalink
feat(playwright-test): improved requirements reporting
Browse files Browse the repository at this point in the history
improved reporting for nested requirements hierarchies
  • Loading branch information
jan-molak committed Jan 24, 2024
1 parent 4e2f1e3 commit 3b99112
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 26 deletions.
4 changes: 3 additions & 1 deletion integration/playwright-test/spec/cast.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integration/testing-tools';
import { ActivityRelatedArtifactGenerated, InteractionStarts, SceneFinished, SceneStarts, SceneTagged } from '@serenity-js/core/lib/events';
import { ExecutionSuccessful, FeatureTag, Name } from '@serenity-js/core/lib/model';
import { CapabilityTag, ExecutionSuccessful, FeatureTag, Name } from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';

import { playwrightTest } from '../src/playwright-test';
Expand All @@ -20,6 +20,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A screenplay scenario receives an actor with default abilities')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test configuration')))
.next(InteractionStarts, event => expect(event.details.name).to.equal(new Name(`Alice logs: 'GenericCast'`)))
.next(InteractionStarts, event => expect(event.details.name).to.equal(new Name(`Alice logs: 'BrowseTheWebWithPlaywright'`)))
Expand All @@ -38,6 +39,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A screenplay scenario receives an actor from a custom cast')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test configuration')))
.next(InteractionStarts, event => expect(event.details.name).to.equal(new Name(`Alice logs: a note of contextOptions`)))
.next(ActivityRelatedArtifactGenerated, event => {
Expand Down
8 changes: 7 additions & 1 deletion integration/playwright-test/spec/failing_scenarios.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integratio
import { AssertionError, LogicError, TestCompromisedError } from '@serenity-js/core';
import { SceneFinished, SceneStarts, SceneTagged, TestRunnerDetected } from '@serenity-js/core/lib/events';
import { trimmed } from '@serenity-js/core/lib/io';
import { ExecutionCompromised, ExecutionFailedWithAssertionError, ExecutionFailedWithError, FeatureTag, Name, ProblemIndication } from '@serenity-js/core/lib/model';
import { CapabilityTag, ExecutionCompromised, ExecutionFailedWithAssertionError, ExecutionFailedWithError, FeatureTag, Name, ProblemIndication } from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';

import { playwrightTest } from '../src/playwright-test';
Expand All @@ -19,6 +19,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A scenario fails when an error is thrown')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('failing')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(SceneFinished, event => {
Expand All @@ -38,6 +39,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A scenario fails when the assertion fails')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('failing')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(SceneFinished, event => {
Expand Down Expand Up @@ -66,6 +68,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A scenario fails when the assertion fails')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('failing')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(SceneFinished, event => {
Expand All @@ -89,6 +92,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A scenario fails when the assertion fails')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('failing')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(SceneFinished, event => {
Expand Down Expand Up @@ -119,6 +123,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A scenario is compromised')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('failing')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(SceneFinished, event => {
Expand All @@ -144,6 +149,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A scenario is marked as failing, but passes')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('failing')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(SceneFinished, event => {
Expand Down
6 changes: 5 additions & 1 deletion integration/playwright-test/spec/native_page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TestRunnerDetected,
TestRunStarts
} from '@serenity-js/core/lib/events';
import { CorrelationId, ExecutionSuccessful, FeatureTag, Name } from '@serenity-js/core/lib/model';
import { CapabilityTag, CorrelationId, ExecutionSuccessful, FeatureTag, Name } from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';

import { playwrightTest } from '../src/playwright-test';
Expand All @@ -31,6 +31,7 @@ describe('@serenity-js/playwright-test', function () {
expect(event.details.name).to.equal(new Name('A screenplay scenario receives a page object associated with the default actor'));
currentSceneId = event.sceneId;
})
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test integration')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))

Expand Down Expand Up @@ -60,6 +61,7 @@ describe('@serenity-js/playwright-test', function () {
expect(event.details.name).to.equal(new Name('A screenplay scenario allows for interactions with the page object to change the state of the page associated with the actor'));
currentSceneId = event.sceneId;
})
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test integration')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))

Expand Down Expand Up @@ -89,6 +91,7 @@ describe('@serenity-js/playwright-test', function () {
expect(event.details.name).to.equal(new Name(`A screenplay scenario registers the native page with actor's BrowsingSession`));
currentSceneId = event.sceneId;
})
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test integration')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))

Expand Down Expand Up @@ -118,6 +121,7 @@ describe('@serenity-js/playwright-test', function () {
expect(event.details.name).to.equal(new Name(`A screenplay scenario tracks newly opened pages`));
currentSceneId = event.sceneId;
})
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test integration')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))

Expand Down
3 changes: 2 additions & 1 deletion integration/playwright-test/spec/no_describe_blocks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integration/testing-tools';
import { Timestamp } from '@serenity-js/core';
import { SceneStarts, SceneTagged, TestRunFinished, TestRunFinishes, TestRunnerDetected, TestRunStarts } from '@serenity-js/core/lib/events';
import { Category, FeatureTag, Name } from '@serenity-js/core/lib/model';
import { CapabilityTag, Category, FeatureTag, Name } from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';

import { playwrightTest } from '../src/playwright-test';
Expand Down Expand Up @@ -43,6 +43,7 @@ describe('@serenity-js/playwright-test', function () {
expect(event.details.name).to.equal(new Name('has no describe blocks'));
expect(event.details.category).to.equal(new Category('nested/another-no-describe-blocks.spec.ts'));
})
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('nested')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('nested/another-no-describe-blocks.spec.ts')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integration/testing-tools';
import { Timestamp } from '@serenity-js/core';
import { SceneFinished, SceneFinishes, SceneStarts, SceneTagged, TestRunFinished, TestRunFinishes, TestRunnerDetected, TestRunStarts } from '@serenity-js/core/lib/events';
import { CorrelationId, ExecutionSuccessful, FeatureTag, Name } from '@serenity-js/core/lib/model';
import { CapabilityTag, CorrelationId, ExecutionSuccessful, FeatureTag, Name,ThemeTag } from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';

import { playwrightTest } from '../src/playwright-test';

describe('@serenity-js/playwright-test', function () {

it('recognises a passing scenario', () => playwrightTest('--project=default', 'passing.spec.ts')
it('emits requirement tags so that Serenity BDD can aggregate them correctly', () => playwrightTest('--project=default', 'my_super_theme/my_theme/my_capability/my_feature.spec.ts')
.then(ifExitCodeIsOtherThan(0, logOutput))
.then(result => {

Expand All @@ -22,7 +22,10 @@ describe('@serenity-js/playwright-test', function () {
expect(event.details.name).to.equal(new Name('A scenario passes'));
currentSceneId = event.sceneId;
})
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(SceneTagged, event => expect(event.tag).to.equal(new ThemeTag('my_super_theme')))
.next(SceneTagged, event => expect(event.tag).to.equal(new ThemeTag('my_theme')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('my_capability')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('My feature')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))

// triggered by requiring actorCalled
Expand Down
7 changes: 6 additions & 1 deletion integration/playwright-test/spec/screenplay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integration/testing-tools';
import { AsyncOperationAttempted, AsyncOperationCompleted, InteractionFinished, InteractionStarts, SceneFinished, SceneStarts, SceneTagged, TestRunnerDetected } from '@serenity-js/core/lib/events';
import { trimmed } from '@serenity-js/core/lib/io';
import { CorrelationId, Description, ExecutionFailedWithAssertionError, ExecutionFailedWithError, ExecutionSuccessful, FeatureTag, Name, ProblemIndication } from '@serenity-js/core/lib/model';
import { CapabilityTag, CorrelationId, Description, ExecutionFailedWithAssertionError, ExecutionFailedWithError, ExecutionSuccessful, FeatureTag, Name, ProblemIndication } from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';

import { playwrightTest } from '../src/playwright-test';
Expand All @@ -27,6 +27,7 @@ describe('@serenity-js/playwright-test', function () {
expect(event.details.name).to.equal(new Name('A screenplay scenario propagates events to Serenity reporter'));
currentSceneId = event.sceneId
})
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(InteractionStarts, event => {
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('@serenity-js/playwright-test', function () {
.next(SceneStarts, event => {
expect(event.details.name).to.equal(new Name('A screenplay scenario supports multiple actors'))
})
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))

Expand Down Expand Up @@ -114,6 +116,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A screenplay scenario correctly reports assertion errors')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(SceneFinished, event => {
Expand Down Expand Up @@ -142,6 +145,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A screenplay scenario fails when discarding an ability fails')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(SceneFinished, event => {
Expand All @@ -166,6 +170,7 @@ describe('@serenity-js/playwright-test', function () {

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A screenplay scenario fails when discarding an ability fails')))
.next(SceneTagged, event => expect(event.tag).to.equal(new CapabilityTag('screenplay')))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Playwright Test reporting')))
.next(TestRunnerDetected, event => expect(event.name).to.equal(new Name('Playwright')))
.next(SceneFinished, event => {
Expand Down
Loading

0 comments on commit 3b99112

Please sign in to comment.