Cross_Column

Monday, 8 June 2026

Jenkins Tutorials



Ultimate Jenkins CI/CD Guide for Playwright Python

Ultimate Jenkins CI/CD Guide for Playwright Python Frameworks

Welcome to way2testing.com! As modern test automation moves fully into the DevOps realm, executing your test framework inside a CI/CD pipeline is an absolute core skill. In this highly detailed, step-by-step masterclass series, we will walk through exactly how to take a Playwright Python automation framework featuring a custom testrunner.py execution file and integrate it seamlessly into Jenkins.


Topic 1: Introduction to Jenkins, Full Setup & Tool Optimization

Before jumping into execution scripts, we need to deploy Jenkins and adapt it specifically for executing clean automated browser sessions using Playwright Python.

Section 1.1: Comprehensive Step-by-Step Jenkins Installation

Step 1 → Download the Required Java Development Kit (JDK)

Jenkins is a Java-based application and requires a modern runtime environment. Go to the official Oracle website or adoptium.net and download JDK 17 or JDK 21 (LTS versions). Run the installer installer executable for your respective OS and configure your system environment variables by adding JAVA_HOME pointing to your installation directory.

Step 2 → Download the Official Jenkins Website Distribution Package

Navigate to the official website at jenkins.io/download. For ultimate stability across any local operating system environment, scroll down to the Generic Java package (.war) selection and download the jenkins.war package to a dedicated directory on your computer (e.g., C:\Jenkins\ or /opt/jenkins/).

Step 3 → Launch Jenkins via the Command Line Terminal

Open your command prompt (cmd) on Windows or terminal application on macOS/Linux. Use the change directory command (cd) to access the specific folder path containing your downloaded jenkins.war file. Execute the following baseline command to spin up the integrated web engine instance:

java -jar jenkins.war --httpPort=8080

Keep this command shell window entirely open! Jenkins will print out initialization text lines. Look closely for a long alpha-numeric key called the Setup Administrator Password generated in the console stream. Highlight and copy this string to your clipboard.

Step 4 → Complete the Onboarding Wizard in Your Browser

Open your web browser and navigate directly to the address: http://localhost:8080. Paste the Administrator password from your clipboard into the prompt field and click next. Choose the option titled "Install Suggested Plugins" to automatically pull down core modules like Git and basic UI components. Finally, create your personalized admin profile login account credentials.

Section 1.2: Mastering Headed vs. Headless Mode Execution

By default, Playwright executes browser engines in headless mode (meaning no actual UI windows pop open). This is highly optimized for CI engines since Jenkins nodes frequently run on server architectures devoid of graphics hardware.

However, if your framework overrides this configurations via a parameter to run in headed mode, running it on an unconfigured Linux machine or isolated server environment will instantly trigger execution failures due to missing display outputs. To bypass this:

  • For Headless (Best Practice): Ensure your testrunner.py invokes context initializations using the argument headless=True.
  • For Headed on Server Nodes: If you absolutely must watch browser behaviors inside server logs, you must install the Xvfb (X Virtual Framebuffer) Plugin via the Jenkins dashboard. This acts as a virtual monitor layout space directly within the background system infrastructure.

Section 1.3: Installing Core Automation Plugins

How to Install Core Plugins
  1. Click on Manage Jenkins from your left menu dashboard column.
  2. Select the option labeled Plugins, then switch active views over to the Available plugins tab section.
  3. Search for the following plugins and tick their checkboxes:
    • Git Plugin: Controls codebase repository checkouts.
    • HTML Publisher Plugin: Displays your framework HTML reports embedded inside Jenkins pages.
    • AnsiColor: Formats complex Python terminal print statements with vibrant logging text colors.
  4. Click Install without restart (or download and restart after compilation concludes).

Topic 2: Connecting Jenkins to Source Control (GitHub / Bitbucket)

Your pipeline must pull source updates cleanly from your remote source code control system directly into isolated build workspace directories.

Section 2.1: Generating Authentication Token Credentials

Do not use your standard text account profile passwords inside Jenkins config fields! Instead, create a secure access pathway:

  • GitHub Configuration: Go to Settings → Developer Settings → Personal Access Tokens → Tokens (classic). Click Generate Token, check the specific scope authorization for repo access, and copy down the secret hash string.
  • Bitbucket Configuration: Go to Personal Settings → App Passwords → Create App Password. Toggle explicit read/write repository rights and note the resulting credential token.

