Skip to content

Commit 338e086

Browse files
Merge pull request #13 from AlfredStenwin/development_local
Moved constants to GlobalConstants.java, Added ExtentReport.property file
2 parents 1e6548b + fbe3d47 commit 338e086

File tree

7 files changed

+57
-53
lines changed

7 files changed

+57
-53
lines changed

src/main/java/constants/GlobalConstants.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ public final class GlobalConstants {
44

55
private GlobalConstants() {}
66

7-
public static final String RUN_SETUP_CSV = System.getProperty("user.dir")+"/src/test/resources/RunSetup.csv";
8-
public static final String CONFIGFILE = System.getProperty("user.dir")+"/src/test/resources/Config.properties";
7+
public static final String RUNSETUP = System.getProperty("user.dir")+"/src/test/resources/RunSetup.csv";
8+
public static final String CONFIG = System.getProperty("user.dir")+"/src/test/resources/Config.properties";
9+
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";
11+
public static final String EXTENTREPORT_CONFIG = System.getProperty("user.dir")+"/src/test/resources/ExtentReport.properties";
912

1013
}

src/main/java/listeners/MethodInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestConte
3434
List<Map<String, String>> mapList = new ArrayList<>();
3535

3636
try {
37-
mapList.addAll(CsvReaderUtility.read(new File(GlobalConstants.RUN_SETUP_CSV)));
37+
mapList.addAll(CsvReaderUtility.read(new File(GlobalConstants.RUNSETUP)));
3838
testList=getListOfTestCasesToRun(methods, mapList);
3939

4040
} catch (IOException e) {

src/main/java/listeners/TestListener.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import java.io.IOException;
55
import java.util.Arrays;
66

7+
import org.openqa.selenium.OutputType;
8+
import org.openqa.selenium.TakesScreenshot;
79
import org.openqa.selenium.WebDriver;
10+
import org.openqa.selenium.WebDriverException;
811
import org.openqa.selenium.io.FileHandler;
912
import org.testng.ISuite;
1013
import org.testng.ISuiteListener;
@@ -16,6 +19,7 @@
1619
import com.aventstack.extentreports.ExtentTest;
1720
import com.aventstack.extentreports.Status;
1821

22+
import constants.GlobalConstants;
1923
import decorators.Driver;
2024
import logsetup.Log;
2125
import reports.ExtentReport;
@@ -70,15 +74,16 @@ public void onTestFailure(ITestResult result) {
7074
Driver driver = (Driver)result.getTestClass().getRealClass().getField("driver").get(result.getInstance());
7175

7276
//Take screenshot and copying to Screenshot folder in the project
73-
String screenshotsFolderPath =System.getProperty("user.dir")+"/Screenshots/"+testDesc+".png";
77+
String screenshotsFolderPath =GlobalConstants.SCREENSHOT_FOLDER + testDesc + ".png";
7478

7579
//Call takescreenshot() method from DriverLogger class and copying the screenshot from source path to Screenshot folder
76-
//FileHandler.copy(ScreenshotUtility.takescreenshot(driver), new File(screenshotsFolderPath));
80+
//FileHandler.copy(((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE),
81+
// new File(screenshotsFolderPath));
7782

7883
//Add screenshot from Screenshot folder to extent report
7984
//extentTest.addScreenCaptureFromPath(screenshotsFolderPath);
8085

81-
} catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException e) {
86+
} catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException | WebDriverException e) {
8287
e.printStackTrace();
8388
}
8489

src/main/java/reports/ExtentManager.java

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
package reports;
22

3-
import java.awt.Desktop;
43
import java.io.File;
5-
import java.io.IOException;
64
import java.util.Objects;
5+
import java.util.Properties;
76

87
import com.aventstack.extentreports.ExtentReports;
9-
import com.aventstack.extentreports.ExtentTest;
108
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
119
import com.aventstack.extentreports.reporter.configuration.Theme;
1210

11+
import constants.GlobalConstants;
12+
import logsetup.Log;
1313
import utilities.PropertyFileReader;
1414

