Skip to content

Commit 4b6edf2

Browse files
author
swtestacademy
committed
latest modifications done.
1 parent 0556ff9 commit 4b6edf2

File tree

6 files changed

+52
-69
lines changed

6 files changed

+52
-69
lines changed

ExtentReports/ExtentReportResults.html

Lines changed: 22 additions & 56 deletions
Large diffs are not rendered by default.

src/test/java/tests/LoginTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.testng.annotations.Test;
44
import pages.HomePage;
55
import pages.LoginPage;
6+
import utils.ExtentReports.ExtentTestManager;
67

78
public class LoginTests extends BaseTest {
89

@@ -12,8 +13,10 @@ public class LoginTests extends BaseTest {
1213
// Homepage homepage = new HomePage(driver,wait);
1314
// 3) super () method in page class transfer the driver and wait variables values to the BasePage class.
1415

15-
@Test (priority = 0)
16+
@Test (priority = 0, description="Invalid Login Scenario with wrong username and password.")
1617
public void invalidLoginTest_InvalidUserNameInvalidPassword () throws InterruptedException {
18+
//ExtentReports Description
19+
ExtentTestManager.getTest().setDescription("Invalid Login Scenario with wrong username and password.");
1720

1821
//*************PAGE INSTANTIATIONS*************
1922
HomePage homePage = new HomePage(driver,wait);
@@ -34,8 +37,11 @@ public void invalidLoginTest_InvalidUserNameInvalidPassword () throws Interrupte
3437
loginPage.verifyLoginPassword(("E-posta adresiniz veya şifreniz hatalı"));
3538
}
3639

37-
@Test (priority = 1)
40+
@Test (priority = 1, description="Invalid Login Scenario with empty username and password.")
3841
public void invalidLoginTest_EmptyUserEmptyPassword () throws InterruptedException {
42+
//ExtentReports Description
43+
ExtentTestManager.getTest().setDescription("Invalid Login Scenario with empty username and password.");
44+
3945
//*************PAGE INSTANTIATIONS*************
4046
HomePage homePage = new HomePage(driver,wait);
4147
LoginPage loginPage = new LoginPage(driver,wait);

src/test/java/utils/ExtentReports/ExtentManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class ExtentManager {
1010

1111
public synchronized static ExtentReports getReporter(){
1212
if(extent == null){
13+
//Set HTML reporting file location
1314
String workingDir = System.getProperty("user.dir");
1415
extent = new ExtentReports(workingDir+"\\ExtentReports\\ExtentReportResults.html", true);
1516
}

src/test/java/utils/ExtentReports/ExtentTestManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import java.util.HashMap;
77
import java.util.Map;
88

9-
/* OB: A map extentTestMap holds the information of the thread id and ExtentTest.
10-
* ExtentReports instance created by calling getReporter() method from ExtentManager.
11-
* At startTest() method, an instance of ExtentTest created and put into extentTestMap.
12-
* At endTest() method, test ends and thread id got from extentTestMap.
13-
* At getTest() method, information held in extentTestMap called.
9+
/* OB: extentTestMap holds the information of thread ids and ExtentTest instances.
10+
ExtentReports instance created by calling getReporter() method from ExtentManager.
11+
At startTest() method, an instance of ExtentTest created and put into extentTestMap with current thread id.
12+
At endTest() method, test ends and ExtentTest instance got from extentTestMap via current thread id.
13+
At getTest() method, return ExtentTest instance in extentTestMap by using current thread id.
1414
*/
1515

1616
public class ExtentTestManager {

src/test/java/utils/Listeners/Retry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public boolean retry(ITestResult iTestResult) {
1919
if (!iTestResult.isSuccess()) { //Check if test not succeed
2020
if (count < maxTry) { //Check if maxtry count is reached
2121
count++; //Increase the maxTry count by 1
22-
iTestResult.setStatus(ITestResult.FAILURE); //Mark test as failed
22+
iTestResult.setStatus(ITestResult.FAILURE); //Mark test as failed and take base64Screenshot
2323
extendReportsFailOperations(iTestResult); //ExtentReports fail operations
2424
return true; //Tells TestNG to re-run the test
2525
}

src/test/java/utils/Listeners/TestListener.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,52 @@ public void onStart(ITestContext iTestContext) {
2727
@Override
2828
public void onFinish(ITestContext iTestContext) {
2929
System.out.println("I am in onFinish method " + iTestContext.getName());
30+
//Do tier down operations for extentreports reporting!
3031
ExtentTestManager.endTest();
3132
ExtentManager.getReporter().flush();
3233
}
3334

3435
@Override
3536
public void onTestStart(ITestResult iTestResult) {
3637
System.out.println("I am in onTestStart method " + getTestMethodName(iTestResult) + " start");
38+
//Start operation for extentreports.
3739
ExtentTestManager.startTest(iTestResult.getMethod().getMethodName(),"");
3840
}
3941

4042
@Override
4143
public void onTestSuccess(ITestResult iTestResult) {
4244
System.out.println("I am in onTestSuccess method " + getTestMethodName(iTestResult) + " succeed");
45+
//Extentreports log operation for passed tests.
4346
ExtentTestManager.getTest().log(LogStatus.PASS, "Test passed");
44-
4547
}
4648

4749
@Override
4850
public void onTestFailure(ITestResult iTestResult) {
4951
System.out.println("I am in onTestFailure method " + getTestMethodName(iTestResult) + " failed");
52+
53+
//Get driver from BaseTest and assign to local webdriver variable.
5054
Object testClass = iTestResult.getInstance();
5155
WebDriver webDriver = ((BaseTest) testClass).getDriver();
52-
String base64Screenshot = "data:image/png;base64,"+((TakesScreenshot)webDriver).getScreenshotAs(OutputType.BASE64);
53-
ExtentTestManager.getTest().log(LogStatus.FAIL,"Test Failed", ExtentTestManager.getTest().addBase64ScreenShot(base64Screenshot));
56+
57+
//Take base64Screenshot screenshot.
58+
String base64Screenshot = "data:image/png;base64,"+((TakesScreenshot)webDriver).
59+
getScreenshotAs(OutputType.BASE64);
60+
61+
//Extentreports log and screenshot operations for failed tests.
62+
ExtentTestManager.getTest().log(LogStatus.FAIL,"Test Failed",
63+
ExtentTestManager.getTest().addBase64ScreenShot(base64Screenshot));
5464
}
5565

5666
@Override
5767
public void onTestSkipped(ITestResult iTestResult) {
5868
System.out.println("I am in onTestSkipped method "+ getTestMethodName(iTestResult) + " skipped");
69+
//Extentreports log operation for skipped tests.
70+
ExtentTestManager.getTest().log(LogStatus.SKIP, "Test Skipped");
5971
}
6072

6173
@Override
6274
public void onTestFailedButWithinSuccessPercentage(ITestResult iTestResult) {
6375
System.out.println("Test failed but it is in defined success ratio " + getTestMethodName(iTestResult));
64-
ExtentTestManager.getTest().log(LogStatus.SKIP, "Test Skipped");
6576
}
6677

67-
6878
}

0 commit comments

Comments
 (0)