playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Add annotations for test.step similar to test

Open jithinjosejacob opened this issue 3 years ago • 37 comments

Currently skip option is available on test case level(https://playwright.dev/docs/test-annotations)

But there is no skip /similar annotations in test step level

Expected

test.step.skip test.step.only test.step.fail (https://github.com/microsoft/playwright/issues/10033)

jithinjosejacob avatar Nov 04 '21 04:11 jithinjosejacob

Sometimes there may be a reason to skip a step, especially if that step is just for checking content, i.e. test.expect

For example

test("update profile", async function () {
	test.step("update");
	test.step.skip("check part A"); // part A currently disabled due to frontend bugs
	test.step("check part B");
})

it's better than commenting out the step

A-ZC-Lau avatar Jun 29 '22 04:06 A-ZC-Lau

I have a situation where one test step works on chromium and firefox but fails on WebKit due to the latest trunk build for the playwright WebKit browser. I would like to skip the test step just for WebKit and only that step since the other ones work fine for all of the browsers. Having annotations added to the test.step() level and not just the parent level test() method would substantially help to organize and provide correct results for reporting without having to add if/else conditionals all over the test file.

amauch-adobe avatar Mar 29 '23 20:03 amauch-adobe

test.step.skip in reports:

Total steps: x
Skipped: y

❤️

kumarchandresh avatar Apr 20 '23 08:04 kumarchandresh

And my usecase

await test.step('#4 - type unique keyword(BUG:EP-26957)', async () => {
            const uniqueKeyword = subForm2.NAME;
            await formScreen.subformDropdownMenuSearchInput.fill(uniqueKeyword);

            // await expect.soft(formScreen.subformDropdownMenuItem).toHaveText(uniqueKeyword);// restore after fixing https://company.atlassian.net/browse/EP-26957
        });

sergtimosh avatar Dec 06 '23 14:12 sergtimosh

Sometimes there may be a reason to skip a step, especially if that step is just for checking content, i.e. test.expect

For example

test("update profile", async function () {
	test.step("update");
	test.step.skip("check part A"); // part A currently disabled due to frontend bugs
	test.step("check part B");
})

it's better than commenting out the step

Totally agree

aandrieiev1998 avatar Dec 14 '23 11:12 aandrieiev1998

Adding my vote! I just went to skip a new test step and discovered that there was no such option. I just expected it would be there, its intuitive that it would exist.

craigcote avatar Dec 14 '23 22:12 craigcote

This is definitely a valuable feature. My use case is for a step that does not work across all test environments at the moment so need to skip it to avoid unnecessary test failures.

mascarion avatar Dec 22 '23 16:12 mascarion

I have been recently working to improve our end-to-end tests at my company, and a lot of good work's been done. Only thing I am missing is having the ability to just test.step.skip instead of commenting it out.

I reckon there has to be a temporary way to be able to implement it ourselves, till Playwright officially adds it. I am not looking for being able to pass a condition into test.step like we have for test.

Just adding a .skip should skip that step without supplying a condition.

hitarthdesai avatar Jan 05 '24 22:01 hitarthdesai

Another use case: We use skipped tests in our daily smoke testing reporting to see which tests we know are currently disabled (because they found a bug that is currently being worked on, and we disable the tests to not have red pipelines all the times, until the bug is fixed).

It would be super helpful to only disable some steps of a test that perform the checks for the things that are currently broken, have the rest of the test still being executed, and getting this "test X step Y was skipped" message in the reports

ErikBrendel avatar Jan 30 '24 14:01 ErikBrendel

Another +1 for this please

Use case: We have different product types that we define in env variables and pass to skip tests:

PRODUCT_TYPE=foo npx playwright test

Having an option to conditionally skip a step would be really helpful. Such as:

await test.step('My test title', async () => {
    step.skip(process.env.PRODUCT_TYPE === 'foo');
    await testPage.myTestName();
});

Thanks :)

cctui-dev avatar Feb 05 '24 16:02 cctui-dev

+1 For this request, would be super useful.

ph624723 avatar Mar 08 '24 12:03 ph624723

+1 very handy ask, I do not want to skip the entire test just skip the test.step that is looking for a specific context in the whole test aka, a button can have 4 different classes, I'd like to test.step each class scenario but skip it if on an entire grid of which there are many assigned classes, if 1/4 classes are not present, skip the test.step targeting them. it would be handy

kylebradshaw avatar Mar 08 '24 21:03 kylebradshaw

This would be super helpful so voting this to get added as well.

LeTiina avatar Apr 10 '24 11:04 LeTiina

another +1, would be really helpful

ch4r-ch4r avatar Apr 25 '24 22:04 ch4r-ch4r

another +1, would be really helpful if we can skip a test with or without condition

TamalikaChakraborty avatar Apr 29 '24 03:04 TamalikaChakraborty

+1

kp-abhishek-agrawal avatar May 06 '24 09:05 kp-abhishek-agrawal

+1 this is needed.

GoranOst avatar May 10 '24 19:05 GoranOst

+1

roby-rodriguez avatar May 13 '24 14:05 roby-rodriguez

+1

IrfanSyed-PSC avatar May 13 '24 19:05 IrfanSyed-PSC

+1

iEnergyy avatar May 28 '24 14:05 iEnergyy

+1

bohdanhulobov avatar May 31 '24 08:05 bohdanhulobov

Please, lets just add 👍 reaction to the first message.

vitalets avatar May 31 '24 10:05 vitalets

Could you help me understand why the following notation is not solving this request?

condition && await test.step('my step', async () => {
  ...
});

pavelfeldman avatar Aug 02 '24 21:08 pavelfeldman

Could you help me understand why the following notation is not solving this request?

That approach is viable and something I've personally used but I do think a dedicated method does provide a bit cleaner syntax. I wonder what the motivations for test.skip originally were, I am sure there would be some crossover here.

On another note, that kind of conditional logic is also seemingly against recommend best practices and flags warnings for me. However I am aware that's a bit of a "six of one, half a dozen of the other" scenario.

quoid avatar Aug 03 '24 02:08 quoid

@pavelfeldman

condition && await test.step('my step', async () => {
  ...
});

will not show in reports. Visibility over what was run is one of the good characteristics of Playwright. If something was skipped, reports should reflect it.

kumarchandresh avatar Aug 06 '24 08:08 kumarchandresh

@quoid

I wonder what the motivations for test.skip originally were

Just like test.skip gives finer control over which tests execute based on certain conditions that can be evaluated at runtime. In the same way, step.skip will give finer control over which steps contribute towards the test based on some conditions that can be evaluated at runtime.

There are times where one may want to skip a step from executing when run in a different (but similar) environment. Some steps may not be applicable or become additional steps depending upon the execution environment. I would not want to maintain two copies of similar test with minor differences.

kumarchandresh avatar Aug 06 '24 08:08 kumarchandresh