Automation Architecture Course > Module 8: CI/CD Integration and DevOps Patterns

Module 8: CI/CD Integration and DevOps Patterns

⏱️ 70 minutes 📈 Advanced 🚀 CI/CD & DevOps

🎯 Learning Objectives

Design CI/CD Test Pipelines

Create robust pipelines for automated test execution

Implement Quality Gates

Set up automated quality checks and deployment gates

Container-based Testing

Use Docker and Kubernetes for scalable test environments

Infrastructure as Code

Manage test infrastructure using code and automation

🚀 CI/CD Pipeline Integration

✅ Jenkins Pipeline for Test Automation

pipeline {
    agent any
    parameters {
        choice(name: 'ENVIRONMENT', choices: ['dev', 'staging', 'prod'], description: 'Target Environment')
        choice(name: 'BROWSER', choices: ['chrome', 'firefox', 'edge'], description: 'Browser for Testing')
        choice(name: 'TEST_SUITE', choices: ['smoke', 'regression', 'full'], description: 'Test Suite to Execute')
    }
    environment {
        MAVEN_OPTS = '-Xmx1024m'
        TEST_RESULTS_DIR = 'target/test-results'
    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }
        
        stage('Build') {
                sh 'mvn clean compile'
        stage('Unit Tests') {
                sh 'mvn test -Dtest=*UnitTest'
            post {
                always {
                    publishTestResults testResultsPattern: 'target/surefire-reports/*.xml'
                }
        stage('Integration Tests') {
            parallel {
                stage('API Tests') {
                    steps {
                        sh """
                            mvn test -Dtest=*ApiTest \\
                            -Denvironment=${params.ENVIRONMENT} \\
                            -Dapi.base.url=${getApiUrl(params.ENVIRONMENT)}
                        """
                    }
                
                stage('UI Tests') {
                            mvn test -Dtest=*UiTest \\
                            -Dbrowser=${params.BROWSER} \\
                            -Dsuite=${params.TEST_SUITE} \\
                            -Dheadless=true
                    publishTestResults testResultsPattern: 'target/failsafe-reports/*.xml'
                    publishHTML([
                        allowMissing: false,
                        alwaysLinkToLastBuild: true,
                        keepAll: true,
                        reportDir: 'target/test-reports',
                        reportFiles: 'index.html',
                        reportName: 'Test Report'
                    ])
        stage('Quality Gate') {
                script {
                    def testResults = readTestResults()
                    def passRate = testResults.passRate
                    
                    if (passRate < 95) {
                        error("Quality gate failed: Pass rate ${passRate}% is below threshold of 95%")
                    if (testResults.criticalFailures > 0) {
                        error("Quality gate failed: ${testResults.criticalFailures} critical test failures")
        stage('Deploy to Next Environment') {
            when {
                expression { params.ENVIRONMENT != 'prod' }
                    def nextEnv = getNextEnvironment(params.ENVIRONMENT)
                    build job: 'deploy-application', parameters: [
                        string(name: 'ENVIRONMENT', value: nextEnv),
                        string(name: 'VERSION', value: env.BUILD_NUMBER)
                    ]
    post {
        always {
            archiveArtifacts artifacts: 'target/test-reports/**/*', fingerprint: true
            cleanWs()
        failure {
            emailext (
                subject: "Test Execution Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER}",
                body: """
                    Test execution failed for ${env.JOB_NAME} build ${env.BUILD_NUMBER}.
                    Environment: ${params.ENVIRONMENT}
                    Browser: ${params.BROWSER}
                    Test Suite: ${params.TEST_SUITE}
                    Check the build logs for details: ${env.BUILD_URL}
                """,
                to: "${env.CHANGE_AUTHOR_EMAIL}, qa-team@company.com"
            )
        success {
            slackSend (
                channel: '#qa-automation',
                color: 'good',
                message: "✅ Test execution successful: ${env.JOB_NAME} - ${env.BUILD_NUMBER}"
}

🐳 Containerized Test Environments

✅ Docker Compose for Test Infrastructure

# docker-compose.test.yml
version: '3.8'
services:
  selenium-hub:
    image: selenium/hub:4.15.0
    container_name: selenium-hub
    ports:
      - "4444:4444"
    environment:
      - GRID_MAX_SESSION=16
      - GRID_BROWSER_TIMEOUT=300
      - GRID_TIMEOUT=300
  chrome-node:
    image: selenium/node-chrome:4.15.0
    shm_size: 2gb
    depends_on:
      - selenium-hub
      - HUB_HOST=selenium-hub
      - NODE_MAX_INSTANCES=4
      - NODE_MAX_SESSION=4
    scale: 2
  firefox-node:
    image: selenium/node-firefox:4.15.0
  test-runner:
    build:
      context: .
      dockerfile: Dockerfile.test
      - test-database
      - mock-api
      - SELENIUM_HUB_URL=http://selenium-hub:4444/wd/hub
      - DATABASE_URL=jdbc:postgresql://test-database:5432/testdb
      - API_BASE_URL=http://mock-api:8080
    volumes:
      - ./target/test-reports:/app/test-reports
    command: mvn test -Dparallel=true -DthreadCount=8
  test-database:
    image: postgres:13
      - POSTGRES_DB=testdb
      - POSTGRES_USER=testuser
      - POSTGRES_PASSWORD=testpass
      - ./test-data/init.sql:/docker-entrypoint-initdb.d/init.sql
  mock-api:
    image: wiremock/wiremock:2.35.0
      - "8080:8080"
      - ./test-data/wiremock:/home/wiremock

🎓 Course Completion

🎉 Congratulations!

You have successfully completed the Automation Architecture Techniques and Design Patterns course!

What You've Mastered:

  • ✅ Foundation of Automation Architecture (45 min)
  • ✅ SOLID Principles in Test Automation (60 min)
  • ✅ Essential Design Patterns for Automation (75 min)
  • ✅ Advanced Page Object Patterns (50 min)
  • ✅ Data-Driven Architecture Design (55 min)
  • ✅ Parallel Execution and Scalability (65 min)
  • ✅ Reporting and Monitoring Architecture (50 min)
  • ✅ CI/CD Integration and DevOps Patterns (70 min)

Total Course Duration: 470 minutes (7.8 hours)

🚀 You're Now Ready For:

Tech Lead positions, Senior QA Engineer roles, Test Architect positions, and leading automation initiatives in enterprise environments.