New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discussion] addContext in .then() closure of Cypress (multiple screenshots) #385
Comments
I'm having the exact same problem.
...but the same structure outside of the event handler does work:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The original problem
So, just like many of us, I wanted to add screenshots 馃摲 to my mochawesome report. And I quickly found several guides online on how to do so. Eventually, I ended up with something like this to solve my problem;
Done, works fine right?
Well, what if you have a test that has several attempts, adding screenshots with (attempt 2, attempt 3, etc). Are you happy just getting one of those screenshots?
And what if you have a beforeEach() hook and it fails there? Then the screenshot name becomes
${test.title} -- before each hook (failed).png
So I set out to add all the screenshots. 馃摲 馃摲 馃摲 馃摲
My idea馃挕
Instead of statically defining the name(s) of the screenshot(s) that may or may not be there, I wanted to use fs.readdirSync() to find and list all screenshots in the folder and match them to the test.title. Like so;
I am utilizing cy.task() because you cannot use fs-functions within Cypress test code itself. So I use the task below to return a string[] of filenames.
From config file;
Unfortunately, this does not work...
The problem now
While encapsulated in the cy.task().then(), the addContext() function doesn't seem to do anything... Its doesnt even add the broken image link that you see if there is an issue with the url itself.
I have tries moving the
const addContext = require("mochawesome/addContext.js")
import inside the .then() closure to ensure that it is accessible in its context without it making a difference.Any ideas or inputs on how to solve this is more than welcome!
Alternate solutions
The text was updated successfully, but these errors were encountered: