| 15 | import com.force.config.ConfigurationManager; |
| 16 | |
| 17 | public abstract class HtmlReporter extends DriverFactory { |
| 18 | |
| 19 | private static ExtentReports extent; |
| 20 | private static final ThreadLocal<ExtentTest> parentTest = new ThreadLocal<ExtentTest>(); |
| 21 | private static final ThreadLocal<ExtentTest> test = new ThreadLocal<ExtentTest>(); |
| 22 | private static final ThreadLocal<String> testName = new ThreadLocal<String>(); |
| 23 | |
| 24 | |
| 25 | private String fileName = "result.html"; |
| 26 | private static String pattern = "dd-MMM-yyyy HH-mm-ss"; |
| 27 | |
| 28 | public String testcaseName, testDescription, authors, category, dataFileName, dataFileType; |
| 29 | public static String folderName = ""; |
| 30 | |
| 31 | public static String createFolder(String folderName) { |
| 32 | String date = new SimpleDateFormat(pattern).format(new Date()); |
| 33 | folderName = folderName+"/" + date; |
| 34 | |
| 35 | File folder = new File("./" + folderName); |
| 36 | if (!folder.exists()) { |
| 37 | folder.mkdir(); |
| 38 | } |
| 39 | return folderName; |
| 40 | } |
| 41 | |
| 42 | public synchronized void startReport() { |
| 43 | folderName = createFolder("reports"); |
| 44 | ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("./" + folderName + "/" + fileName); |
| 45 | htmlReporter.config().setTestViewChartLocation(ChartLocation.BOTTOM); |
| 46 | htmlReporter.config().setChartVisibilityOnOpen(!true); |
| 47 | htmlReporter.config().setTheme(Theme.STANDARD); |
| 48 | if(ConfigurationManager.configuration().reportTheme().equalsIgnoreCase("dark")) |
| 49 | htmlReporter.config().setTheme(Theme.DARK); |
| 50 | htmlReporter.config().setDocumentTitle(ConfigurationManager.configuration().reportTitle()); |
| 51 | htmlReporter.config().setEncoding("utf-8"); |
| 52 | htmlReporter.config().setReportName(ConfigurationManager.configuration().reportName()); |
| 53 | htmlReporter.setAppendExisting(true); |
| 54 | extent = new ExtentReports(); |
| 55 | extent.attachReporter(htmlReporter); |
| 56 | } |
| 57 | |
| 58 | public synchronized void startTestCase() { |
| 59 | ExtentTest parent = extent.createTest(testcaseName, testDescription); |
| 60 | parent.assignCategory(category); |
| 61 | parent.assignAuthor(authors); |
| 62 | parentTest.set(parent); |
| 63 | testName.set(testcaseName); |
| 64 | } |
| 65 | |
| 66 | public synchronized void setNode() { |
| 67 | ExtentTest child = parentTest.get().createNode(getTestName()); |
| 68 | test.set(child); |
| 69 | } |
| 70 | |
| 71 | public abstract String takeSnap(); |
| 72 | |
| 73 | public void reportStep(String desc, String status, boolean bSnap) { |
| 74 | synchronized (test) { |
nothing calls this directly
no outgoing calls
no test coverage detected