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

JSONFormatter v1.2x throws Gson unsupportedoperation exception #63

Closed grasshopper7 closed 4 years ago

grasshopper7 commented 4 years ago

Tried adapter v1.2x code with extent V5. Got below exception when creating Json report.

java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: com.aventstack.extentreports.gherkin.model.Feature. Forgot to register a type adapter? at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:73) at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:69) at com.google.gson.TypeAdapter$1.write(TypeAdapter.java:191) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245) at com.google.gson.internal.bind.ObjectTypeAdapter.write(ObjectTypeAdapter.java:107) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61) at com.google.gson.Gson.toJson(Gson.java:704) at com.google.gson.Gson.toJson(Gson.java:683) at com.google.gson.Gson.toJson(Gson.java:658) at com.aventstack.extentreports.reporter.JsonFormatter.flush(JsonFormatter.java:58) at com.aventstack.extentreports.reporter.JsonFormatter.access$0(JsonFormatter.java:50) at com.aventstack.extentreports.reporter.JsonFormatter$1.onNext(JsonFormatter.java:37) at com.aventstack.extentreports.reporter.JsonFormatter$1.onNext(JsonFormatter.java:1) at io.reactivex.rxjava3.subjects.PublishSubject$PublishDisposable.onNext(PublishSubject.java:310) at io.reactivex.rxjava3.subjects.PublishSubject.onNext(PublishSubject.java:226)

When I make the bddType field in Test.java transient, the report is generated. Similar to what was there in V4, though not sure if this is correct. https://github.com/extent-framework/extentreports-java/blob/1fd8bed14fd4aa1a8f3bb41d4d46c9267ff81416/src/main/java/com/aventstack/extentreports/model/Test.java#L53

Also facing the problem that spark and json report is not generated when folder structure is absent. Similar to this earlier issue. https://github.com/extent-framework/extentreports-cucumber4-adapter/issues/60#issuecomment-651027526

anshooarora commented 4 years ago

Ah! Gson does not understand the gherkin classes, thus throwing this error. I will fix this.

Regarding the folder structure, its only for JSON right? Spark should still work.

grasshopper7 commented 4 years ago

Nope spark is also not working without an existing folder structure.

anshooarora commented 4 years ago

fixed issues with TypeAdapter not recognizing Gherkin classes. Working on paths.

anshooarora commented 4 years ago

Fixed and deployed SNAPSHOT with the 2 fixes.

Note: if paths are supplied like so:

extent.reporter.spark.out=test-output/SparkReport/Spark.html
extent.reporter.json.out=test-output/JsonReport/json.json

Then all file-reporters will resolve them to the file-name.

If they are supplied like:

extent.reporter.spark.out=test-output/SparkReport/
extent.reporter.json.out=test-output/JsonReport/

Files will not be created under SparkReport or JsonReport. Instead, 2 files will be created in the below path:

test-output/SparkReport.html
test-output/JsonReport.json
anshooarora commented 4 years ago

If all looks good - then I think we are ready to release. :)

grasshopper7 commented 4 years ago

If they are supplied like:

extent.reporter.spark.out=test-output/SparkReport/
extent.reporter.json.out=test-output/JsonReport/

Files will not be created under SparkReport or JsonReport. Instead, 2 files will be created in the below path:

test-output/SparkReport.html
test-output/JsonReport.json

I think when creating reports with the above style, to display images for spark the screenshot setting (ie screenshot.rel.path) will need to be modified. Will test and check.

grasshopper7 commented 4 years ago

Json report is being generated now.

Works with the first approach when filenames are mentioned.

With the second approach, it is a bit confusing.

extent.reporter.spark.out=test-output/SparkReport/
extent.reporter.json.out=test-output/JsonReport/
  1. No test-output folder - Reports are generated in newly created test-output folder. But spark shows blank images. Tried different settings for screenshot property, did not work.
  2. Existing test-output\spark & test-output\json folder structure - Reports are generated in test-output\spark & test-output\json folder rather than in the test-output folder. Reports are with default names - index.html and extent.json.

On an additional note, suppose from one run of tests images are generated in test-output folder. In the next run, existing images are not deleted but reused. Is this correct behavior?

anshooarora commented 4 years ago

Okay - for paths then, I will port the version 4 approach.

New images are created for each run, if you check the modified date for each, it will be current.

anshooarora commented 4 years ago

The latest SNAPSHOT uses v4, which will create a fully qualified file name if user has not supplied a file with the known extensions. Below are the use cases:

test-output/SparkReport -> test-output/SparkReport/Index.html
test-output/SparkReport/ -> test-output/SparkReport/Index.html
test-output/SparkReport/Spark.html -> test-output/SparkReport/Spark.html

Using the above, if:

grasshopper7 commented 4 years ago

Works now.

anshooarora commented 4 years ago

Thanks for the confirmation. I will close this ticket and start preparing for release.

rahgir commented 4 years ago

@anshooarora : Any plans of releasing this new version soon ? I am waiting for this JSONFormatter fix :)

grasshopper7 commented 4 years ago

It is available in nexus - https://oss.sonatype.org/#nexus-search;quick~extentreports. Both extent and adapter4. U could download or wait for maven central to replicate.

rahgir commented 4 years ago

Thanks much :)