Skip to content

Commit

Permalink
feat(playwright): add support for testIdAttribute configuration (#2441)
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgegriff authored Jan 24, 2024
1 parent c65efbc commit d46133f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/artillery-engine-playwright/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const debug = require('debug')('engine:playwright');
const { chromium } = require('playwright');
const { chromium, selectors } = require('playwright');

class PlaywrightEngine {
constructor(script) {
Expand All @@ -21,6 +21,8 @@ class PlaywrightEngine {
this.config.defaultPageTimeout || this.config.defaultTimeout,
10
) || 30) * 1000;

this.testIdAttribute = this.config.testIdAttribute;

this.aggregateByName =
script.config.engines.playwright.aggregateByName || false;
Expand Down Expand Up @@ -84,6 +86,9 @@ class PlaywrightEngine {

context.setDefaultNavigationTimeout(self.defaultNavigationTimeout);
context.setDefaultTimeout(self.defaultTimeout);
if (self.testIdAttribute) {
selectors.setTestIdAttribute(self.testIdAttribute);
}
debug('context created');

const uniquePageLoadToTiming = {};
Expand Down
6 changes: 6 additions & 0 deletions packages/types/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ export type PlaywrightEngineConfig = {
* @title Default navigation timeout
*/
defaultNavigationTimeout?: number;
/**
* When set, changes the attribute used by locator `page.getByTestId` in Playwright.
* https://playwright.dev/docs/api/class-framelocator#frame-locator-get-by-test-id
* @title Test ID Attribute
*/
testIdAttribute?: string;
/**
* Aggregate Artillery metrics by test scenario name.
* https://www.artillery.io/docs/reference/engines/playwright#aggregate-metrics-by-scenario-name
Expand Down
5 changes: 5 additions & 0 deletions packages/types/schema/engines/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const PlaywrightConfigSchema = Joi.object({
.description(
'Default maximum navigation time (in seconds) for Playwright navigation methods, like `page.goto()`.\nhttps://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout'
),
testIdAttribute: Joi.string()
.meta({ title: 'Test ID Attribute'})
.description(
'When set, changes the attribute used by locator `page.getByTestId` in Playwright. \n https://playwright.dev/docs/api/class-framelocator#frame-locator-get-by-test-id'
),
extendedMetrics: artilleryBooleanOrString
.meta({ title: 'Playwright Extended Metrics' })
.description(
Expand Down

0 comments on commit d46133f

Please sign in to comment.