Sponsored Link
Looking for a unified way to  viewmonitor, and  debug Playwright Test Automation runs?
Try the Playwright Dashboard by today. Use the coupon code PWSOL10 for a 12 month 10% discount.

What's an easy way to tell how many Playwright Tests I can comfortably run in parallel?

The good news, is by default Playwright takes a stab at running tests in parallel based on your computer specs. The even better news is you may be able to get faster feedback when running your Playwright Tests by increasing or decreasing the worker count.

You can learn a whole lot by reading the docs on Parallelism and Sharding, but if you want a quick and easy way to see how many workers is optimal for your computer or a computer in the cloud, it's as easy as running this command.

for i in `seq <min> <max>`; do time npx playwright test --reporter=line --workers=$i; done

Change <min> to be your # of CPUs divided by 2, and <max> to be # of CPUs times 2. This command will kick off your suite of playwright tests with different workers passed in (iterating through min/max). The output will be returned via the command line. And note, depending on your min/max inputs and how many tests you have, this process could take some time. So go kick it off and go brew some ☕️ or 🫖. Once the run is complete you should have an output that looks like this.

The test runs with 3, 5, and 6 runs were all the shortest runs. The key is to find the winner, fasters run that doesn't introduce any flakey tests. My default is 4 and looking the the results I would probably go ahead and stick with that.

I could see this script coming in very handy, when trying to run the playwright tests on AWS EC2 instances or other servers in the cloud.