Skip to content

Commit 4b37366

Browse files
committed
1 parent 548ee3d commit 4b37366

3 files changed

Lines changed: 47 additions & 6 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ hs_err_pid*
2727
.project
2828
.settings/
2929

30+
# netbeans
31+
nb-configuration.xml
32+
nbproject/
33+
3034
# java folders
3135
target/
3236
test-output/

src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ else if (log.hasMedia())
7878
private void addMedia(Log log, ExtentTest extentTest, Throwable ex) {
7979
Media m = log.getMedia();
8080
if (m.getPath() != null) {
81-
extentTest.log(log.getStatus(), ex,
81+
extentTest.log(log.getStatus(), log.getDetails(), ex,
8282
MediaEntityBuilder.createScreenCaptureFromPath(m.getPath()).build());
8383
} else if (((ScreenCapture) m).getBase64() != null) {
84-
extentTest.log(log.getStatus(), ex,
84+
extentTest.log(log.getStatus(), log.getDetails(), ex,
8585
MediaEntityBuilder.createScreenCaptureFromBase64String(((ScreenCapture) m).getBase64())
8686
.build());
8787
}

src/test/java/com/aventstack/extentreports/AppenderTest.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.aventstack.extentreports;
22

3-
import java.io.IOException;
4-
import java.util.List;
3+
import com.aventstack.extentreports.model.Log;
4+
import com.aventstack.extentreports.model.Media;
5+
import com.aventstack.extentreports.model.ScreenCapture;
6+
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
7+
import com.aventstack.extentreports.reporter.JsonFormatter;
58

69
import org.testng.Assert;
710
import org.testng.annotations.Test;
811

9-
import com.aventstack.extentreports.model.ScreenCapture;
10-
import com.aventstack.extentreports.reporter.JsonFormatter;
12+
import java.io.IOException;
13+
import java.util.List;
1114

1215
public class AppenderTest {
1316
private static final String JSON_ARCHIVE = "target/json/jsonArchive.json";
@@ -163,4 +166,38 @@ public void testWithMediaBase64() throws IOException {
163166
Assert.assertEquals(((ScreenCapture) list.get(0).getLogs().get(0).getMedia()).getBase64(),
164167
((ScreenCapture) test1.getModel().getLogs().get(0).getMedia()).getBase64());
165168
}
169+
170+
@Test
171+
public void appendWithSparkReporter() throws IOException {
172+
ExtentReports extent = new ExtentReports();
173+
String testNamePrefix = "Append Test ";
174+
String textWithoutScreenshotPrefix = "Just some random text ";
175+
String textWithScreenshotPrefix = "Some text explaining the screenshot ";
176+
for (int i = 1; i < 3; i++) {
177+
String reportPath = "target/append/index.html";
178+
String jsonPath = "target/append/index.json";
179+
ExtentSparkReporter sparkReporter = new ExtentSparkReporter(reportPath);
180+
JsonFormatter jsonReporter = new JsonFormatter(jsonPath);
181+
extent.createDomainFromJsonArchive(jsonPath);
182+
extent.attachReporter(jsonReporter, sparkReporter);
183+
Media screenshot = MediaEntityBuilder.createScreenCaptureFromPath("img.png").build();
184+
ExtentTest test = extent.createTest(testNamePrefix + i, "Test Description")
185+
.log(Status.INFO, textWithoutScreenshotPrefix + i, null, null)
186+
.log(Status.INFO, textWithScreenshotPrefix + i, null, screenshot);
187+
extent.flush();
188+
}
189+
for (com.aventstack.extentreports.model.Test test : extent.getReport().getTestList()) {
190+
if (test.getName().startsWith(testNamePrefix)) {
191+
String runNumber = test.getName().substring(testNamePrefix.length());
192+
for (Log logEntry : test.getLogs()) {
193+
Assert.assertEquals(Status.INFO, logEntry.getStatus());
194+
String details = logEntry.getDetails();
195+
if (logEntry.getMedia() != null) Assert.assertEquals(details, textWithScreenshotPrefix + runNumber);
196+
else Assert.assertEquals(details, textWithoutScreenshotPrefix + runNumber);
197+
}
198+
}
199+
}
200+
201+
}
202+
166203
}

0 commit comments

Comments
 (0)