1515
public final class ExtentReport {
1616

17+
// Parameters read from extentreports config file
18+
enum ConfigParameters {
19+
THEME,
20+
REPORT_NAME,
21+
DOCUMENT_TITLE,
22+
TIMESTAMP_FORMAT
23+
}
24+
1725
private static ExtentReports extentReport;
1826

1927
private ExtentReport() {}
@@ -23,26 +31,39 @@ private ExtentReport() {}
2331
* Improvemnt - parameter can be read from a config file
2432
*/
2533
public static ExtentReports initReport() {
26-
if(Objects.isNull(extentReport)) {
27-
String propertyFilePath = System.getProperty("user.dir")+"/src/test/resources/Config.properties";
28-
34+
Properties extentReportConfig = PropertyFileReader.readFile(GlobalConstants.EXTENTREPORT_CONFIG);
35+
String theme = extentReportConfig.get(ConfigParameters.THEME.name()).toString();
36+
String reportName = extentReportConfig.get(ConfigParameters.REPORT_NAME.name()).toString();
37+
String documentTitle = extentReportConfig.get(ConfigParameters.DOCUMENT_TITLE.name()).toString();
38+
String timeStampFormat = extentReportConfig.get(ConfigParameters.TIMESTAMP_FORMAT.name()).toString();
39+
40+
if(Objects.isNull(extentReport)) {
2941
extentReport = new ExtentReports();
3042
ExtentSparkReporter extentSparkReporter=new ExtentSparkReporter(
31-
new File(System.getProperty("user.dir")+"/ExtentReports/ExtentReports.html"));
43+
new File(GlobalConstants.EXTENTREPORT_HTML));
3244

3345
//attach the extentSparkReporter to extendReports object
3446
extentReport.attachReporter(extentSparkReporter);
3547

36-
//spark report configurations
37-
extentSparkReporter.config().setTheme(Theme.STANDARD);//DARK for dark theme
38-
extentSparkReporter.config().setReportName("Demo Test Automation Results");
39-
extentSparkReporter.config().setDocumentTitle("Demo Test Automation Results");
40-
extentSparkReporter.config().setTimeStampFormat("yyyy/MM/dd hh:mm:ss");
41-
48+
// SPark report configuration
49+
switch(theme.toLowerCase()) {
50+
case "standard":
51+
extentSparkReporter.config().setTheme(Theme.STANDARD);
52+
break;
53+
case "dark":
54+
extentSparkReporter.config().setTheme(Theme.DARK);
55+
break;
56+
default :
57+
Log.info("Invalid theme "+theme+" configured in " +GlobalConstants.EXTENTREPORT_CONFIG+" file. Please enter 'standard' or 'dark' for 'Theme'.");
58+
break;
59+
}
60+
61+
extentSparkReporter.config().setReportName(reportName);
62+
extentSparkReporter.config().setDocumentTitle(documentTitle);
63+
extentSparkReporter.config().setTimeStampFormat(timeStampFormat);
4264

4365
// setting test and system info from test/resources/Config.properties file
44-
extentReport.setSystemInfo("Application URL",
45-
PropertyFileReader.readFile(propertyFilePath).get("url").toString());
66+
extentReport.setSystemInfo("Application URL", PropertyFileReader.readFile(GlobalConstants.CONFIG).get("url").toString());
4667
extentReport.setSystemInfo("Operating System",System.getProperty("os.name"));
4768
extentReport.setSystemInfo("User name ",System.getProperty("user.name"));
4869
extentReport.setSystemInfo("Java version",System.getProperty("java.version"));
@@ -57,9 +78,4 @@ public static void flushReport() {
5778
extentReport.flush();
5879
}
5980
}
60-
61-
//Method to create test in extend reports
62-
public static void getTest(String testName) {
63-
ExtentManager.setExtentTest(extentReport.createTest(testName));
64-
}
6581
}

src/test/java/Tests/BaseTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class BaseTest {
2424
protected HomePage homePage;
2525
protected MainMenuSection mainMenuSection;
2626

27-
String url = PropertyFileReader.readFile(GlobalConstants.CONFIGFILE).get("url").toString();
27+
String url = PropertyFileReader.readFile(GlobalConstants.CONFIG).get("url").toString();
2828

2929
@Parameters({"browser"})
3030
@BeforeMethod
@@ -33,7 +33,7 @@ public void testInit(String browser) throws Exception {
3333
// Setup the driver of type Driver
3434
driver = new DriverLogger(new DriverBase());
3535

36-
// Add the Driver to Threadlocal from DriverManager
36+
// Add the Driver to Threadlocalmap from DriverManager
3737
DriverManager.setDriver(driver);
3838
Log.info("Driver set up Successfull.");
3939

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# theme options: STANDARD, DARK
2+
THEME=Standard
3+
REPORT_NAME=Selenium Test Automation
4+
DOCUMENT_TITLE=Demo Test Automation Results
5+
TIMESTAMP_FORMAT=yyyy/MM/dd hh:mm:ss

0 commit comments

Comments
 (0)