Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(playwright-test): nested error handling #1897

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ConfigurationError } from '@serenity-js/core';
import { describe, it } from '@serenity-js/playwright-test';

describe('Playwright Test reporting', () => {

describe('A scenario', () => {

it('fails with a Serenity/JS ConfigurationError', () => {
try {
throw new Error('Example nested error');
}
catch (error) {
throw new ConfigurationError('Example configuration error', error)
}
});
});
});
38 changes: 36 additions & 2 deletions integration/playwright-test/spec/failing_scenarios.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integration/testing-tools';
import { AssertionError, LogicError, TestCompromisedError } from '@serenity-js/core';
import { AssertionError, ConfigurationError, 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 {
ExecutionCompromised,
ExecutionFailedWithAssertionError,
ExecutionFailedWithError,
FeatureTag,
Name,
ProblemIndication
} from '@serenity-js/core/lib/model';
import { describe, it } from 'mocha';

import { playwrightTest } from '../src/playwright-test';
Expand Down Expand Up @@ -81,6 +88,33 @@ describe('@serenity-js/playwright-test', function () {
;
}));

it('fails with a Serenity/JS ConfigurationError', () => playwrightTest('--project=default', 'failing/failing-serenity-js-configuration-error.spec.ts')
.then(ifExitCodeIsOtherThan(1, logOutput))
.then(result => {

expect(result.exitCode).to.equal(1);

PickEvent.from(result.events)
.next(SceneStarts, event => expect(event.details.name).to.equal(new Name('A scenario fails with a Serenity/JS ConfigurationError')))
.next(SceneFinished, event => {
const outcome = event.outcome as ProblemIndication;
expect(outcome).to.be.instanceOf(ExecutionFailedWithError);

const error = outcome.error as ConfigurationError;

expect(error.name).to.equal('Error');
expect(error.message).to.equal('Example configuration error');

const stack = error.stack.split('\n');

expect(stack).to.include.members([
'ConfigurationError: Example configuration error',
'Error: Example nested error',
]);
})
;
}));

it('fails with a Serenity/JS Screenplay AssertionError', () => playwrightTest('--project=default', 'failing/failing-serenity-js-screenplay-assertion.spec.ts')
.then(ifExitCodeIsOtherThan(1, logOutput))
.then(result => {
Expand Down