playwright
playwright copied to clipboard
Update test title using test.extend.
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
.
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`
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
.
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.
Doesnt work. When running tests, get an error Error: No tests found
.
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)
Closing as per above. I don't think we'll be implementing the original feature request.