diff --git a/.gitignore b/.gitignore index dce0a7d..a205848 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,6 @@ build/ .idea/ out/ *.iml -reports/ report/ logs/ *.log \ No newline at end of file diff --git a/src/main/java/com/anhtester/reports/AllureManager.java b/src/main/java/com/anhtester/reports/AllureManager.java new file mode 100644 index 0000000..be68cac --- /dev/null +++ b/src/main/java/com/anhtester/reports/AllureManager.java @@ -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; + } + +} diff --git a/src/main/java/com/anhtester/reports/ExtentReportManager.java b/src/main/java/com/anhtester/reports/ExtentReportManager.java new file mode 100644 index 0000000..d4dac4f --- /dev/null +++ b/src/main/java/com/anhtester/reports/ExtentReportManager.java @@ -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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/anhtester/reports/ExtentTestManager.java b/src/main/java/com/anhtester/reports/ExtentTestManager.java new file mode 100644 index 0000000..832ced1 --- /dev/null +++ b/src/main/java/com/anhtester/reports/ExtentTestManager.java @@ -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 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); + } +} \ No newline at end of file diff --git a/src/test/resources/configs/configs.properties b/src/test/resources/configs/configs.properties index d3a4d5e..d1fd824 100644 --- a/src/test/resources/configs/configs.properties +++ b/src/test/resources/configs/configs.properties @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/src/test/resources/suites/SuiteCRM.xml b/src/test/resources/suites/SuiteCRM.xml index 61fb878..800ef4d 100644 --- a/src/test/resources/suites/SuiteCRM.xml +++ b/src/test/resources/suites/SuiteCRM.xml @@ -1,6 +1,6 @@ - + diff --git a/src/test/resources/suites/SuiteLoginTest.xml b/src/test/resources/suites/SuiteLoginTest.xml index 58bd001..7b18e4b 100644 --- a/src/test/resources/suites/SuiteLoginTest.xml +++ b/src/test/resources/suites/SuiteLoginTest.xml @@ -1,8 +1,8 @@ - + - +