playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] tags API

Open vitalets opened this issue 2 years ago • 1 comments

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 }) => {
  // ...
});

vitalets avatar May 20 '23 12:05 vitalets

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

gskierk avatar May 20 '23 15:05 gskierk

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

Kranael avatar May 31 '23 20:05 Kranael

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.

gskierk avatar May 31 '23 21:05 gskierk

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.

Kranael avatar May 31 '23 21:05 Kranael

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

brunojbarros avatar Nov 12 '23 10:11 brunojbarros

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 }) => {
  // ...
});

MindaugasMateika avatar Dec 11 '23 11:12 MindaugasMateika

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? :)

vitalets avatar Dec 11 '23 17:12 vitalets