Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Attachments optional trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
lamkovod committed Jul 11, 2019
1 parent c720da6 commit 32cbb61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ example config file
"enableLogs": false, // disables console logging. Default value: true.*
"hideWarning": true, // hides "results won't be published" message. Default value: false.
"hideResultUrl": true // skip printing out of suite url in the end. Default value: false.
"attachmentTrigger": "ALL" // send attachments depending on test state. Default value === value of stateFailed. Special option - "ALL"
"attachmentFolder": "cypress/screenshots" // path to attachments. Default value: report/screenshot
"attachmentType": "image/png" // media type of attachments. More info https://www.iana.org/assignments/media-types/media-types.xhtml
}
Expand Down
35 changes: 19 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function qTest(runner, options = {}) {

const attachmentFolder = qTestConfig.attachmentFolder || 'report/screenshot'
const attachmentType = qTestConfig.attachmentType || 'image/png'
const attachmentTrigger = qTestConfig.attachmentTrigger || stateFailed

if (!testSuiteId && (!parentId || !testSuiteName || !parentType)) {
if (!qTestConfig.hideWarning) {
Expand Down Expand Up @@ -109,19 +110,6 @@ function qTest(runner, options = {}) {

test.qTest.executionLog.status = stateFailed
test.qTest.executionLog.note = err.stack

const attachmentsFolder = path.join(process.cwd(), `${attachmentFolder}`)

if (fs.existsSync(attachmentsFolder)) {
const attachmentPath = getAttachmentPath(path.join(process.cwd(), `${attachmentFolder}`), getQTestId(test.title))
if (attachmentPath) {
test.qTest.executionLog.file = fs.readFileSync(attachmentPath).toString('base64')
} else {
log(log.TEST_PAD, "Attachments with qTestId in name not found")
}
} else {
log(log.TEST_PAD, "Attachments path not found")
}
},

onTestSkip(test) {
Expand All @@ -146,6 +134,10 @@ function qTest(runner, options = {}) {
if (!test.qTest.executionLog.status) {
test.qTest.executionLog.status = statePending
}

if ([test.qTest.executionLog.status, 'ALL'].some(tr => attachmentTrigger === tr)) {
test.qTest.executionLog.file = getAttachment(attachmentFolder, test.title)
}
},

onSuiteStart(suite) {
Expand Down Expand Up @@ -352,9 +344,20 @@ function addTest(testTitle, testCaseId, buildUrl) {
}
}

function getAttachmentPath(attachmentPath, testCaseId) {
const files = getFiles(attachmentPath)
return files.find(filename => filename.includes(testCaseId))
function getAttachment(attachmentFolder, testTitle) {
const attachmentsFolder = path.join(process.cwd(), `${attachmentFolder}`)

if (fs.existsSync(attachmentsFolder)) {
const attachmentPath = getFiles(attachmentsFolder).find(filename => filename.includes(testTitle))
if (attachmentPath) {
return fs.readFileSync(attachmentPath).toString('base64')
} else {
console.log("Attachments with qTestId in name not found")
}
} else {
console.log("Attachments path not found")
}
return undefined
}

function getFiles (folderPath) {
Expand Down

0 comments on commit 32cbb61

Please sign in to comment.