Playwright Parameterized Projects

Profile picture for user arilio666
Submitted by arilio666 on

Playwright Parameterized Projects is a feature of the Playwright tool that allows you to run multiple script instances with different parameters. 

With this feature, you can define a set of parameters for each run and then use those parameters in your script.  This can be useful for running tests with different configurations or performance tests with varying load levels. It also supports multiple running projects at the same time.

Let us see in the action how it can be done.

1.) Create A JS Test File.

const {test, expect}  = require('@playwright/test')
exports.test = {test, expect}.test.extend({
 userName: ['Naruto', { option: true }],
  • Here we have imported the playwright and extended it to other specs to be visible.

2.) Import In Spec

const { expect } = require('@playwright/test');
const { test } = require('./test-man');

test('Parameterized Testing With', async ({page, userName})=> 
   await page.goto('');
   await page.locator('#edit-name').fill(userName)
   await expect(page.locator('#edit-name')).toContainText(userName)
  • Doing this allows us to parameterize the userName and use it in every project.
  • We can also define the parameters and access them from the config.js file.
const config = {
 projects: [
     name: 'dave',
     use: { person: 'Dave' },
     name: 'manny',
     use: { person: 'Manny' },
module.exports = config;
  • We can configure these inside the project config and access them from spec.
  • We can also parameterize inside the js file too directly.
const {test, expect}  = require('@playwright/test')
exports.test = {test, expect}.test.extend({
 userName: ['Itachi', { option: true }],
 page: async ({ page, userName }, use) => {
   await page.goto('');
await page.locator('#edit-name').fill(userName)  },
  • This way, we can parameterize projects easily using the playwright's provided method.
  • Multiple parameters are run efficiently in separate projects, with each value set in the config file.