cucumber-reporting
cucumber-reporting copied to clipboard
How to merge 2 json files into one html report
I am running 2 cucumber runner files. One will run all the tests and failed feature will store in a rerun.text file. 2nd runner will be used to rerun failed feature only. In this case i am getting two different json files. is there any way that i can configure to get single HTML report
Jenkins file creating two json files but failing to genarate reports
Build.gradle
plugins { id 'java' }
repositories { mavenCentral() }
dependencies { testImplementation 'io.cucumber:cucumber-java:6.10.4' testImplementation 'io.cucumber:cucumber-junit:6.10.4' testImplementation 'junit:junit:4.13.2' implementation 'net.masterthought:cucumber-reporting:5.8.1' // Maven Cucumber Reporting implementation 'net.masterthought:maven-cucumber-reporting:5.8.1'
}
test { // Configure rerun.txt file generation // This example is for Cucumber systemProperty 'cucumber.options', "--rerun-file=${buildDir}/rerun.txt" }
// Define task to generate HTML reports using Maven Cucumber Reporting task generateCucumberReports(type: Exec) { // Ensure this task runs after tests are executed dependsOn test
def classpath = configurations.runtimeClasspath.collect { it.absolutePath }.join(':')
// Command to execute the Maven Cucumber Reporting ReportBuilder
commandLine 'java', '-cp', classpath, 'net.masterthought.cucumber.ReportBuilder',
'--json', 'target/reports/cucumber-reports/cucumber.json,target/reports/cucumber-reports/cucumberReRun.json',
'--output', 'target/reports/cucumber-reports/merged-report.html',
'--merge', true // Enable merging of reports
}
//reports.junitXml.destination = file("$buildDir/test-results/test")
// Ensure the generateCucumberReports task runs after tests test.finalizedBy generateCucumberReports
test { useJUnit() }
wrapper { gradleVersion = '8.8' //version required }
Jenkins file
pipeline { agent any
environment {
RERUN_FILE = 'target/rerun.txt'
}
stages {
stage('Clean Workspace') {
steps {
deleteDir()
}
}
stage('Build') {
steps {
script {
try {
sh './gradlew clean build'
} catch (Exception e) {
// Handle build failure if necessary
}
}
}
}
stage('Run Tests') {
steps {
script {
try {
dir('D:\\LearnAutomation\\Selenium Java\\LearnCucumber2.0'){
bat './gradlew test --tests com.example.runners.Runner'
echo 'Running............'
}
//gradlew test --tests Runner // Adjust this command based on your build tool
} catch (Exception e) {
// Ignore errors to allow post section to execute
}
}
}
}
stage('Rerun Failed Tests') {
steps {
script {
try {
dir('D:\\LearnAutomation\\Selenium Java\\LearnCucumber2.0'){
bat './gradlew test --tests com.example.runners.ReRunner'
echo 'Running............'
}
//gradlew test --tests Runner // Adjust this command based on your build tool
} catch (Exception e) {
// Ignore errors to allow post section to execute
}
}
}
}
}
post {
always {
//junit 'build/test-results/test/cucumber.xml' // Adjust this pattern based on your results location
//cucumber 'target/reports/cucumber-reports/cucumberfinal.json' // Adjust this path based on your JSON report location
junit allowEmptyResults: true, testResults: '**/test-results/*.xml'
archiveArtifacts artifacts: 'target/reports/cucumber-reports/merged-report.html'
// Optional: Archive the rerun file if it exists
archiveArtifacts artifacts: 'target/rerun.txt', allowEmptyArchive: true
}
success {
echo 'Build and tests succeeded.'
}
failure {
echo 'Build or tests failed.'
}
}
}