Skip to content

Commit

Permalink
Support Playwright 1.39
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Oct 13, 2023
1 parent 9b90209 commit 57920a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* i18n: Generate scenario outlines correctly [#60](https://github.com/vitalets/playwright-bdd/issues/60).
* Check for duplicate fixture names [#52](https://github.com/vitalets/playwright-bdd/issues/52)
* Fix flushing logs for several projects [#59](https://github.com/vitalets/playwright-bdd/issues/59)
* Support Playwright `1.39`.

## 5.3.0
* Add support for Playwright `1.38`.
Expand Down
19 changes: 19 additions & 0 deletions src/playwright/testTypeImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ export function getTestImpl(test: TestTypeCommon) {
return test[testTypeSymbol] as any;
}

/**
* Run step with location pointing to Given, When, Then call.
*/
// eslint-disable-next-line max-params
export async function runStepWithCustomLocation(
test: TestTypeCommon,
stepText: string,
location: Location,
body: () => unknown,
) {
const testInfo = test.info();

// See: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/common/testType.ts#L221
// @ts-expect-error _runAsStep is hidden from public
return testInfo._runAsStep({ category: 'test.step', title: stepText, location }, async () => {
return await body();
});
}

/**
* Returns true if all fixtures of parent test found in child test.
*/
Expand Down
8 changes: 5 additions & 3 deletions src/run/bddWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ISupportCodeLibrary } from '@cucumber/cucumber/lib/support_code_library
import { PickleStep } from '@cucumber/messages';
import { findStepDefinition } from '../cucumber/loadSteps';
import { getLocationInFile } from '../playwright/getLocationInFile';
import { getTestImpl } from '../playwright/testTypeImpl';
import { runStepWithCustomLocation } from '../playwright/testTypeImpl';
import { TestTypeCommon } from '../playwright/types';
import { getStepCode } from '../stepDefinitions/defineStep';

Expand Down Expand Up @@ -50,7 +50,8 @@ export class BddWorld<ParametersType = any> extends CucumberWorld<ParametersType
this.customFixtures = customFixtures;
const code = getStepCode(stepDefinition);

// get location of step call in generated test file
// Get location of step call in generated test file.
// This call must be exactly here to have correct call stack.
const location = getLocationInFile(this.test.info().file);

const { parameters } = await stepDefinition.getInvocationParameters({
Expand All @@ -59,9 +60,10 @@ export class BddWorld<ParametersType = any> extends CucumberWorld<ParametersType
world: this,
});

const res = await getTestImpl(this.test)._step(location, text, () =>
const res = await runStepWithCustomLocation(this.test, text, location, () =>
code.apply(this, parameters),
);

delete this.customFixtures;

return res;
Expand Down

0 comments on commit 57920a2

Please sign in to comment.