extent-framework / extentreports-cucumber4-adapter

Cucumber4 Adapter for Extent Framework
http://extentreports.com/docs/versions/4/java/cucumber2.html
Apache License 2.0
39 stars 22 forks source link

Extent report adapter screenshot issue #48

Closed abhishekrhyme closed 4 years ago

abhishekrhyme commented 4 years ago

https://github.com/extent-framework/extentreports-cucumber4-adapter/issues/20 as this is closed so raising a new one.. same issue not able to attach a screenshot in report. I looked into other issues but couldnt get my issue fixed.

I am not getting screenshots in spark report/logger report, only blue icon is displayed.

Screen Shot 2020-04-08 at 1 34 05 AM

using adapter 1.0.8 and cucumber 4.8.1 also, 1.0.11-SNAPSHOT repo not available. Here is the screenshot.

anshooarora commented 4 years ago

@abhishekrhyme Please share your extent.properties.

abhishekrhyme commented 4 years ago

extent.reporter.html.start=true extent.reporter.logger.start=true extent.reporter.spark.start=true

extent.reporter.html.config=src/test/resources/extent-config.xml extent.reporter.logger.config=src/test/resources/extent-config.xml extent.reporter.spark.config=src/test/resources/extent-config.xml

extent.reporter.html.out=test-output/HtmlReport/ExtentHtml.html extent.reporter.logger.out=test-output/Logger extent.reporter.spark.out=test-output/Spark

screenshot.dir=test-output/ screenshot.rel.path=../

anshooarora commented 4 years ago

Use this:

extent.reporter.html.start=false
extent.reporter.logger.start=false
extent.reporter.spark.start=true

extent.reporter.html.config=src/test/resources/extent-config.xml
extent.reporter.logger.config=src/test/resources/extent-config.xml
extent.reporter.spark.config=src/test/resources/extent-config.xml

extent.reporter.html.out=test-output/HtmlReport/ExtentHtml.html
extent.reporter.logger.out=test-output/Logger/
extent.reporter.spark.out=test-output/Spark/

screenshot.dir=test-output/
screenshot.rel.path=../
abhishekrhyme commented 4 years ago

I tried this but no luck stil the spark report without screenshots.

anshooarora commented 4 years ago

Can you make sure you have the latest snapshot? Can you force refresh the project along with all snapshots?

abhishekrhyme commented 4 years ago

done still not working... here is my sample code

public class Steps {

private WebDriver driver;

@BeforeStep
public void beforeStep() throws InterruptedException {
    Thread.sleep(250);
}

@AfterStep
public void afterStep(Scenario scenario) {
    System.out.println("AFTER STEP");
    TakesScreenshot ts = (TakesScreenshot) driver;
    byte[] screenshot = ts.getScreenshotAs(OutputType.BYTES);
    scenario.write("step is completed……….");
    scenario.embed(screenshot, "image/png");
}

@Given("open facebook")
public void open_facebook() {

// System.setProperty("webdriver.chrome.driver", "chromedriver"); WebDriverManager.chromedriver().setup(); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.notifications", 2); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); options.setPageLoadStrategy(PageLoadStrategy.NONE); driver = new ChromeDriver(options); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); driver.get("https://www.facebook.com"); driver.manage().window().maximize(); String title = driver.getTitle(); System.out.println(title); }

anshooarora commented 4 years ago

Can you share your HTML file?

abhishekrhyme commented 4 years ago

attached

anshooarora commented 4 years ago

No attachments.

abhishekrhyme commented 4 years ago

chere here https://github.com/abhishekrhyme/Cucumber4AdapterExample/tree/master/CucumAdaptar2

anshooarora commented 4 years ago

You are not using the latest snapshot:

https://github.com/abhishekrhyme/Cucumber4AdapterExample/blob/master/CucumAdaptar2/pom.xml#L19

abhishekrhyme commented 4 years ago

Hi @anshooarora Updated the snapshot and dependency but the screenshots are still not attached. https://github.com/abhishekrhyme/extentadapter.git

Screen Shot 2020-04-08 at 9 43 19 PM
abhishekrhyme commented 4 years ago

Hi @anshooarora , Upon using, ExtentCucumberAdapter.addTestStepScreenCaptureFromPath(imagepath); - I enabled html report and was able to get the screenshots in html report. scenario.embed(Files.readAllBytes(Paths.get(imagepath)), "image/png”); - But in spark report screenshots are still missing.

My git repo is updated if you want to have a look at HTML reports. https://github.com/abhishekrhyme/extentadapter.git

I have used the latest snapshot

extentreports-cucumber4-adapter 1.0.10

Please advise if you want me to try anything else.

abhishekrhyme commented 4 years ago

Also one point, the screenshots are not inserted in html report, i believe its just a link, if the screenshots from folder are deleted, image is not opening.. in this case if we email html report alone to anybody without screenshots, image wont open from html report right?

vzenzo commented 4 years ago

I have same issue, in Spark there is no screenshots at all and in HTML report there are screenshot icons looking in right folders but thing is screenshots are saved in test-output no matter what I do

anshooarora commented 4 years ago

The feature to specify the screenshot save location, and its relative path to the HTML file has been added in 1.0.11-SNAPSHOT. I will publish the release and also share details of how to utilize this enhancement.

Please feel free to use the SNAPSHOT version until then, the instructions are towards the end of this ticket. The below 2 settings are available to use:

screesnshot.dir=test-output/
screenshot.rel.path=../
anshooarora commented 4 years ago

Please use the latest release 1.0.11 and refer to this section.

abhishekrhyme commented 4 years ago

It’s not working please verify with user before closing defect. It is redundant process to keep creating defects for the same issue as there is no reopen option available. Behavior is same as before... only hooks in the report are not appearing now rest screenshots don’t appear anywhere with scenario.embed function.

abhishekrhyme commented 4 years ago

@anshooarora tagging you to refer above comment.

anshooarora commented 4 years ago

Can you update your project with the latest updates?

https://github.com/abhishekrhyme/extentadapter

anshooarora commented 4 years ago

Also see my comment here: https://github.com/extent-framework/extentreports-cucumber4-adapter/issues/20#issuecomment-612212611

If you are using @BeforeStep or @AfterStep, use 1.0.12-SNAPSHOT after enabling SNAPSHOTS. Otherwise, use the current release version.

abhishekrhyme commented 4 years ago

Thanks for the comment. Sure will give it a try and let you know.

abhishekrhyme commented 4 years ago

@anshooarora I have used 1.0.11 release and also didn’t use @AfterStep as you advised, but there are no screenshots saved under test-output folder or attached to HTML report.

This are the steps used for taking screenshot: byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); scenario.embed(screenshot, "image/png”);

Please check my updated repo and checkout the html reports and properties file. https://github.com/abhishekrhyme/extentadapter

anshooarora commented 4 years ago

Here is what I see:

image

There are 3 images attached.

abhishekrhyme commented 4 years ago

yes, screenshots are showing in ur screenshot, but in the HTML report from repo I am seeing nothing. I am using mac and opening the HTML in chrome, not sure if any plugin is required. I can see only a paperclip icon attached to the scenario.

Screen Shot 2020-04-12 at 2 36 10 AM
anshooarora commented 4 years ago

I see this as the path src='../embedded1.png'

https://github.com/abhishekrhyme/extentadapter/blob/master/test-output/Spark/Index.html#L172

but I do not see any images in this folder:

https://github.com/abhishekrhyme/extentadapter/tree/master/test-output

Why is that? No wonder nothing is showing for you because the screenshots are not being saved to test-output.

abhishekrhyme commented 4 years ago

@anshooarora It may be due to screenshot.rel.path attribute, yes screenshots are being generated but it is going in a different folder. It may be a Mac feature, any idea how to get this fixed other than not having space in the project location path.

My Project path is this location: /Users/abhisheksen/My Computer/My Projects/eclipse-workspace-v1/extentadapter/test-output

while screenshot are getting saved here: /Users/abhisheksen/My%20Computer/My%20Projects/eclipse-workspace-v1/extentadapter/test-output

And this is the very reason report is not displaying the screenshots though having the link if we move these screenshots in the original location, screenshots will display. The below images will give you a clear idea.

Screen Shot 2020-04-12 at 4 58 26 PM Screen Shot 2020-04-12 at 5 12 08 PM
vzenzo commented 4 years ago

I am on windows and I have same issue as mentioned above but I do not see any screenshots in reports, I've moved all of my reports to test-output because of this, and still nothing, sometimes it generates screenshots but it is in that %20 folder, sometimes it doesn't even generate screenshot but at the end, there is no screenshot icon in html report nor spark report

anshooarora commented 4 years ago

@abhishekrhyme not sure if it helps but can you try ./test-output/ in extent.properties.

@vzenzo Are you using @After or @AfterStep? Version? Can you create a small snippet or project?

vzenzo commented 4 years ago

@vzenzo Are you using @After or @AfterStep? Version? Can you create a small snippet or project?

I am using @AfterStep

@AfterStep
public void afterStep(Scenario scenario) {
    TakesScreenshot ts = (TakesScreenshot) driver;
    byte[] screenshot = ts.getScreenshotAs(OutputType.BYTES);
    scenario.write("Step finished");
    scenario.embed(screenshot, "image/png");
}

I am using it in Hooks class, the problem I am occurring is sometimes it doesn't even save picture and the report doesnt't have picture link. I am using 1.0.11

I have later made my own code to take screenshot, just don't know how to implement it into a report

Also some of the colors on charts are mixed up but thats another issue.

anshooarora commented 4 years ago

@AfterStep - use version 1.0.12-SNAPSHOT.

Due to an error, the AfterStep hook was removed but is now included in the latest snapshot.

abhishekrhyme commented 4 years ago

I tried by changing screenshot.dir but no help. It is still goin in %20 folders.

anshooarora commented 4 years ago

I referred to your screenshots above and this happens because the default way to save screenshots is by writing against a URL. See the official Cucumber HTML formatter. Any space would be replaced by %20 so I would advise you to not have any spaces, use - or _ where necessary. This is also why I was unable to reproduce the behavior you are.

abhishekrhyme commented 4 years ago

@anshooarora Got your point so in Spark report as screenshots look into the project folder to link screenshots, and if we have space in project path because of formatter it will go to %20 folder, so we need to keep this in mind. For now I have moved the screenshots (manually) to project folder, and spark report is showing the screenshots. Step is: scenario.embed(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES), "image/png");

I would prefer using HTML report where I can actually attach the image by taking Base64 screenshot. In this way screenshots from the report won’t look to any folder, and if I email or check the report in a different system (which is actually my objective), the images won’t get lost. Step is: ExtentCucumberAdapter.addTestStepScreenCaptureFromPath(getBase64Screenshot(driver));

I have also updated the repo for reference. Repository: https://github.com/abhishekrhyme/extentadapter

Both my html and spark report is displaying screenshots now. Test Reports: Html: https://github.com/abhishekrhyme/extentadapter/tree/master/test-output/Extent Spark: https://github.com/abhishekrhyme/extentadapter/tree/master/test-output/Spark

anshooarora commented 4 years ago

Thanks for the update.

rajeeshnair commented 3 years ago

@anshooarora i have a query here,in html report you are attaching this as base64string.So we can share the report across no need to depends on the local image file.But in Spark report and even for additional logo also,attached image is depends on the local path and image .Just correct me if i am wrong,so my request is there anyway we can add the image in both these case also as similar to html report .

My requirement is to share the report via mail...... added logo and spark report attachments are missing beacuse of this dpendency i feel. aftre i shared the report across

vishal131991 commented 3 years ago

@abhishekrhyme I went through your repo and I am using below code to capture screen shot in html report and its working as expected if(scenario.isFailed()) { ExtentCucumberAdapter.addTestStepScreenCaptureFromPath(getBase64Screenshot(Pojo.getDriver())); byte[] screenshotBytes = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); scenario.embed(screenshotBytes, "image/png"); }

But but it is strange that if I remove this snippet from the code byte[] screenshotBytes = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); scenario.embed(screenshotBytes, "image/png"); Then screenshots does not get attach with in the HTML report.

