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

Attachment support #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

lamkovod
Copy link

Proposed changes
Attachment support with possibility of choosing attachment media type.

Types of changes
New feature

Fixes #1

@lamkovod lamkovod force-pushed the attachment-support branch from e89fbbf to c720da6 Compare July 10, 2019 07:36
Copy link
Owner

@mgrybyk mgrybyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking care of this one! Have some comments

index.js Outdated
@@ -339,6 +352,20 @@ function addTest(testTitle, testCaseId, buildUrl) {
}
}

function getAttachmentPath(attachmentPath, testCaseId) {
const files = getFiles(attachmentPath)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is possible that multiple tests have the same testCaseId.

Is it possible to get screenshot name directly from test object? It would reduce complexity a lot.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we could use full test name and default path without subfolders, but I'm pretty sure that it all fully depends on user's testing framework settings.
Ex. : Cypress got it's own subfolder for each spec file.

But still full test name can be used for screenshot search to make usage of "shared" testCaseId possible.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most frameworks can generate full path to screenshots, not sure if cypress can do it.
That would help a lot

index.js Outdated

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

if (fs.existsSync(attachmentsFolder)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the approach, however you may also take a look at https://github.com/adamgruber/mochawesome#addcontexttestobj-context

It looks a bit more flexible imo.
We can have global after each hook, in case test failed add attachment to test object and then extract it here.

That's up to you

Copy link
Collaborator

@xlenz xlenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please test and provide some examples with following frameworks:

  • cypress
  • pure mocha framework

The way it is implemented currently doesn't look really well for me, however if it works with cypress/mocha/wdio I don't mind.

I think that it would require storing screenshots in file system for mocha framework (without cypress). If yes - we'll need to think on different approach/solution.

Anyway, thank you for helping with this!

@@ -339,6 +344,31 @@ function addTest(testTitle, testCaseId, buildUrl) {
}
}

function getAttachment(attachmentFolder, testTitle) {
const attachmentsFolder = path.join(process.cwd(), `${attachmentFolder}`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think attachmentFolder can be declared once in the top.
Can't see any reason to pass attachmentFolder in current implementation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, it's a property of qTestConfig

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

if (fs.existsSync(attachmentsFolder)) {
const attachmentPath = getFiles(attachmentsFolder).find(filename => filename.includes(testTitle))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please mention somewhere (in doc/readme) how are you attaching screenshots, please?
It is not obvious at all

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.js Outdated
if (attachmentPath) {
return fs.readFileSync(attachmentPath).toString('base64')
} else {
console.log("Attachments with qTestId in name not found")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the code is not properly formatted

index.js Outdated
const res = path.resolve(folderPath, dirent)
return fs.existsSync(res) && fs.lstatSync(res).isDirectory() ? getFiles(res) : res
})
return Array.prototype.concat(...files)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you converting files to array here? May it be simplified to return [...files]?

@lamkovod lamkovod force-pushed the attachment-support branch from 32cbb61 to 6578a20 Compare July 16, 2019 14:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attachments support
3 participants