Skip to content

Commit

Permalink
Update reports package
Browse files Browse the repository at this point in the history
  • Loading branch information
anhtester committed Jan 14, 2024
1 parent 2d8b6aa commit 019ecc7
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ build/
.idea/
out/
*.iml
reports/
report/
logs/
*.log
23 changes: 23 additions & 0 deletions src/main/java/com/anhtester/reports/AllureManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.anhtester.reports;

import com.anhtester.drivers.DriverManager;
import io.qameta.allure.Attachment;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

public class AllureManager {

private AllureManager() {
}

@Attachment(value = "Page screenshot", type = "image/png")
public static byte[] saveScreenshotPNG() {
return ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
}

@Attachment(value = "{0}", type = "text/plain")
public static String saveTextLog(String message) {
return message;
}

}
20 changes: 20 additions & 0 deletions src/main/java/com/anhtester/reports/ExtentReportManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.anhtester.reports;

import com.anhtester.helpers.PropertiesHelper;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;

public class ExtentReportManager {

private static final ExtentReports extentReports = new ExtentReports();

public synchronized static ExtentReports getExtentReports() {
ExtentSparkReporter reporter = new ExtentSparkReporter(PropertiesHelper.getValue("EXTENT_REPORT_PATH"));
reporter.config().setReportName("Extent Report | " + PropertiesHelper.getValue("AUTHOR"));
extentReports.attachReporter(reporter);
// extentReports.setSystemInfo("Framework Name", "Test Automation Selenium Java");
// extentReports.setSystemInfo("Author", PropertiesHelper.getValue("AUTHOR"));
return extentReports;
}

}
51 changes: 51 additions & 0 deletions src/main/java/com/anhtester/reports/ExtentTestManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.anhtester.reports;

import com.anhtester.drivers.DriverManager;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.MediaEntityBuilder;
import com.aventstack.extentreports.Status;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

import java.util.HashMap;
import java.util.Map;

public class ExtentTestManager {
static Map<Integer, ExtentTest> extentTestMap = new HashMap<>();
static ExtentReports extent = ExtentReportManager.getExtentReports();

public static ExtentTest getTest() {
return extentTestMap.get((int) Thread.currentThread().getId());
}

public static synchronized ExtentTest saveToReport(String testName, String desc) {
ExtentTest test = extent.createTest(testName, desc);
extentTestMap.put((int) Thread.currentThread().getId(), test);
return test;
}

public static void addScreenShot(String message) {
String base64Image = "data:image/png;base64,"
+ ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BASE64);

getTest().log(Status.INFO, message,
MediaEntityBuilder.createScreenCaptureFromBase64String(base64Image).build());
}

public static void addScreenShot(Status status, String message) {
String base64Image = "data:image/png;base64,"
+ ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(OutputType.BASE64);

getTest().log(status, message,
MediaEntityBuilder.createScreenCaptureFromBase64String(base64Image).build());
}

public static void logMessage(String message) {
getTest().log(Status.INFO, message);
}

public static void logMessage(Status status, String message) {
getTest().log(status, message);
}
}
24 changes: 13 additions & 11 deletions src/test/resources/configs/configs.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
browser = chrome
email = admin@example.com
password = 123456
timeout = 20
url = https://crm.anhtester.com/admin/authentication
SCREENSHOT_PATH = reports/Screenshots/
VIDEO_RECORD_PATH = reports/VideoRecords/
HEADLESS = false
VIDEO_RECORD = false
SCREENSHOT_FAIL = true
SCREENSHOT_PASS = false
browser=chrome
email=admin@example.com
password=123456
timeout=20
url=https://crm.anhtester.com/admin/authentication
SCREENSHOT_PATH=report/Screenshots/
VIDEO_RECORD_PATH=report/VideoRecords/
EXTENT_REPORT_PATH=report/ExtentReport/ExtentReport.html
HEADLESS=false
VIDEO_RECORD=false
SCREENSHOT_FAIL=true
SCREENSHOT_PASS=false
AUTHOR=Anh Tester
2 changes: 1 addition & 1 deletion src/test/resources/suites/SuiteCRM.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Regression Test" verbose="1" parallel="none">
<suite name="Suite Regression Test CRM" verbose="1" parallel="none">
<test name="Login Test CRM CHROME" parallel="methods">
<parameter name="browser" value="chrome"></parameter>
<classes>
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/suites/SuiteLoginTest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Parallel Suite All" verbose="1">
<suite name="Suite Login Test" verbose="1">

<test name="Regression Test Parallel" parallel="methods">
<test name="Regression Test Login Parallel" parallel="methods">
<parameter name="browser" value="chrome"/>
<classes>
<class name="com.anhtester.Bai31_TestListener.testcases.LoginTest"/>
Expand Down

0 comments on commit 019ecc7

Please sign in to comment.