Skip to content

Commit

Permalink
updated runner.js
Browse files Browse the repository at this point in the history
  • Loading branch information
far11ven committed Sep 12, 2023
1 parent 36b6e43 commit 78eea75
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions v13/cypress/e2e/common/pages/HomePage/elements.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
HOMEPAGE:{
SEARCH_TXTBOX: "input[name='q']",
SEARCH_TXTBOX_XPATH: "//input[contains(@name,'q')]"
SEARCH_TXTBOX: "textarea[name='q']",
SEARCH_TXTBOX_XPATH: "//textarea[contains(@name,'q')]"
}
}
2 changes: 2 additions & 0 deletions v13/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"pg": "^8.7.1"
},
"cypress-cucumber-preprocessor": {
"filterSpecs": true,
"omitFiltered": true,
"nonGlobalStepDefinitions": true,
"stepDefinitions": "cypress/e2e/common/stepDefinitions/**/*.{js,mjs,ts,tsx}"
}
Expand Down
43 changes: 23 additions & 20 deletions v13/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ cypress.run({
json: true
}
})
.then(testResults => {
.then(finalResult => {

// generate a unified report, once Cypress test run is done
generateReport(mergeOptions, testResults)
generateReport(mergeOptions, finalResult)
.then(() => {
console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Test Report has been generated.`)
})
Expand Down Expand Up @@ -150,7 +150,7 @@ function getRunTimeStamp() {
}

// generate unified report from sourceReport.files directory and create a unified report and store it in finalReport.reportDir location
function generateReport(mergeOptions, testResults) {
function generateReport(mergeOptions, finalResult) {
return merge(mergeOptions).then(report => {
marge.create(report, finalReport)
.then(result => {
Expand All @@ -160,44 +160,47 @@ function generateReport(mergeOptions, testResults) {
console.error(`[Cypress-TestFramework][${new Date().toISOString()}] Error while merging reports: `, err.message)
})
.finally(() => {
console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Test Run Completed on - ` + testResults.endedTestsAt)
console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Total duration - ` + testResults.totalDuration)
console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Test Run Completed on - ` + finalResult.endedTestsAt)
console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Total duration - ` + finalResult.totalDuration)

//calculate total time taken for test run
let endDate = new Date(testResults.endedTestsAt)
let startDate = new Date(testResults.startedTestsAt)
let endDate = new Date(finalResult.endedTestsAt)
let startDate = new Date(finalResult.startedTestsAt)
let gitHubActions = {};

const hours = parseInt(Math.abs(endDate - startDate) / (1000 * 60 * 60) % 24)
const minutes = parseInt(Math.abs(endDate.getTime() - startDate.getTime()) / (1000 * 60) % 60)
const seconds = parseInt(Math.abs(endDate.getTime() - startDate.getTime()) / (1000) % 60)

console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Total time taken - ${('0' + hours).slice(-2)}:${('0' + minutes).slice(-2)}:${('0' + seconds).slice(-2)}`)
console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Total ${testResults.totalPassed} test passed out of ${testResults.totalTests} tests`)
console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Test Run Status - ` + testResults.status)


// stats for GitHub Actions
gitHubActions.projectId = testResults.config.projectId;
gitHubActions.projectId = finalResult.config.projectId;
gitHubActions.envUrl = args.config.baseUrl;
gitHubActions.totalTests = testResults.totalTests;
gitHubActions.totalPassed = testResults.totalPassed;
gitHubActions.totalSuites = testResults.totalSuites;

gitHubActions.suites = finalResult.totalSuites;
gitHubActions.tests = finalResult.totalTests;
gitHubActions.passed = finalResult.totalPassed;
gitHubActions.failed = finalResult.totalFailed;
gitHubActions.skipped = finalResult.totalSkipped;
gitHubActions.pending = finalResult.totalPending;

// used for signalling GitHub Actions Teams Notifications about the Test Run Success/Failure
if (testResults.totalFailed === undefined) {
if (finalResult.totalFailed === undefined) {
gitHubActions.status = "failure"
console.log(gitHubActions)

} else if (testResults.totalFailed > 0) {
} else if (finalResult.totalFailed > 0) {
gitHubActions.status = "failure"
console.log(gitHubActions)

} else if (testResults.totalFailed == 0) {
} else if (finalResult.totalFailed == 0) {
gitHubActions.status = "success"
console.log(gitHubActions)

}

console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Total time taken - ${('0' + hours).slice(-2)}:${('0' + minutes).slice(-2)}:${('0' + seconds).slice(-2)}`)
console.log(`[Cypress-TestFramework][${new Date().toISOString()}] Total ${finalResult.totalPassed} test(s) passed out of ${finalResult.totalTests} tests`)
console.log(`[Cypress-TestFramework][${new Date().toISOString()}] ======================== Test Run was complete ========================`)

process.exit()
})
})
Expand Down

0 comments on commit 78eea75

Please sign in to comment.