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
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.
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_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.
If you still have questions, please ask a question and I will try to answer it.
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 email@example.com.