DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Efficiently Migrating From Jest to Vitest in a Next.js Project
  • Supercharging Pytest: Integration With External Tools
  • Mocking and Its Importance in Integration and E2E Testing
  • Seamless CI/CD Integration: Playwright and GitHub Actions

Trending

  • Java Virtual Threads and Scaling
  • Immutable Secrets Management: A Zero-Trust Approach to Sensitive Data in Containers
  • A Modern Stack for Building Scalable Systems
  • How to Configure and Customize the Go SDK for Azure Cosmos DB
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Integrating Jenkins With Playwright TypeScript: A Complete Guide

Integrating Jenkins With Playwright TypeScript: A Complete Guide

A step-by-step guide to integrate Jenkins with Playwright TypeScript: The key files needed are playwright.config.ts, Jenkinsfile, package.json, and test files.

By 
Sidharth Shukla user avatar
Sidharth Shukla
·
Apr. 17, 25 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
4.6K Views

Join the DZone community and get the full member experience.

Join For Free

In this blog post, we'll explore how to set up and integrate Jenkins with Playwright TypeScript for automated testing. This integration enables continuous integration and automated test execution in your development pipeline.

Playwright is a modern, open-source automation testing framework developed by Microsoft that enables reliable end-to-end testing for web applications. It supports multiple browser engines (Chromium, Firefox, and WebKit) and allows you to write tests in multiple programming languages, including TypeScript, JavaScript, Python, and .NET. Playwright is known for its auto-wait capabilities, strong reliability, and cross-browser testing features.

Jenkins is a popular, open-source automation server that helps automate various parts of software development, including building, testing, and deploying software. It provides hundreds of plugins to support building, deploying, and automating any project. Jenkins offers easy installation, simple configuration, extensible features, and a thriving community ecosystem.

Prerequisites

  • Jenkins installed on your system
  • Node.js and npm installed
  • Basic knowledge of TypeScript and Playwright
  • Git repository with your Playwright tests

Step 1: Setting Up Your Playwright TypeScript Project

Ensure Node.js and npm are installed on your machine by running the following commands in your terminal:  

TypeScript
 
node -v
npm -v


These commands will display the installed versions of Node.js and npm, respectively. Refer to the image below:

Installed versions of Node.js and npm

Let's create a basic Playwright TypeScript project:

Shell
 
# Create a new directory
mkdir playwright-jenkins-demo
cd playwright-jenkins-demo

# Initialize npm project
npm init -y

# Install Playwright and TypeScript
npm install -D @playwright/test typescript


Create a basic test file tests/example.spec.ts:

Shell
 
import { test, expect } from '@playwright/test';

test('basic test', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  const title = await page.title();
  expect(title).toContain('Playwright');
});


Step 2: Configure Playwright

Create playwright.config.ts:

Shell
 
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  testDir: './tests',
  timeout: 30000,
  reporter: [
    ['html'],
    ['junit', { outputFile: 'test-results/junit-report.xml' }]
  ],
  use: {
    headless: true,
    screenshot: 'only-on-failure',
  },
};

export default config;


Step 3: Create Jenkins Pipeline

Create a Jenkinsfile in your project root:

Shell
 
pipeline {
    agent any

    tools {
        nodejs 'Node16'  // Make sure this matches your Jenkins NodeJS installation name
    }

    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }

        stage('Install Dependencies') {
            steps {
                sh 'npm ci'
                sh 'npx playwright install --with-deps'
            }
        }

        stage('Run Tests') {
            steps {
                sh 'npx playwright test'
            }
        }
    }

    post {
        always {
            junit 'test-results/junit-report.xml'
            publishHTML(target: [
                allowMissing: false,
                alwaysLinkToLastBuild: true,
                keepAll: true,
                reportDir: 'playwright-report',
                reportFiles: 'index.html',
                reportName: 'Playwright Report'
            ])
        }
    }
}


