Skip to content

Commit bcda77a

Browse files
Merge pull request #15 from AlfredStenwin/development_local
Added threadlocal to extentreport to make the Extenttest thread safe.
2 parents e2d1ba7 + 1c594bd commit bcda77a

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/main/java/constants/GlobalConstants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ private GlobalConstants() {}
77
public static final String RUNSETUP = System.getProperty("user.dir")+"/src/test/resources/RunSetup.csv";
88
public static final String CONFIG = System.getProperty("user.dir")+"/src/test/resources/Config.properties";
99
public static final String SCREENSHOT_FOLDER = System.getProperty("user.dir")+"/Screenshots/";
10-
public static final String EXTENTREPORT_HTML = System.getProperty("user.dir")+"/ExtentReports/ExtentReports.html";
1110
public static final String EXTENTREPORT_CONFIG = System.getProperty("user.dir")+"/src/test/resources/ExtentReport.properties";
1211

1312
}

src/main/java/listeners/TestListener.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import drivermanager.DriverManager;
2525
import logsetup.Log;
2626
import reports.ExtentReport;
27+
import reports.ReportManager;
2728
import utilities.ScreenshotUtility;
2829

2930
public class TestListener implements ITestListener, ISuiteListener{
@@ -53,15 +54,17 @@ public void onStart(ITestContext context) {
5354
public void onTestStart(ITestResult result) {
5455
String testDesc=result.getMethod().getDescription();
5556
extentTest = extentReport.createTest(testDesc);
56-
extentTest.log(Status.INFO, testDesc+" started." );
57+
ReportManager.setExtentTest(extentTest);
58+
ReportManager.getExtentTest().log(Status.INFO, testDesc+" started." );
5759
Log.info("\""+testDesc+"\" execution started. EntentTest created");
5860

5961
}
6062

6163
@Override
6264
public void onTestSuccess(ITestResult result) {
6365
String testDesc=result.getMethod().getDescription();
64-
extentTest.log(Status.PASS, testDesc+" test passed." );
66+
ReportManager.getExtentTest().log(Status.PASS, testDesc+" test passed." );
67+
ReportManager.removeExtentTest();
6568
Log.info("\""+testDesc+"\" passed.");
6669

6770
}
@@ -77,22 +80,24 @@ public void onTestFailure(ITestResult result) {
7780
FileHandler.copy(ScreenshotUtility.getscreenshot(),new File(screenshotsFolderPath));
7881

7982
//Add screenshot from Screenshot folder to extent report
80-
extentTest.addScreenCaptureFromPath(screenshotsFolderPath);
83+
ReportManager.getExtentTest().addScreenCaptureFromPath(screenshotsFolderPath);
8184

8285
} catch (IllegalArgumentException | SecurityException | WebDriverException | IOException e) {
8386
e.printStackTrace();
8487
}
8588

86-
extentTest.log(Status.FAIL, testDesc +" failed.");
87-
extentTest.fail(Arrays.toString(result.getThrowable().getStackTrace()));//beautify stacktrace
89+
ReportManager.getExtentTest().log(Status.FAIL, testDesc +" failed.");
90+
ReportManager.getExtentTest().fail(Arrays.toString(result.getThrowable().getStackTrace()));//beautify stacktrace
91+
ReportManager.removeExtentTest();
8892
Log.error("\""+result.getName()+"\" failed.", result.getThrowable());
8993
}
9094

9195
@Override
9296
public void onTestSkipped(ITestResult result) {
9397
String testName=result.getName();
94-
extentTest.log(Status.SKIP, testName +" skipped.");
95-
extentTest.skip(Arrays.toString(result.getThrowable().getStackTrace()));
98+
ReportManager.getExtentTest().log(Status.SKIP, testName +" skipped.");
99+
ReportManager.getExtentTest().skip(Arrays.toString(result.getThrowable().getStackTrace()));
100+
ReportManager.removeExtentTest();
96101
Log.error("\""+result.getName()+"\" skipped.", result.getThrowable());
97102
}
98103

src/test/resources/ExtentReport.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
THEME=Standard
33
REPORT_NAME=Selenium Test Automation
44
DOCUMENT_TITLE=Demo Test Automation Results
5-
TIMESTAMP_FORMAT=yyyy/MM/dd hh:mm:ss
5+
TIMESTAMP_FORMAT=yyyy-MM-dd hh:mm:ss

0 commit comments

Comments
 (0)