Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playwright: Possible to specify either number of workers or the browser for 1 test only?

Tags:

playwright

I have my suite set up to run against 4 browsers using 3 workers (2 desktops and 2 mobile) I have a test that I need to either not run in parallel or limit to just run in one desktop browser.

Is that possible?

The reason I need to do this is that the test is triggering an event that can take a few seconds to run, when running nobody else can start this event so if 3 tests are running at once only the first one can pass. Also, on mobile, you can't trigger the event, so I skip parts of the test if isMobile is true.

Ideally, I'd like to just run this test in Firefox and leave the rest of the suite running in 3 workers with 4 browsers.

I looked at test.describe.configure({ mode: 'serial' }); but that doesn't seem to make a difference I still see

Running 4 tests using 3 workers

when I try just running this single spec file.

like image 621
Doctor Who Avatar asked Oct 21 '25 20:10

Doctor Who


1 Answers

There are actually multiple ways to conditionally skip tests based off a condition like browserName being Firefox - which one you might choose depends on your goal, setup, and/or criteria:

  • Project level:
    • Separating out those tests into separate directories, and specifying directory in your projects
    • Separating them into their own files, and telling projects to match or ignore them
    • Tagging tests within files, using grep to tell projects which to run or invert to not run
  • File level using annotations with test.skip
    • Conditionally skipping per test, whether within the test or in the beforeEach
    • Conditionally skipping all tests in a file or within a describe group, even containing single tests
  • Probably others

Based on what I understand to be your ideal setup and having just the one test within one file, I would probably recommend the whole file skip, so that not only would any beforeEach not run, but also any custom fixture setup required by the test wouldn’t run I imagine either. So something like the below before your test:

test.skip(({ browserName }) => browserName !== 'firefox');

And in the chance one of your mobile browsers is also Firefox, may need the isMobile check too. (Or actually, since apparently isMobile is not supported by Firefox, could probably check the hasTouch option instead)

Of course, choose whichever approach works best for you and your tests!

Hope that helps!

like image 50
David R Avatar answered Oct 27 '25 05:10

David R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!