playwright icon indicating copy to clipboard operation
playwright copied to clipboard

Update test title using test.extend.

Open quldude opened this issue 1 year ago • 5 comments

Is there a way to override the test tile to add a tag using test.extend? For eg instead of writing test('test title @tag', ...), I would like to extend test function to auto add that @tag.

quldude avatar May 19 '23 13:05 quldude

This method is not designed to modify the test title.

Could you provide more context about your use case? If you want to add the tag to all of the tests, then this particular tag would become useless.

If you want to add tags only to your chosen tests just by changing the imported test instance (from import { test } from '@playwright/test' to import { test } from './custom-test'), then you can achieve the same by adding custom function and using it on demand.

// addTag.js

export const addTag = (title) => `${title} @tag`

gskierk avatar May 19 '23 13:05 gskierk

I want to add the same tag to a custom test function automatically and be able to execute playwright command using --grep @tag. For eg: if I call a custom test function customTest('test title', ...), customTest should automatically append the tag @tag to the title, ie, new title = test title @tag.

quldude avatar May 19 '23 14:05 quldude

Does this solution satisfy you?

const customTest = function(title, callback) {
  return test(`${title} @tag`, callback)
}

customTest.fixme = function(title, callback) {
  return test.fixme(`${title} @tag`, callback)
}

// etc.

gskierk avatar May 19 '23 14:05 gskierk

Doesnt work. When running tests, get an error Error: No tests found.

quldude avatar May 19 '23 16:05 quldude

import { test } from '@playwright/test'

const customTest = function(title, callback) {
  return test(`${title} @tag`, callback)
}

customTest('title', async ({ page }) => {
  await page.goto('https://playwright.dev')
})

✓  1 [desktop] › test.spec.ts:3:43 › title @tag (1.3s)

gskierk avatar May 19 '23 17:05 gskierk

Closing as per above. I don't think we'll be implementing the original feature request.

dgozman avatar May 22 '23 15:05 dgozman