[Feature] tags API
Currently adding tags is only possible by inserting them into test title, e.g.:
test('Test login page @fast @mobile', async ({ page }) => {
// ...
});
It may have some downsides for reporting when you get very long titles, see https://github.com/microsoft/playwright/issues/17375
Suggestion is to introduce test.tags() method that will add tags to current test without altering the title:
test.tags('@fast', '@mobile');
test('Test login page', async ({ page }) => {
// ...
});
I'm posting how this is solved in Cypress for a quick reference.
// ...
it('works as an array', { tags: ['config', 'some-other-tag'] }, () => {
expect(true).to.be.true
})
// ...
Source: https://github.com/cypress-io/cypress/tree/develop/npm/grep
I would also prefer:
test.tags('@fast', '@mobile');
test('Test login page', async ({ page }) => {
// ...
});
instead of:
// ...
it('works as an array', { tags: ['config', 'some-other-tag'] }, () => {
expect(true).to.be.true
})
// ...
because in cypress solution its again in the "testtitle" or lets say the same line ofc you can break the line here but you would have just have a ugly looking async function instead.
also test.tags is really great to reminding instead of a object passed in the testfunction as argument
If anyone is in a rush with separating tags and the title in spec files, tests could also be decorated in this way with a bit of custom code.
tags(['@describe']).describe('describe', async () => {
tags(['@test']).test('test', async () => {})
})
I wonder if it's even possible to code this feature exactly as suggested.
If anyone is in a rush with separating tags and the title in spec files, tests could also be decorated in this way with a bit of custom code.
tags(['@describe']).describe('describe', async () => { tags(['@test']).test('test', async () => {}) })I wonder if it's even possible to code this feature exactly as suggested.
Thats really wierd. I thought evertime for now that "tags" are under the suite coded. but here "tags" are a class above "describe"? But really hope here for native solution like described above.
I estimate that the new tag syntax will not break the existing tags, but will be weird to find some tests using:
test.tags('@fast', '@mobile');
test('Test login page', async ({ page }) => {
// ...
});
And others with:
test('Test login page @fast @mobile', async ({ page }) => {
// ...
});
Is there going to be a way to update old tests to use the new syntax via some command? For instance, --update-tags
The way Playwright works, this solution will require putting all tests in describe blocks if multiple tests will have different tags in the spec file. It will be a bit annoying.
test.tags('@fast', '@mobile');
test('Test login page', async ({ page }) => {
// ...
});
The way Playwright works, this solution will require putting all tests in describe blocks if multiple tests will have different tags in the spec file. It will be a bit annoying.
test.tags('@fast', '@mobile'); test('Test login page', async ({ page }) => { // ... });
@dgozman could you open some details how tags API will look like, if you already agreed on that? :)