can we links to a screenshot or logs inside cucumber report?

91 views
Skip to first unread message

Styris

unread,
Mar 25, 2016, 12:51:01 PM3/25/16
to Cukes
Hello,

I am working on an Appium/Selenium project and my Mgmt. wants me to take screenshots, along with the application logs for any scenarios that fail. Currently I am taking screenshots inside my code and storing them in a folder inside the Project. However, my Boss wants me to see if there is a way to give a link to the screenshot within the Cucumber report itself (currently I am using the maven cucumber report plugin to get the detailed TC report). Please let me know if something like this is doable/possible.


Thanks.

Chuck van der Linden

unread,
Mar 28, 2016, 2:40:36 PM3/28/16
to Cukes
This is fairly easy to do.   this blog posting might help as a starting point http://blog.tentamen.eu/how-to-embed-screenshot-in-cucumber-report-across-various-environments/  it's for watir-webdriver  but the syntax is very similar (since it's webdriver under the hood of watir-webdriver as the name implies)  

Kashif BHATTI

unread,
Mar 28, 2016, 4:59:56 PM3/28/16
to cu...@googlegroups.com
Can I make this work with JAVA?


Thanks

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to a topic in the Google Groups "Cukes" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cukes/ne6SIX_tlIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert

unread,
Mar 28, 2016, 5:45:08 PM3/28/16
to Cukes


On Monday, March 28, 2016 at 1:59:56 PM UTC-7, Styris wrote:
Can I make this work with JAVA?


This can be handled in Java.  We use the following Groovy code, which can be easily ported over to Java.  Keep in mind, that the key here is to place the code in an After hook, and then grab a reference to the Scenario class

import org.openqa.selenium.TakesScreenshot
import org.openqa.selenium.OutputType

...

After() { ScenarioImpl scenario ->
   
if (scenario.failed) {
       
byte[] screenshot = ((TakesScreenshot) driver)?.getScreenshotAs(OutputType.BYTES)
        scenario
.embed(screenshot, "image/png")
 
}
...

Kashif BHATTI

unread,
Mar 28, 2016, 6:29:05 PM3/28/16
to cu...@googlegroups.com
nice thanks. I kinda already had that figured out before your response. So I ran that piece of code and I see that the report contains a file named "Screenshot 1" at the end of the failed Scenario. Can I customize the name of that file? I tried to say something like this but it didn't work out I guess:

String fileName0 = "Feature# " + featureValue + "; Scenario# " + scenario.getName();

String fileName1 = fileName0.replace("-", " ");

String fileNameWithoutDate = fileName1 + "_" + ".png";

byte[] bytes = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES)

scenario.embed(bytes, fileNameWithoutDate);

Reply all
Reply to author
Forward
0 new messages