From 8c67fcc302913d02d567a5b6d6249d8073509020 Mon Sep 17 00:00:00 2001 From: Anshoo Arora Date: Mon, 18 Sep 2023 13:59:04 -0400 Subject: [PATCH] fixes #331 - Gson error when merging reports due to Throwable#detailMessage --- .../extentreports/AbstractProcessor.java | 3 +- .../append/JsonDeserializer.java | 2 +- .../append/RawEntityConverter.java | 76 ++++++++++++------- .../extentreports/gson/BddTypeAdapter.java | 9 +-- .../gson/BddTypeAdapterFactory.java | 16 ---- .../gson/GsonExtentTypeAdapterBuilder.java | 8 +- .../gson/GsonTypeAdapterFactory.java | 22 ++++++ .../gson/ThrowableTypeAdapter.java | 38 ++++++++++ .../extentreports/model/ExceptionInfo.java | 7 +- .../aventstack/extentreports/model/Test.java | 3 +- .../extentreports/reporter/JsonFormatter.java | 12 +-- .../reporter/JsonFormatterBDDTest.java | 56 ++++++++++++-- .../reporter/JsonFormatterStandardTest.java | 54 +++++++++++-- .../reporter/SparkReporterTest.java | 30 ++++---- 14 files changed, 247 insertions(+), 89 deletions(-) delete mode 100644 src/main/java/com/aventstack/extentreports/gson/BddTypeAdapterFactory.java create mode 100644 src/main/java/com/aventstack/extentreports/gson/GsonTypeAdapterFactory.java create mode 100644 src/main/java/com/aventstack/extentreports/gson/ThrowableTypeAdapter.java diff --git a/src/main/java/com/aventstack/extentreports/AbstractProcessor.java b/src/main/java/com/aventstack/extentreports/AbstractProcessor.java index b6f5466..82aa40c 100644 --- a/src/main/java/com/aventstack/extentreports/AbstractProcessor.java +++ b/src/main/java/com/aventstack/extentreports/AbstractProcessor.java @@ -90,8 +90,9 @@ protected void onDeviceAdded(Device x, Test test) { @Override protected void onFlush() { getReport().refresh(); - if (!usingNaturalConf) + if (!usingNaturalConf) { getReport().applyOverrideConf(); + } super.onFlush(); } diff --git a/src/main/java/com/aventstack/extentreports/append/JsonDeserializer.java b/src/main/java/com/aventstack/extentreports/append/JsonDeserializer.java index c2342ad..76598bb 100644 --- a/src/main/java/com/aventstack/extentreports/append/JsonDeserializer.java +++ b/src/main/java/com/aventstack/extentreports/append/JsonDeserializer.java @@ -21,7 +21,7 @@ public JsonDeserializer(final File f) { public List deserialize() throws IOException { Gson gson = GsonExtentTypeAdapterBuilder.builder() - .withBddTypeAdapterFactory() + .withGsonTypeAdapterFactory() .withScreenCaptureTypeAdapter() .build(); String json = new String(Files.readAllBytes(f.toPath())); diff --git a/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java b/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java index 59a6f5e..efc83d6 100644 --- a/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java +++ b/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java @@ -8,12 +8,15 @@ import com.aventstack.extentreports.ExtentTest; import com.aventstack.extentreports.GherkinKeyword; import com.aventstack.extentreports.MediaEntityBuilder; +import com.aventstack.extentreports.model.ExceptionInfo; import com.aventstack.extentreports.model.Log; import com.aventstack.extentreports.model.Media; +import com.aventstack.extentreports.model.NamedAttribute; import com.aventstack.extentreports.model.ScreenCapture; import com.aventstack.extentreports.model.Test; public class RawEntityConverter { + private final ExtentReports extent; public RawEntityConverter(final ExtentReports extent) { @@ -26,43 +29,42 @@ public void convertAndApply(final File jsonFile) throws IOException { } extent.setReportUsesManualConfiguration(true); - List tests = new JsonDeserializer(jsonFile).deserialize(); - for (Test test : tests) { + final List tests = new JsonDeserializer(jsonFile).deserialize(); + + for (final Test test : tests) { + ExtentTest extentTest; try { - if (test.getBddType() == null) { - createDomain(test, extent.createTest(test.getName(), test.getDescription())); + if (test.isBDD()) { + final GherkinKeyword gk = new GherkinKeyword(test.getBddType().getSimpleName()); + extentTest = extent.createTest(gk, test.getName(), test.getDescription()); } else { - ExtentTest extentTest = extent.createTest(new GherkinKeyword(test.getBddType().getSimpleName()), - test.getName(), test.getDescription()); - createDomain(test, extentTest); + extentTest = extent.createTest(test.getName(), test.getDescription()); } + createDomain(test, extentTest); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } - public void createDomain(Test test, ExtentTest extentTest) throws ClassNotFoundException { + public void createDomain(final Test test, final ExtentTest extentTest) throws ClassNotFoundException { extentTest.getModel().setStartTime(test.getStartTime()); extentTest.getModel().setEndTime(test.getEndTime()); - addMedia(test, extentTest); + constructTestMedia(test, extentTest); // create events for (Log log : test.getLogs()) { - if (log.hasException() && log.hasMedia()) - addMedia(log, extentTest, log.getException().getException()); - else if (log.hasException()) - extentTest.log(log.getStatus(), log.getException().getException()); - else if (log.hasMedia()) - addMedia(log, extentTest, null); - else + if (log.hasException() || log.hasMedia()) { + constructLog(log, extentTest, log.getException()); + } else { extentTest.log(log.getStatus(), log.getDetails()); + } } // assign attributes - test.getAuthorSet().stream().map(x -> x.getName()).forEach(extentTest::assignAuthor); - test.getCategorySet().stream().map(x -> x.getName()).forEach(extentTest::assignCategory); - test.getDeviceSet().stream().map(x -> x.getName()).forEach(extentTest::assignDevice); + test.getAuthorSet().stream().map(NamedAttribute::getName).forEach(extentTest::assignAuthor); + test.getCategorySet().stream().map(NamedAttribute::getName).forEach(extentTest::assignCategory); + test.getDeviceSet().stream().map(NamedAttribute::getName).forEach(extentTest::assignDevice); // handle nodes for (Test node : test.getChildren()) { @@ -73,23 +75,38 @@ else if (log.hasMedia()) GherkinKeyword gk = new GherkinKeyword(node.getBddType().getSimpleName()); extentNode = extentTest.createNode(gk, node.getName(), node.getDescription()); } - addMedia(node, extentNode); + constructTestMedia(node, extentNode); createDomain(node, extentNode); } } - private void addMedia(Log log, ExtentTest extentTest, Throwable ex) { - Media m = log.getMedia(); - if (m.getPath() != null) { - extentTest.log(log.getStatus(), ex, - MediaEntityBuilder.createScreenCaptureFromPath(m.getPath()).build()); - } else if (((ScreenCapture) m).getBase64() != null) { - extentTest.log(log.getStatus(), ex, - MediaEntityBuilder.createScreenCaptureFromBase64String(((ScreenCapture) m).getBase64()).build()); + private void constructLog(final Log log, final ExtentTest extentTest, final ExceptionInfo ex) { + final Media m = log.getMedia(); + + if (m != null) { + if (m.getPath() != null) { + extentTest.log(log.getStatus(), + MediaEntityBuilder.createScreenCaptureFromPath(m.getPath()).build()); + } + if (((ScreenCapture) m).getBase64() != null) { + extentTest.log(log.getStatus(), + MediaEntityBuilder.createScreenCaptureFromBase64String(((ScreenCapture) m).getBase64()).build()); + } + } + + if (ex != null) { + if (!extentTest.getModel().hasLog()) { + extentTest.log(log.getStatus(), log.getDetails()); + } + + final List logs = extentTest.getModel().getLogs(); + final Log lastLog = logs.get(logs.size() - 1); + lastLog.setException(ex); + extentTest.getModel().getExceptions().add(ex); } } - private void addMedia(Test test, ExtentTest extentTest) { + private void constructTestMedia(final Test test, final ExtentTest extentTest) { if (test.getMedia() != null) { for (Media m : test.getMedia()) { if (m.getPath() != null) { @@ -100,4 +117,5 @@ private void addMedia(Test test, ExtentTest extentTest) { } } } + } diff --git a/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapter.java b/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapter.java index 78e161f..5783cb8 100644 --- a/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapter.java +++ b/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapter.java @@ -11,17 +11,16 @@ import com.google.gson.stream.JsonWriter; public class BddTypeAdapter extends TypeAdapter> { + private static final Logger LOG = Logger.getLogger(BddTypeAdapter.class.getName()); @SuppressWarnings("unchecked") @Override public Class read(final JsonReader reader) throws IOException { - int cycle = 0; while (reader.hasNext()) { - JsonToken token = reader.peek(); + final JsonToken token = reader.peek(); if ("string".equalsIgnoreCase(token.name())) { - token = reader.peek(); - String s = reader.nextString(); + final String s = reader.nextString(); if (s != null && !s.isEmpty()) { try { return (Class) Class.forName(s); @@ -30,8 +29,6 @@ public Class read(final JsonReader reader) thr } } } - if (cycle++ > 10) - return null; } return null; } diff --git a/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapterFactory.java b/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapterFactory.java deleted file mode 100644 index 441ccc2..0000000 --- a/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapterFactory.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.aventstack.extentreports.gson; - -import com.google.gson.Gson; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.reflect.TypeToken; - -public class BddTypeAdapterFactory implements TypeAdapterFactory { - @SuppressWarnings("unchecked") - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - if (!Class.class.isAssignableFrom(type.getRawType())) - return null; - return (TypeAdapter) new BddTypeAdapter(); - } -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/gson/GsonExtentTypeAdapterBuilder.java b/src/main/java/com/aventstack/extentreports/gson/GsonExtentTypeAdapterBuilder.java index 5c873d3..ec74290 100644 --- a/src/main/java/com/aventstack/extentreports/gson/GsonExtentTypeAdapterBuilder.java +++ b/src/main/java/com/aventstack/extentreports/gson/GsonExtentTypeAdapterBuilder.java @@ -6,15 +6,17 @@ import com.google.gson.GsonBuilder; public class GsonExtentTypeAdapterBuilder { + public static Builder builder() { return new Builder(); } public static class Builder { + GsonBuilder builder = new GsonBuilder(); - public Builder withBddTypeAdapterFactory() { - builder.registerTypeAdapterFactory(new BddTypeAdapterFactory()); + public Builder withGsonTypeAdapterFactory() { + builder.registerTypeAdapterFactory(new GsonTypeAdapterFactory()); return this; } @@ -26,5 +28,7 @@ public Builder withScreenCaptureTypeAdapter() { public Gson build() { return builder.create(); } + } + } diff --git a/src/main/java/com/aventstack/extentreports/gson/GsonTypeAdapterFactory.java b/src/main/java/com/aventstack/extentreports/gson/GsonTypeAdapterFactory.java new file mode 100644 index 0000000..ee0142c --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/gson/GsonTypeAdapterFactory.java @@ -0,0 +1,22 @@ +package com.aventstack.extentreports.gson; + +import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel; +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; + +public class GsonTypeAdapterFactory implements TypeAdapterFactory { + + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (Class.class.isAssignableFrom(type.getRawType()) && + type.getType().getTypeName().indexOf(IGherkinFormatterModel.class.getTypeName()) >= 0) { + return (TypeAdapter) new BddTypeAdapter(); + } + + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/gson/ThrowableTypeAdapter.java b/src/main/java/com/aventstack/extentreports/gson/ThrowableTypeAdapter.java new file mode 100644 index 0000000..a4898f4 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/gson/ThrowableTypeAdapter.java @@ -0,0 +1,38 @@ +package com.aventstack.extentreports.gson; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; + +public class ThrowableTypeAdapter extends TypeAdapter { + + @Override + public Throwable read(final JsonReader reader) { + return new UnsupportedOperationException(); + } + + @Override + public void write(final JsonWriter out, final Throwable value) throws IOException { + if (value == null) { + out.nullValue(); + return; + } + + out.beginObject(); + out.name("type"); + out.value(value.getClass().getSimpleName()); + + out.name("message"); + out.value(value.getMessage()); + + final Throwable cause = value.getCause(); + if (cause != null) { + out.name("cause"); + write(out, cause); + } + + out.endObject(); + } +} diff --git a/src/main/java/com/aventstack/extentreports/model/ExceptionInfo.java b/src/main/java/com/aventstack/extentreports/model/ExceptionInfo.java index 473be56..de4902e 100644 --- a/src/main/java/com/aventstack/extentreports/model/ExceptionInfo.java +++ b/src/main/java/com/aventstack/extentreports/model/ExceptionInfo.java @@ -11,14 +11,17 @@ @Setter @ToString public class ExceptionInfo extends NamedAttribute implements Serializable, BaseEntity { + private static final long serialVersionUID = -8152865623044194249L; - private Throwable exception; + + private transient Throwable exception; private String stackTrace; - + @Builder public ExceptionInfo(Throwable exception, String name, String stackTrace) { super(name); this.exception = exception; this.stackTrace = stackTrace; } + } diff --git a/src/main/java/com/aventstack/extentreports/model/Test.java b/src/main/java/com/aventstack/extentreports/model/Test.java index 80fdc14..c0329f4 100644 --- a/src/main/java/com/aventstack/extentreports/model/Test.java +++ b/src/main/java/com/aventstack/extentreports/model/Test.java @@ -83,8 +83,9 @@ public void addChild(Test child) { private void end(Status evtStatus) { setStatus(Status.max(status, evtStatus)); - if (useNaturalConf) + if (useNaturalConf) { propagateTime(); + } } private void propagateTime() { diff --git a/src/main/java/com/aventstack/extentreports/reporter/JsonFormatter.java b/src/main/java/com/aventstack/extentreports/reporter/JsonFormatter.java index ca6a4bb..1a2302b 100644 --- a/src/main/java/com/aventstack/extentreports/reporter/JsonFormatter.java +++ b/src/main/java/com/aventstack/extentreports/reporter/JsonFormatter.java @@ -49,10 +49,10 @@ public void onComplete() { private void flush(ReportEntity value) { Gson gson = GsonExtentTypeAdapterBuilder.builder() - .withBddTypeAdapterFactory() + .withGsonTypeAdapterFactory() .build(); final String filePath = getFileNameAsExt(FILE_NAME, new String[]{".json"}); - try (FileWriter writer = new FileWriter(new File(filePath))) { + try (FileWriter writer = new FileWriter(filePath)) { List list = value.getReport().getTestList(); gson.toJson(list, writer); } catch (IOException e) { @@ -61,19 +61,19 @@ private void flush(ReportEntity value) { } @Override - public void loadJSONConfig(File jsonFile) throws IOException { + public void loadJSONConfig(File jsonFile) { } @Override - public void loadJSONConfig(String jsonString) throws IOException { + public void loadJSONConfig(String jsonString) { } @Override - public void loadXMLConfig(File xmlFile) throws IOException { + public void loadXMLConfig(File xmlFile) { } @Override - public void loadXMLConfig(String xmlFile) throws IOException { + public void loadXMLConfig(String xmlFile) { } } diff --git a/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterBDDTest.java b/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterBDDTest.java index 4f76ede..1be973c 100644 --- a/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterBDDTest.java +++ b/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterBDDTest.java @@ -1,8 +1,12 @@ package com.aventstack.extentreports.reporter; import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.aventstack.extentreports.ExtentReports; @@ -12,10 +16,20 @@ import com.aventstack.extentreports.gherkin.model.Scenario; public class JsonFormatterBDDTest { - private static final String JSON_PATH = "target/extent.json"; + + private static final String BASE_PATH = "target/"; + private static final String JSON_PATH = BASE_PATH + "extent.json"; + + @BeforeMethod + public void beforeHook() { + try { + Files.createDirectories(Paths.get(BASE_PATH)); + Files.delete(Path.of(JSON_PATH)); + } catch (Exception ignored) { } + } @Test - public void writeBdd() throws UnsupportedEncodingException { + public void writeRead() throws IOException { ExtentReports extent = new ExtentReports(); extent.setGherkinDialect(GherkinDialectManager.getDefaultLanguage()); JsonFormatter json = new JsonFormatter(JSON_PATH); @@ -25,11 +39,43 @@ public void writeBdd() throws UnsupportedEncodingException { .createNode(Given.class, "Given ..") .pass("Pass"); extent.flush(); + + // read, recreate domain from JSON_PATH + extent.createDomainFromJsonArchive(JSON_PATH); + + executeAsserts(extent); + } + + private void executeAsserts(final ExtentReports extent) { + Assert.assertEquals(extent.getReport().getTestList().size(), 2); + Assert.assertEquals(extent.getReport().getTestList().get(0).getName(), + extent.getReport().getTestList().get(1).getName()); } - @Test(dependsOnMethods = "writeBdd") - public void readBdd() throws IOException { + @Test + public void supportsThrowable() throws IOException { + // write a failed test with an exception ExtentReports extent = new ExtentReports(); + extent.setGherkinDialect(GherkinDialectManager.getDefaultLanguage()); + JsonFormatter json = new JsonFormatter(JSON_PATH); + extent.attachReporter(json); + extent.createTest(Feature.class, "FeatureName") + .createNode(Scenario.class, "ScenarioName") + .createNode(Given.class, "Given ..") + .fail(new IllegalArgumentException("")); + extent.flush(); + + // read back the test with exception extent.createDomainFromJsonArchive(JSON_PATH); + + executeAsserts(extent); + + // check for exceptions + for (var test : extent.getReport().getTestList()) { + final com.aventstack.extentreports.model.Test step = test.getChildren().get(0).getChildren().get(0); + Assert.assertEquals(step.getExceptions().size(), 1); + Assert.assertEquals(step.getExceptions().get(0).getName(), IllegalArgumentException.class.getName()); + } } + } diff --git a/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterStandardTest.java b/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterStandardTest.java index 95b9f7d..5cc9788 100644 --- a/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterStandardTest.java +++ b/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterStandardTest.java @@ -1,26 +1,70 @@ package com.aventstack.extentreports.reporter; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.aventstack.extentreports.ExtentReports; public class JsonFormatterStandardTest { - private static final String JSON_PATH = "target/extent.json"; + + private static final String BASE_PATH = "target/"; + private static final String JSON_PATH = BASE_PATH + "extent.json"; + + @BeforeMethod + public void beforeHook() throws IOException { + try { + Files.createDirectories(Paths.get(BASE_PATH)); + Files.delete(Path.of(JSON_PATH)); + } catch (Exception ignored) { } + } @Test - public void writeStandard() { + public void writeRead() throws IOException { + // write ExtentReports extent = new ExtentReports(); JsonFormatter json = new JsonFormatter(JSON_PATH); extent.attachReporter(json); - extent.createTest("Test"); + extent.createTest("Test").pass("message"); extent.flush(); + + // read, recreate domain from JSON_PATH + extent.createDomainFromJsonArchive(JSON_PATH); + + executeAsserts(extent); + } + + private void executeAsserts(final ExtentReports extent) { + Assert.assertEquals(extent.getReport().getTestList().size(), 2); + Assert.assertEquals(extent.getReport().getTestList().get(0).getName(), + extent.getReport().getTestList().get(1).getName()); } - @Test(dependsOnMethods = "writeStandard") - public void readStandard() throws IOException { + @Test + public void supportsThrowable() throws IOException { + // write a failed test with an exception ExtentReports extent = new ExtentReports(); + JsonFormatter json = new JsonFormatter(JSON_PATH); + extent.attachReporter(json); + extent.createTest("Test") + .fail(new IllegalArgumentException("")); + extent.flush(); + + // read back the test with exception extent.createDomainFromJsonArchive(JSON_PATH); + + executeAsserts(extent); + + // check for exceptions + for (var test : extent.getReport().getTestList()) { + Assert.assertEquals(test.getExceptions().size(), 1); + Assert.assertEquals(test.getExceptions().get(0).getName(), IllegalArgumentException.class.getName()); + } } + } diff --git a/src/test/java/com/aventstack/extentreports/reporter/SparkReporterTest.java b/src/test/java/com/aventstack/extentreports/reporter/SparkReporterTest.java index 64490ab..2290cd3 100644 --- a/src/test/java/com/aventstack/extentreports/reporter/SparkReporterTest.java +++ b/src/test/java/com/aventstack/extentreports/reporter/SparkReporterTest.java @@ -18,20 +18,20 @@ public class SparkReporterTest { private static final String SCRIPTS = "spark-script.js"; private static final String STYLESHEET = "spark-style.css"; - private final String path() { + private final String getPath() { return FILE_PATH + Calendar.getInstance().getTimeInMillis() + FILE_NAME; } private void assertFileExists(String path) { File f = new File(path); Assert.assertTrue(f.exists()); - f.delete(); + //f.delete(); } @Test public void createsReportWithNoTestsInitPath() { ExtentReports extent = new ExtentReports(); - String path = path(); + String path = getPath(); ExtentSparkReporter spark = new ExtentSparkReporter(path); extent.attachReporter(spark); extent.flush(); @@ -41,7 +41,7 @@ public void createsReportWithNoTestsInitPath() { @Test public void createsReportWithNoTestsInitFile() { ExtentReports extent = new ExtentReports(); - String path = path(); + String path = getPath(); ExtentSparkReporter spark = new ExtentSparkReporter(new File(path)); extent.attachReporter(spark); extent.flush(); @@ -51,7 +51,7 @@ public void createsReportWithNoTestsInitFile() { @Test public void reportContainsTestsAndNodes() { ExtentReports extent = new ExtentReports(); - String path = path(); + String path = getPath(); ExtentSparkReporter spark = new ExtentSparkReporter(path); extent.attachReporter(spark); extent.createTest(PARENT) @@ -72,7 +72,7 @@ public void reportContainsTestsAndNodes() { @Test public void reportContainsTestsAndNodesTags() { ExtentReports extent = new ExtentReports(); - String path = path(); + String path = getPath(); ExtentSparkReporter spark = new ExtentSparkReporter(path); extent.attachReporter(spark); extent.createTest(PARENT).assignCategory("Tag1") @@ -91,7 +91,7 @@ public void reportContainsTestsAndNodesTags() { @Test public void reportContainsTestsAndNodesUsers() { ExtentReports extent = new ExtentReports(); - String path = path(); + String path = getPath(); ExtentSparkReporter spark = new ExtentSparkReporter(path); extent.attachReporter(spark); extent.createTest(PARENT).assignAuthor("Tag1") @@ -110,7 +110,7 @@ public void reportContainsTestsAndNodesUsers() { @Test public void reportContainsTestsAndNodesDevices() { ExtentReports extent = new ExtentReports(); - String path = path(); + String path = getPath(); ExtentSparkReporter spark = new ExtentSparkReporter(path); extent.attachReporter(spark); extent.createTest(PARENT).assignDevice("Tag1") @@ -129,7 +129,7 @@ public void reportContainsTestsAndNodesDevices() { @Test public void statusFilterable() { ExtentReports extent = new ExtentReports(); - String path = path(); + String path = getPath(); ExtentSparkReporter spark = new ExtentSparkReporter(path) .filter() .statusFilter() @@ -147,28 +147,28 @@ public void statusFilterable() { @Test public void statusFilterableNode() { ExtentReports extent = new ExtentReports(); - String path = path(); + String path = getPath(); ExtentSparkReporter spark = new ExtentSparkReporter(path) .filter() .statusFilter() .as(new Status[]{Status.FAIL}) .apply(); extent.attachReporter(spark); - extent.createTest(PARENT).pass("Pass"); - extent.createTest(CHILD).pass("Pass") + extent.createTest("PassedTest").pass(""); + extent.createTest(PARENT) + .createNode(CHILD).pass("Pass") .createNode(GRANDCHILD).fail("Fail"); extent.flush(); assertFileExists(path); Assert.assertEquals(spark.getReport().getTestList().size(), 1); - Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), CHILD); + Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), PARENT); Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().size(), 1); - Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getName(), GRANDCHILD); } @Test public void sparkOffline() { ExtentReports extent = new ExtentReports(); - String path = path(); + String path = getPath(); ExtentSparkReporter spark = new ExtentSparkReporter(path); spark.config().enableOfflineMode(true); extent.attachReporter(spark);