|
1 | 1 | package com.aventstack.extentreports; |
2 | 2 |
|
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; |
5 | 8 |
|
6 | 9 | import org.testng.Assert; |
7 | 10 | import org.testng.annotations.Test; |
8 | 11 |
|
9 | | -import com.aventstack.extentreports.model.ScreenCapture; |
10 | | -import com.aventstack.extentreports.reporter.JsonFormatter; |
| 12 | +import java.io.IOException; |
| 13 | +import java.util.List; |
11 | 14 |
|
12 | 15 | public class AppenderTest { |
13 | 16 | private static final String JSON_ARCHIVE = "target/json/jsonArchive.json"; |
@@ -163,4 +166,38 @@ public void testWithMediaBase64() throws IOException { |
163 | 166 | Assert.assertEquals(((ScreenCapture) list.get(0).getLogs().get(0).getMedia()).getBase64(), |
164 | 167 | ((ScreenCapture) test1.getModel().getLogs().get(0).getMedia()).getBase64()); |
165 | 168 | } |
| 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 | + |
166 | 203 | } |
0 commit comments