Rayrun

How do I set up Playwright test parallelization in Bitbucket Pipelines?

Answer

Implementing Playwright Parallelization in Bitbucket Pipelines

To start, you'll need to use the public Docker image provided by Playwright: mcr.microsoft.com/playwright:v1.35.0-jammy. This image has all the dependencies you need to run Playwright tests.

In your Bitbucket Pipelines configuration file, specify the Playwright Docker image as the build environment using the image keyword:

image: mcr.microsoft.com/playwright:v1.35.0-jammy

Next, define a stage for running your Playwright tests, like "e2e-tests". You can use the sh command to execute shell commands:

stages:
  - e2e-tests

pipelines:
  default:
    - step:
        name: Run Playwright Tests
        script:
          - sh 'npm ci'
          - sh 'npx playwright test'

By default, your tests will run sequentially. To enable parallelization and split your tests into smaller jobs that run in parallel, use Bitbucket Pipelines' support for parallel execution.

Add a parallel keyword under the tests section of your pipeline configuration to specify how many parallel jobs should be created:

pipelines:
  default:
    - step:
        name: Run Parallelized Playwright Tests
        script:
          - sh 'npm ci'
          - sh 'npx playwright test --shard=$BITBUCKET_PARALLEL_STEP/$BITBUCKET_PARALLEL_TOTAL'

Bitbucket Pipelines automatically sets the $BITBUCKET_PARALLEL_STEP and $BITBUCKET_PARALLEL_TOTAL environment variables when running in parallel mode. Each job will have a unique value for $BITBUCKET_PARALLEL_STEP, ranging from 1 to the total number of parallel jobs specified by $BITBUCKET_PARALLEL_TOTAL. You can use this value in your Playwright test command to shard the tests accordingly.

For more details on maximizing test efficiency with parallelism in Playwright, check out this blog post.

References

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Discord Threads

Related Questions

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.