Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I attach screenshot with my failed test case? #14

Open
sumeetp4 opened this issue Feb 8, 2018 · 12 comments
Open

How do I attach screenshot with my failed test case? #14

sumeetp4 opened this issue Feb 8, 2018 · 12 comments

Comments

@sumeetp4
Copy link

sumeetp4 commented Feb 8, 2018

I'm using mocha for my test case. I am getting report using mochawesome as well with mochawesome screenshot, How do I attach screenshot with my failed test case?

@BelAn97
Copy link
Owner

BelAn97 commented Feb 8, 2018

Screenshorts for failed tests generate automatically using protractor.browser.takeScreenshot() method.
For passed tests you need add 'takePassedScreenshot' parameter to mocha options:
--reporter-options takePassedScreenshot=true

@sumeetp4
Copy link
Author

sumeetp4 commented Feb 8, 2018

What if I'm using mocha, and for me client.screenshot() function returns the screenshot or I can client.saveScreenshot() to save it in some location

@BelAn97
Copy link
Owner

BelAn97 commented Feb 8, 2018

Unfortunately, now it works only with protractor. I'll think how to implement custom screenshot.

@sumeetp4
Copy link
Author

sumeetp4 commented Feb 8, 2018

Okay so what I did is
in my test I have added afterEach in my js file to execute it after each test case and take a screenshot for failed and save it in screenshots location

afterEach("take screenshot on failure", function() {
if (this.currentTest.state !== "passed") {
var imageFileName = this.currentTest.title+'.jpeg';
client.saveScreenshot('./mochawesome-reports/screenshots/'+imageFileName);
}
});

Also updated mochawesome.js to take the same name
Working for now 💯

@BelAn97
Copy link
Owner

BelAn97 commented Feb 8, 2018

Done. version 1.5.9
Use logReport.setScreenshot(this, imageFileName) to get custom screenshot at the report.

@AndrewFisher093
Copy link

Hello
I'm using mocha as framework and mochawesome as a reporter in my automation project. How can I use mochawesome-screenshots without protractor methods and config files?
Example of my console command which launching tests:
mocha tests --reporter mochawesome --reporter-options autoOpen=true --browser Chrome

Thx for the reply

@linjin-harvey
Copy link

@AndrewFisher093 You can use it directly, my test run by below command:
mocha ./test/spec//.js --reporter mochawesome-screenshots --reporter-options jsonReport=true,clearOldScreenshots=true,shortScrFileNames=true --timeout=60000

@anilchander1
Copy link

@BelAn97 logReport.setScreenshot(this, imageFileName) , will imageFileName accept a file name with a relative or absolute path or is it just a name? I am not able to see the screenshot in the report when my test is in the test folder and the screenshot is generated is one level up in ./mochawesome-reports/screenshots/ folder.

@Serg-develop
Copy link

Done. version 1.5.9
Use logReport.setScreenshot(this, imageFileName) to get custom screenshot at the report.
How to receive logReport?

@BelAn97
Copy link
Owner

BelAn97 commented May 6, 2020

require('mochawesome-screenshots/logReport');

@Serg-develop
Copy link

Can i use this functionality without Protector?
I see, that someone up this topic above, but i didn`t understand well.

Thanks.

@BelAn97
Copy link
Owner

BelAn97 commented May 6, 2020

it uses default protractor's browser.takeScreenshot() method, but if you do not have browser object - this will skip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants