extent-framework / extentreports-java

Extent Reporting Library, Java
http://extentreports.com
Apache License 2.0
226 stars 130 forks source link

Query: How to add logs for cucumber extent report? #383

Open Snehaveeranna opened 1 year ago

Snehaveeranna commented 1 year ago

How to add logs like "opening broswers" in cucumber report under Steps.

Below is the sample step i am following: ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), "Refund item"); ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Jeff returns a faulty microwave"); scenario.createNode(new GherkinKeyword("Given"), "Jeff has bought a microwave for $100").pass("pass"); feature.info("logging"); scenario.createNode(new GherkinKeyword("And"), "he has a receipt").pass("pass"); scenario.createNode(new GherkinKeyword("When"), "he returns the microwave").pass("pass"); scenario.createNode(new GherkinKeyword("Then"), "Jeff should be refunded $100").fail("fail");

Here, i am trying to log but its not showing in report. Attached screenshot for reference. image

Snehaveeranna commented 1 year ago

Also, please help in achieving this. I need to integrate extent report to my Cucumber with Playwright framework. Presently i am using extent cucumber adaptor and since we are not able to call the extent report, my reports are overlapping. Could you please suggest me some work around, where report should have scenario name and Steps inside this and insider each steps i can add customized logs.

grasshopper7 commented 1 year ago

In the adapter you can access the currently executing step and scenario by using the static methods. https://github.com/grasshopper7/extentreports-cucumber7-adapter/blob/049d5b823ce9c2c29bc90c901876ca4f96b9eb19/extentreports-cucumber7-adapter/src/main/java/com/aventstack/extentreports/cucumber/adapter/ExtentCucumberAdapter.java#L515. You do not need to write code that creates the extent test structure.

To add your custom logs to the step you can also use the cucumber log methods.

Snehaveeranna commented 1 year ago

I am already using Addstep method, but when element is not found sometimes report is overlapping. Is there any way to start and close the extent report?

grasshopper7 commented 1 year ago

What do you mean by overlapping? Can you add an image of this?

Snehaveeranna commented 1 year ago

image This is not the proper way of reporting right?

grasshopper7 commented 1 year ago

Nope this is not correct. Is this the report generated when you use only the adapter?

Also is this the HTML report? Have you tried with the Spark report?

Can you give some more details when this is happening?

Snehaveeranna commented 1 year ago

Hi, yes even in Spark report we are facing same issue. When we are running test cases in batch using Cucumber format, if element is not identified in once step then it will continue to next step. during these scenarios it is failing.

grasshopper7 commented 1 year ago

Hi, Can you create a sample code in a public repo which is generating this error? I am unable to recreate this. Would be very helpful.

Snehaveeranna commented 1 year ago

Hi, is there any sample project where extent report is used with cucumber Java?

Snehaveeranna commented 1 year ago

Hi,

Is it possible to identify the issue if i provide complete HTML for correct report and overlapped report?

grasshopper7 commented 1 year ago

That would help. Can you replicate the issue with sample code?

grasshopper7 commented 1 year ago

I have tried to replicate this issue in numerous ways but unable to replicate it. Seems to be some HTML character which is causing the report display to be spoiled. I would need your help on this by providing the report and if possible a sample code.

Snehaveeranna commented 1 year ago

Hi, I am unable to replicate with sample code. But i have correct and corrupted html details of that. I will add that here. Overlapped report.txt Correct Report.txt

grasshopper7 commented 1 year ago

Thanks I will have a look at these files.

Snehaveeranna commented 1 year ago

And i also observed combining of logs. When 2 test cases fails then logs are combining. The second test case logs are not fully displayed. I have attached screenshot and HTML for reference. [Uploading Combining report.txt…]()

image

grasshopper7 commented 1 year ago

The previous file is not uploaded. Can you try again? Can you also share the correct and incorrect reports with the Spark report.

Snehaveeranna commented 1 year ago

Spark Overalapped report.txt Combining report.txt

Spark combined report.txt

I dont have spark correct report. But i have attached combined report with spark.

Snehaveeranna commented 1 year ago

What i observed in combining report issue is, i can see all steps for 2nd testcase in HTML but it is not showing in report UI.

grasshopper7 commented 1 year ago

What does the 'Student groups and Student Ledger' feature file contain (from the Spark report). I mean does it contain scenario outlines also? Just send me the list of scenario\scenariooutline with names.

Snehaveeranna commented 1 year ago

One more info, if you use these two lines together for same step it is combining or sometimes even wont log anything after this.

ExtentCucumberAdapter.getCurrentStep().log(Status.FAIL, MediaEntityBuilder.createScreenCaptureFromBase64String(PlaywrightFactory.takeScreenshot()).build()); ExtentCucumberAdapter.getCurrentStep().log(Status.FAIL, e.getMessage());

grasshopper7 commented 1 year ago

Hi Can you also add the feature file(s)? It will be very helpful.

Why are you adding log for exception and screen images? The adapter will handle it automatically. This is confusing.

grasshopper7 commented 1 year ago

Refer to the sample project Screenshots -> https://github.com/grasshopper7/cuke7-extent-adapter-report/blob/59bc1098f7dfb74495564fcc03ea0e4fce7dfbe2/cuke7-extent-adapter-report/src/test/java/stepdefs/Stepdefs.java#L218 -- Using scenario.attach()

Text log -> https://github.com/grasshopper7/cuke7-extent-adapter-report/blob/59bc1098f7dfb74495564fcc03ea0e4fce7dfbe2/cuke7-extent-adapter-report/src/test/java/stepdefs/Stepdefs.java#L109 -- Using scenario.log()

Exception -> Any exception thrown by selenium or playwright is sent to the adapter by cucumber events and is added to the step test. -> https://github.com/grasshopper7/extentreports-cucumber7-adapter/blob/049d5b823ce9c2c29bc90c901876ca4f96b9eb19/extentreports-cucumber7-adapter/src/main/java/com/aventstack/extentreports/cucumber/adapter/ExtentCucumberAdapter.java#L190

I am not sure why you have such a messed up report. I would comment all the custom logs or tests you might have added in the step definition and run the test. Do not add your own custom tests to the currently executing step or scenario.

Snehaveeranna commented 1 year ago

So we should use scenario.log instead of adaptor log. Then where and when can we use adaptor log?

grasshopper7 commented 1 year ago

only in cases where the scenario object is not accessible. Best to be avoided.

I think you are explicitly adding extent tests to the scenario object in your code.

Snehaveeranna commented 1 year ago

Previously i was using only adaptor log and screenshot, as you have suggested i have updated everything to scenario.log. It was working fine when i ran 2 feature file in batch but when i tried with 6 feature file it again overlapped.

grasshopper7 commented 1 year ago

Check if you have added extent tests to scenario test. Try running features individually and check.

Snehaveeranna commented 1 year ago

Individually it was working fine. Let me explain you the scenario. I have 1 class where i have overridden page class methods and after the method i want to log the actions in extent report, this is one scenario. And i have page class where i am doing action and here i am comparing 2 values if it is matching i want to print in extent report as it is matching if not then not matching. So should i use in these case?

grasshopper7 commented 1 year ago

Hard to comment without access to code. As long as the page methods are called from stepdefinitions method everything should work. Log actions using scenario.log() in step definition and for assertions just use the assert() method. No need to explicitly log this.

Snehaveeranna commented 1 year ago

There is one bug in this html report. If you click on the Test case hyperlink it will not go to the same test case step.