Playwright - Jenkins
Running Playwright tests in parallel with Jenkins and Currents Dashboard
Here's an example of Jenkins pipeline that is running Playwright tests in parallel on 2 workers.
The pipeline will be running 2 workers, based on mcr.microsoft.com/playwright:v1.34.0-jammy Docker image. Those workers will run all the tests in parallel.
The steps are:
Use
mcr.microsoft.com/playwright:v1.34.0-jammyas the base imageInstall the necessary dependencies:
playwrightand@currents/playwrightPopulate the environment variable
CURRENTS_RECORD_KEYusing Jenkins Credentials Store. Learn more about Record KeyPopulate the environment variable
CURRENTS_PROJECT_IDusing Jenkins Credentials Store.Run Playwright tests on 2 workers, using CI Build ID for "connecting" the workers to the same parallel run. See CI Build ID.
npx pwc --key CURRENTS_RECORD_KEY --project-id CURRENTS_PROJECT_ID --ci-build-id ${env.BRANCH_NAME}-${env.BUILD_ID}"Here's the full Jenkins pipeline configuration file:
pipeline {
agent {
// this image provides everything needed to run Playwright
docker {
image 'mcr.microsoft.com/playwright:v1.34.0-jammy'
}
}
stages {
// installs node dependencies
stage('build') {
steps {
echo "Running build ${env.BUILD_ID} on ${env.JENKINS_URL}"
sh 'npm install playwright @currents/plawyright'
}
}
// this stage runs Playwright tests, and each agent uses the workspace
// from the previous stage
stage('Playwright parallel tests') {
environment {
// see https://jenkins.io/doc/book/using/using-credentials/
CURRENTS_RECORD_KEY = credentials('currents-record-key')
CURRENTS_PROJECT_ID = credentials('currents-project-id')
}
// Run parallel workers, see:
// https://jenkins.io/doc/book/pipeline/syntax/#parallel
parallel {
// each worker is running the same command,
stage('tester A') {
steps {
echo "Running build ${env.BUILD_ID}"
sh "npx pwc --key ${env.CURRENTS_RECORD_KEY} --project-id ${env.CURRENTS_RECORD_KEY} --ci-build-id ${env.BRANCH_NAME}-${env.BUILD_ID} --shard 1/2 --output test-results/shard-1"
}
}
// second tester runs the same command
stage('tester B') {
steps {
echo "Running build ${env.BUILD_ID}"
sh "npx pwc --key ${env.CURRENTS_RECORD_KEY} --project-id ${env.CURRENTS_RECORD_KEY} --ci-build-id ${env.BRANCH_NAME}-${env.BUILD_ID} --shard 2/2 --output test-results/shard-2"
}
}
}
}
}
}Using last failed flag with shards and orchestration
We have made available a public repository with an example of how to setup last failed functionality using shards and orchestration in different machines.
Here you will be able to find the following Jenkinsfile that accepts two parameters:
A CI Build ID from a previous run that you can use to apply the
--last-failedflag. If this parameter is set, then the pipeline will automatically apply this tag and only run the failed tests from that run if found.A checkbox for knowing if you want to run an orchestrated run. If so, the pipeline will use
pwc-pcommand instead ofpwc.

In order to use the --last-failed flag, in addition to the project ID and record key, a Currents API key is needed (You can find it in the API Keys section in your dashboard).
Also, within the Jenkinsfile you can set different values as env variables for the total amount of shards TOTAL_SHARDS or the number of parallel jobs for orchestration PARALLEL_JOBS.
Last updated
Was this helpful?