Step 4: Configure Jenkins

  1. Install the required Jenkins plugins:
    • NodeJS Plugin
    • JUnit Plugin
    • HTML Publisher Plugin
  2. Configure NodeJS in Jenkins:
    • Go to Manage Jenkins > Tools
    • Add NodeJS installation
    • Name it 'Node16' (or update the Jenkinsfile accordingly)

Step 5: Create Jenkins Pipeline Job

  1. Create a new pipeline job in Jenkins.
  2. Configure SCM:
    • Select Git
    • Enter your repository URL
    • Specify the branch
  3. Set the Script Path to Jenkinsfile.

Step 6: Package.json Scripts

Update your package.json:

JSON
 
{
  "scripts": {
    "test": "playwright test",
    "test:report": "playwright show-report"
  },
  "devDependencies": {
    "@playwright/test": "^1.35.0",
    "typescript": "^4.9.0"
  }
}


Running the Pipeline

  1. Push your code to the repository.
  2. Run the Jenkins pipeline.
  3. View test results in Jenkins:
    • JUnit test results
    • HTML report with detailed test execution

Best Practices

  1. Always use explicit versions in package.json.
  2. Include screenshots and videos for failed tests.
  3. Use environment variables for sensitive data.
  4. Implement retry mechanisms for flaky tests.
  5. Use parallel execution for faster results.

Example of parallel execution configuration in playwright.config.ts:

TypeScript-JSX
 
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  testDir: './tests',
  workers: 3, // Run 3 tests simultaneously
  reporter: [['html'], ['junit', { outputFile: 'test-results/junit-report.xml' }]],
  use: {
    headless: true,
    screenshot: 'only-on-failure',
  },
  projects: [
    {
      name: 'Chrome',
      use: { browserName: 'chromium' },
    },
    {
      name: 'Firefox',
      use: { browserName: 'firefox' },
    },
    {
      name: 'Safari',
      use: { browserName: 'webkit' },
    },
  ],
};

export default config;


Benefits

Let's understand the practical benefits of integrating Jenkins with Playwright with real-world examples:

1. Daily Automated Testing

  • Instead of manually running tests every morning, Jenkins can automatically run your Playwright tests at 6 AM before the team starts work.
  • The team arrives to find test reports ready, knowing if the overnight code changes caused any issues.

2. Git Integration Workflow

  • When developers push code to the main branch, Jenkins automatically triggers Playwright tests.
  • Developers get immediate email notifications if their changes break any tests.
  • No need to wait for manual QA testing.

3. Cross-Browser Testing Made Easy

  • Jenkins can run Playwright tests simultaneously on Chrome, Firefox, and Safari. What would take hours to test manually can be done in minutes.
  • Test results for all browsers are consolidated in one report.

4. Real Example of Time Saving

  • Manual testing of 100 test cases: ~8-10 hours.
  • Same tests automated with Playwright + Jenkins: ~30 minutes.
  • The QA team can focus on exploratory testing instead.

5. Practical Use in Release Process

  • Jenkins runs Playwright tests as part of the deployment pipeline.
    • If tests pass → automatic deployment to staging.
    • If tests fail → team gets notified immediately with screenshots and error logs.
  • This prevents broken code from reaching production.

Conclusion

This integration provides a robust automated testing pipeline that can be triggered automatically with each code push. The HTML reports and JUnit results give clear visibility into test execution results, making it easier to identify and fix issues quickly.

Remember to adjust the configuration based on your specific needs and environment. You might need to modify paths, timeouts, or other settings depending on your project requirements.

TypeScript Jenkins (software) Testing Integration

Opinions expressed by DZone contributors are their own.

Related

  • Efficiently Migrating From Jest to Vitest in a Next.js Project
  • Supercharging Pytest: Integration With External Tools
  • Mocking and Its Importance in Integration and E2E Testing
  • Seamless CI/CD Integration: Playwright and GitHub Actions

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!