Any thought on this behaviour?

abhishekrhyme commented 3 years ago

Didn’t understand , the lines u remove r for capturing screenshot. So u can’t remove them if u aim for screenshots

On Fri, Oct 16, 2020 at 3:55 PM vishal131991 notifications@github.com wrote:

@abhishekrhyme https://github.com/abhishekrhyme I went through your repo and I am using below code to capture screen shot in html report and its working as expected if(scenario.isFailed()) {

ExtentCucumberAdapter.addTestStepScreenCaptureFromPath(getBase64Screenshot(Pojo.getDriver())); byte[] screenshotBytes = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); scenario.embed(screenshotBytes, "image/png"); }

But but it is strange that if I remove this snippet from the code byte[] screenshotBytes = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); scenario.embed(screenshotBytes, "image/png"); Then screenshots does not get attach with in the HTML report.

Any thought on this behaviour?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/extent-framework/extentreports-cucumber4-adapter/issues/48#issuecomment-709962542, or unsubscribe https://github.com/notifications/unsubscribe-auth/APAGTYDIAE674PKKWPR5RADSLANSTANCNFSM4MDMYXPQ .

--

Thanks & Regards

Abhishek Sen

Contact: +91 7618769358

https://www.linkedin.com/in/senabhishek/ https://www.linkedin.com/in/senabhishek/