microsoft / playwright-java

Java version of the Playwright testing and automation library
https://playwright.dev/java/
Apache License 2.0
1.14k stars 207 forks source link

[Question] - Require Steps to follow in order to integrate Playwright+Java cucumber tests with jenkins #1082

Closed dggadhia closed 1 year ago

dggadhia commented 2 years ago

I tried these steps but not working, not clear as what needs to be done.

image

yury-s commented 2 years ago

Yeah, the doc is from Node.js port of playwright, you have to replace the steps with your own code. We don't have a good guide for that at the moment, try asking for examples in our slack channel for now.

dggadhia commented 2 years ago

have already raised in slack channel but no help as of now. dg gadhia 4:44 PM Any one has integrated Playwright+Cucumber+Java tests with Jenkins?.Is it working?

NikkTod commented 2 years ago

It is working, I am using the playwright docker image, below code is put in a Jenkins file, but it is specific to some extend with my project and company.

Try to play around and replace stuff where needed to suit you project:

pipeline {
agent {  docker { image mcr.microsoft.com/playwright/java:v1.26.0-focal  }  }
parameters {
           string( name: 'TAG', defaultValue: '@EndToEndTests', description: 'Place a tag in order to run a subset of scenarios')
           choice( name: 'ENV_CONFIG', choices: ['configQA', 'configDev'], description: "Select configuration environment file")
       } 
environment {
            PLAYWRIGHT_JAVA_SRC = "${env.WORKSPACE}/e2e/src/main/java:${env.WORKSPACE}/e2e/src/test/java"
       }
stages {
      stage('e2e-tests') {
         steps {
            echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL} with working directory ${env.WORKSPACE}"
            echo "Tag: ${params.TAG} - Config: ${params.ENV_CONFIG}"
            checkout scm
           catchError(message: 'Tests failed: review pipeline logs',
                                        buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
             dir("e2e"){
                sh 'mvn exec:java -e "-Dexec.mainClass=com.microsoft.playwright.CLI" "-Dexec.args=install chrome"'
                sh "mvn test -DargLine=-Dcucumber.filter.tags=${params.TAG} -DcfgFile=${params.ENV_CONFIG}"
             }
           }
            publishHTML (target : [
                  allowMissing: false,
                  alwaysLinkToLastBuild: true,
                  keepAll: true,
                  reportDir: 'e2e/target/cucumber-reports',
                  reportFiles: 'index.html',
                  reportName: 'Cucumber Test Run Report',
                  reportTitles: 'Cucumber Test Run Report'
                  ]
            )
         }
      }
   }
post {
      always {
          junit 'e2e/target/cucumber-reports/**/*.xml'
      }
      unstable {
          archiveArtifacts '**/*.zip'
      }
   }
}
yury-s commented 1 year ago

Closing per the response above, feel free to open a new issue if it doesn't work.