Skip to content

Commit 47afc81

Browse files
committed
Added Report Manager that was not uploaded in last commit and updated
the tests and global constants.
1 parent e4dc879 commit 47afc81

File tree

8 files changed

+44
-17
lines changed

8 files changed

+44
-17
lines changed

WebTestRunner.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</listeners>
1010

1111
<!-- Browser takes two values 'edge' and 'chrome'-->
12-
<parameter name = "browser" value = "chrome"></parameter>
12+
<parameter name = "browser" value = "edge"></parameter>
1313
<test name="Navigate to home page" thread-count="3">
1414
<classes>
1515
<class name="Tests.NewUserRegistration"/>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<dependency>
2020
<groupId>io.github.bonigarcia</groupId>
2121
<artifactId>webdrivermanager</artifactId>
22-
<version>5.0.3</version>
22+
<version>5.3.0</version>
2323
</dependency>
2424

2525
<!-- TestNG dependency-->

src/main/java/constants/GlobalConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ 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";
1011
public static final String EXTENTREPORT_CONFIG = System.getProperty("user.dir")+"/src/test/resources/ExtentReport.properties";
1112

1213
}

src/main/java/listeners/TestListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void onTestStart(ITestResult result) {
5656
extentTest = extentReport.createTest(testDesc);
5757
ReportManager.setExtentTest(extentTest);
5858
ReportManager.getExtentTest().log(Status.INFO, testDesc+" started." );
59-
Log.info("\""+testDesc+"\" execution started. EntentTest created");
59+
Log.info("\""+testDesc+"\" test execution started.");
6060

6161
}
6262

@@ -74,7 +74,7 @@ public void onTestFailure(ITestResult result) {
7474
String testDesc=result.getMethod().getDescription();
7575
try {
7676
//Take screenshot and copying to Screenshot folder in the project
77-
String screenshotsFolderPath =GlobalConstants.SCREENSHOT_FOLDER + testDesc + ".png";
77+
String screenshotsFolderPath = GlobalConstants.SCREENSHOT_FOLDER + testDesc + ".png";
7878

7979
//Call takescreenshot() method from DriverLogger class and copying the screenshot from source path to Screenshot folder
8080
FileHandler.copy(ScreenshotUtility.getscreenshot(),new File(screenshotsFolderPath));

src/main/java/reports/ExtentReport.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private ExtentReport() {}
3333
public static ExtentReports initReport() {
3434
Properties extentReportConfig = PropertyFileReader.readFile(GlobalConstants.EXTENTREPORT_CONFIG);
3535
String theme = extentReportConfig.get(ConfigParameters.THEME.name()).toString();
36-
String reportName = extentReportConfig.get(ConfigParameters.REPORT_NAME.name()).toString();
36+
String fileName = extentReportConfig.get(ConfigParameters.REPORT_NAME.name()).toString();
3737
String documentTitle = extentReportConfig.get(ConfigParameters.DOCUMENT_TITLE.name()).toString();
3838
String timeStampFormat = extentReportConfig.get(ConfigParameters.TIMESTAMP_FORMAT.name()).toString();
3939

@@ -58,7 +58,7 @@ public static ExtentReports initReport() {
5858
break;
5959
}
6060

61-
extentSparkReporter.config().setReportName(reportName);
61+
extentSparkReporter.config().setReportName(fileName);
6262
extentSparkReporter.config().setDocumentTitle(documentTitle);
6363
extentSparkReporter.config().setTimeStampFormat(timeStampFormat);
6464

@@ -76,6 +76,9 @@ public static ExtentReports initReport() {
7676
public static void flushReport() {
7777
if(Objects.nonNull(extentReport)) {
7878
extentReport.flush();
79+
80+
//to open the report in the default browser after flushing
81+
//Desktop.getDesktop().browse(new File(fileName).toURI());
7982
}
8083
}
8184
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package reports;
2+
3+
import com.aventstack.extentreports.ExtentTest;
4+
5+
public class ReportManager {
6+
7+
private ReportManager () {}
8+
9+
private static ThreadLocal<ExtentTest> xtnttest = new ThreadLocal<>();
10+
11+
public static ExtentTest getExtentTest() {
12+
return xtnttest.get();
13+
}
14+
15+
public static void setExtentTest(ExtentTest extentTest) {
16+
xtnttest.set(extentTest);
17+
}
18+
19+
public static void removeExtentTest() {
20+
xtnttest.remove();
21+
}
22+
23+
}

src/test/java/Tests/NewUserRegistration.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ public class NewUserRegistration extends BaseTest{
1313

1414
@Test
1515
public void navigateToHomepage() {
16-
String pageTitle = "Home Page - Magento eCommerce - website to practice selenium | demo website for automation testing | selenium practice sites | selenium demo sites | best website to practice selenium automation | automation practice sites Magento Commerce - website to practice selenium | demo website for automation testing | selenium practice sites";
17-
String title = homePage.gotoUrl(url).getPageTitle();
18-
Assert.assertEquals(title , pageTitle);
16+
String expectedTitle = "Home Page";
17+
String actualtitle = homePage.gotoUrl(url).getPageTitle();
18+
Assert.assertEquals(actualtitle , expectedTitle);
1919
Log.info("Completed test for Navigate to home page.");
2020
}
2121

2222
@Test
2323
public void navigateToUserSignupPage() {
24-
String pageTitle = "Create New Customer Account Magento Commerce - website to practice selenium | demo website for automation testing | selenium practice sites";
24+
String expectedTitle = "Create New Customer Account";
2525
homePage.gotoUrl(url).clickOnSignUpTab().getPageTitle();
26-
String title = userRegistrationPage.getPageTitle();
27-
Assert.assertEquals(title, pageTitle);
26+
String actualtitle = userRegistrationPage.getPageTitle();
27+
Assert.assertEquals(actualtitle, expectedTitle);
2828
Log.info("Completed test for Navigate to user signup page.");
2929
}
3030

3131
@Test( dataProvider = "dataProvider1" )
3232
public void registerNewUser(Map<String, Object> map) {
33-
String title = "My Account Magento Commerce - website to practice selenium | demo website for automation testing | selenium practice sites";
33+
String expectedTitle = "My Account";
3434
homePage.gotoUrl(url)
3535
.clickOnSignUpTab()
3636
.enterFirstname(map.get("firstname").toString())
@@ -40,8 +40,8 @@ public void registerNewUser(Map<String, Object> map) {
4040
.confirmPassword(map.get("password").toString())
4141
.ClickCreateAnAccountButton();
4242

43-
String pageTitle = myaccountsPage.GetPageTitle();
44-
Assert.assertEquals(pageTitle, title); // Expected to fail now as the page wont be displayed
43+
String actualTitle = myaccountsPage.GetPageTitle();
44+
Assert.assertEquals(actualTitle, expectedTitle); // Expected to fail now as the page wont be displayed
4545
Log.info("Completed test for Register new user.");
4646
}
4747

src/test/resources/Log4j2.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
status = warn
22
name= RollingFileLogConfigDemo
33

4-
# Log files location
5-
property.basePath = /IdealAutomationFramework/Advanced_Selenium_Framework/logs
4+
# Log files location - Add correct individual path to projects 'logs' folder below
5+
property.basePath = <ADD-PATH-TO-PROJECT>/Advanced-Selenium-Automation-Framework/logs
66

77
# RollingFileAppender name, pattern, path and rollover policy
88
appender.rolling.type = RollingFile

0 commit comments

Comments
 (0)