microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.59k stars 3.57k forks source link

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

Open jithinjosejacob opened 2 years ago

jithinjosejacob commented 2 years ago

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

A-ZC-Lau commented 2 years ago

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

amauch-adobe commented 1 year ago

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.

kumarchandresh commented 1 year ago

test.step.skip in reports:

Total steps: x
Skipped: y

❤️

sergtimosh commented 9 months ago

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
        });
aandrieiev1998 commented 9 months ago

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

craigcote commented 9 months ago

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.

mascarion commented 8 months ago

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.

hitarthdesai commented 8 months ago

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.

ErikBrendel commented 7 months ago

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

cctui-dev commented 7 months ago

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

ph624723 commented 6 months ago

+1 For this request, would be super useful.

kylebradshaw commented 6 months ago

+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

LeTiina commented 5 months ago

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

ch4r-ch4r commented 4 months ago

another +1, would be really helpful

TamalikaChakraborty commented 4 months ago

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

kp-abhishek-agrawal commented 4 months ago

+1

GoranOst commented 4 months ago

+1 this is needed.

roby-rodriguez commented 4 months ago

+1

IrfanSyed-PSC commented 4 months ago

+1

iEnergyy commented 3 months ago

+1

bohdanhulobov commented 3 months ago

+1

vitalets commented 3 months ago

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

pavelfeldman commented 1 month ago

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

condition && await test.step('my step', async () => {
  ...
});
quoid commented 1 month ago

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.

kumarchandresh commented 1 month ago

@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 commented 1 month ago

@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.

robcsegal commented 2 weeks ago

This would be really good added benefit. I don't want to skip a whole test because one or two steps need to be skipped, especially when the rest of the test runs just fine.

sergius-cheremnich-swo commented 2 weeks ago

+1