Section 2.2: Storing Credentials Inside the Jenkins Security Vault

Step-by-Step Vault Setup
  1. Navigate to the top dashboard view and enter Manage JenkinsCredentials.
  2. Select the (global) domain link, then hit the top-right button labeled Add Credentials.
  3. Set the overall configuration kind to Username with password.
  4. In the Username input box, write out your exact GitHub/Bitbucket email profile identifier.
  5. In the Password input field, paste your generated Access Token or App Password.
  6. Assign a meaningful, identifiable label name into the ID attribute block (e.g., github-framework-token) and save.

Section 2.3: Building a Freestyle Job SCM Connection

Step-by-Step SCM Job Matching
  1. Return to your main menu dashboard view and select New Item.
  2. Enter a project layout label name such as Playwright-Automation-Job, highlight the Freestyle project structural card, and click OK.
  3. Scroll down the configurations menu until reaching the Source Code Management block. Check the radio option circle labeled Git.
  4. Paste your project web repository link directly into the Repository URL field (e.g., https://github.com/youruser/playwright-framework.git).
  5. Under the Credentials selection dropdown interface, select the github-framework-token profile saved earlier.
  6. Specify the exact execution tracking target target branch pathway under the Branch Specifier block (e.g., */main or */master).

Topic 3: Executing the Playwright Test Runner Script File

Once Jenkins downloads your project workspace directory structure, it must execute terminal engine actions to run your testrunner.py routine flawlessly.

Section 3.1: The Crucial Importance of Python Virtual Environments

Never install python packages globally on a Jenkins host terminal environment! If other automated project configurations run on the same platform server, dependency package conflicts will eventually surface. We enforce isolated environment sandboxing using Python's integrated module: venv.

Section 3.2: Constructing Your Platform Build Command Shell Steps

Scroll down to the Build Steps sector configuration view within your project configuration space. Click the Add build step dropdown selection item.

Option A: For Jenkins Nodes Running on Linux / macOS Architectures

Select the option titled Execute shell and embed the following block sequence script precisely into the open editor console window:

# 1. Initialize a localized environment folder called 'venv' inside workspace
python3 -m venv venv

# 2. Fully activate the isolated environment boundaries
source venv/bin/activate

# 3. Upgrade local dependency management utilities and pull dependencies
pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

# 4. CRUCIAL STEP: Pull down Playwright system dependencies and browser binary packages
playwright install --with-deps

# 5. Launch your primary engine automation script
python testrunner.py

Option B: For Jenkins Nodes Running on Native Windows Servers

Select the option titled Execute Windows batch command and enter the following text logic configuration:

:: 1. Initialize a localized python runtime environment folder
python -m venv venv

:: 2. Fully activate the isolated environment boundaries
call venv\Scripts\activate.bat

:: 3. Upgrade environment layout dependencies
python -m pip install --upgrade pip
if exist requirements.txt pip install -r requirements.txt

:: 4. Install Playwright browser frameworks
playwright install

:: 5. Execute code architecture matching your automation layout
python testrunner.py

Topic 4: Modern Declarative Pipelines & Automated Build Schedules (CRON)

Using older Freestyle setups works well for quick tests, but enterprise-grade environments store their infrastructure workflows explicitly as code using a structured Jenkinsfile located right inside the project root folder. Let's build a modern pipeline.

Section 4.1: Constructing the Complete Declarative Pipeline Script

Step-by-Step Pipeline Creation
  1. Create a completely new text file in your local development workspace, name it exactly Jenkinsfile (with no file extensions), and paste the optimized structure block written below:
pipeline {
    agent any
    
    options {
        ansiColor('xterm') // Adds beautiful, colorful terminal reporting logs
        timeout(time: 1, unit: 'HOURS') // Prevents infinitely hanging test suites
    }
    
    triggers {
        // Run tests continuously Monday through Friday at exactly 11:30 PM (Server Time)
        cron('30 23 * * 1-5')
    }
    
    stages {
        stage('Checkout Codebase') {
            steps {
                // Pull code safely from SCM using configured pipeline checkouts
                checkout scm
            }
        }
        
        stage('Initialize Python Environment') {
            steps {
                // Setup dependencies in isolated workspace conditions
                sh '''
                    python3 -m venv venv
                    . venv/bin/activate
                    pip install --upgrade pip
                    pip install -r requirements.txt
                    playwright install --with-deps
                '''
            }
        }
        
        stage('Run Automated Tests') {
            steps {
                // Execute testrunner.py pipeline stage
                sh '''
                    . venv/bin/activate
                    python testrunner.py
                '''
            }
        }
    }
    
    post {
        always {
            // Permanently archive generated test assets like screenshots, traces or video records
            archiveArtifacts artifacts: '**/reports/*.*', allowEmptyArchive: true
        }
    }
}

Section 4.2: Breaking Down the CRON Engine Syntax

The core configuration engine line cron('30 23 * * 1-5') uses five space-separated positional tokens to calculate automatic build trigger intervals:

  • 30: The specific minute marker of the hour (0–59).
  • 23: The hour marker of the standard day in military notation (11 PM).
  • *: Evaluates to every single individual numerical day of the month calendar.
  • *: Evaluates to every single individual calendar month period of the year.
  • 1-5: Restricts execution explicitly to matching days of the week (1=Monday through 5=Friday).

Topic 5: Extracting Reports & Setting Up Email Alerts

An execution suite inside a CI pipeline is only as good as its feedback loop. We need to parse reports and push status configurations directly out to stakeholder team members.

Section 5.1: Publishing HTML Test Reports inside Jenkins UI

If your framework creates a standardized dashboard file (such as `report.html` inside a `reports/` folder), configure the **HTML Publisher Plugin** to expose that artifact inside the build dashboards.

To implement this, insert the following structural instruction block directly inside the post { always { ... } } block area of your active Jenkinsfile:

publishHTML([
    allowMissing: false,
    alwaysLinkToLastBuild: true,
    keepAll: true,
    reportDir: 'reports',
    reportFiles: 'report.html',
    reportName: 'Playwright Execution Report',
    reportTitles: 'Framework Execution Status Summary'
])

Section 5.2: Configuring System SMTP Email Relays

Step-by-Step Global System SMTP Setup
  1. Navigate to Manage JenkinsSystem (older versions call this Configure System).
  2. Scroll all the way down until discovering the block titled E-mail Notification.
  3. Enter your organization's core email routing server address into the SMTP server field (e.g., smtp.gmail.com or your corporate exchange gateway).
  4. Click the Advanced... button configuration dropdown. Tick the box label marked Use SMTP Authentication.
  5. Fill in your primary system sending address credentials along with your matching secure application password token. Tick Use SSL if matching port configuration targets 465.
  6. Tick the test setup connection check box, insert your individual profile email destination address, and confirm it works cleanly.

Section 5.3: Wiring Real-time Alerts to Build Outcomes

Now, expand your Jenkinsfile's post stage blocks to automatically route smart transactional emails out to QA stakeholders matching pipeline status results:

    post {
        success {
            emailext (
                subject: "SUCCESS: Jenkins Build #${env.BUILD_NUMBER} - ${env.JOB_NAME}",
                body: "Great news! All Playwright automation tests passed successfully on Build #${env.BUILD_NUMBER}. Review dashboards at ${env.BUILD_URL}",
                to: "qa-team@way2testing.com"
            )
        }
        failure {
            emailext (
                subject: "FAILURE: Jenkins Build #${env.BUILD_NUMBER} - ${env.JOB_NAME}",
                body: "Alert! Playwright Automation run has failed assertions on Build #${env.BUILD_NUMBER}. Access console logs immediately here: ${env.BUILD_URL}console",
                to: "qa-lead@way2testing.com, developer-alerts@way2testing.com"
            )
        }
    }

There you have it! You now possess a fully operational, industry-standard, resilient enterprise CI/CD testing pipeline running Playwright Python on Jenkins. Stay tuned to way2testing.com for more advanced automation engineering articles!

No comments:

Post a Comment

Few More

ETL Testing with Automation

Ultimate Guide to ETL Testing - Comprehensive Tutorial The Ultimate Guide to ETL Testing: Step-by-Step Masterclass Welcom...