Skip to content

Commit

Permalink
Merge branch 'main' into executionSummaryReportFix
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedHazem95 committed Aug 12, 2024
2 parents bd09227 + fd84020 commit f475b44
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 83 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/e2eTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Native Selenium Grid
run: docker-compose -f src/main/resources/docker-compose/selenium4.yml up --scale chrome=0 --scale edge=0 --scale firefox=10 -d
run: docker compose -f src/main/resources/docker-compose/selenium4.yml up --scale chrome=0 --scale edge=0 --scale firefox=10 -d
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Native Selenium Grid
run: docker-compose -f src/main/resources/docker-compose/selenium4.yml up --scale chrome=10 --scale edge=0 --scale firefox=0 -d
run: docker compose -f src/main/resources/docker-compose/selenium4.yml up --scale chrome=10 --scale edge=0 --scale firefox=0 -d
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -250,7 +250,7 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Native Selenium Grid
run: docker-compose -f src/main/resources/docker-compose/selenium4.yml up --scale chrome=0 --scale edge=10 --scale firefox=0 -d
run: docker compose -f src/main/resources/docker-compose/selenium4.yml up --scale chrome=0 --scale edge=10 --scale firefox=0 -d
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -557,7 +557,7 @@ jobs:
node-version: '16'
- name: Set up Native Selenium Grid
if: runner.os == 'Linux'
run: docker-compose -f src/main/resources/docker-compose/selenium4.yml up --scale chrome=10 --scale edge=0 --scale firefox=0 -d
run: docker compose -f src/main/resources/docker-compose/selenium4.yml up --scale chrome=10 --scale edge=0 --scale firefox=0 -d
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -593,7 +593,7 @@ jobs:
with:
paths: "target/surefire-reports/junitreports/TEST-*.xml"
if: always()
Windows_Edge_Cucumber:
Windows_Edge_Cucumber_Local:
needs: [ Ubuntu_APIs ]
runs-on: windows-latest
steps:
Expand Down Expand Up @@ -633,7 +633,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: Windows_Edge_Cucumber_Allure
name: Windows_Edge_Cucumber_Local_Allure
path: "allure-report/*.html"
- name: Test Summary
uses: test-summary/action@v2
Expand Down
104 changes: 54 additions & 50 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.shafthq</groupId>
<artifactId>SHAFT_ENGINE</artifactId>
<version>8.2.20240624</version> <!-- UPDATE com.shaft.properties.internal > Internal -->
<version>8.3.20240803</version> <!-- UPDATE com.shaft.properties.internal > Internal -->
<name>${project.groupId}:${project.artifactId}</name>
<description>SHAFT is a unified test automation engine. Powered by best-in-class frameworks, SHAFT provides a
wizard-like syntax to drive your automation efficiently, maximize your ROI, and minimize your learning curve.
Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-bom</artifactId>
<version>2.28.0</version>
<version>2.28.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -114,7 +114,7 @@
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>9.2.3</version>
<version>9.3.0</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
Expand Down Expand Up @@ -480,7 +480,7 @@
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>12.7.1.jre11-preview</version>
<version>12.8.0.jre11</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/shaft/api/RestActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
import com.shaft.driver.DriverFactory;
import com.shaft.driver.SHAFT;
import com.shaft.tools.internal.support.JavaHelper;
import com.shaft.tools.io.ReportManager;
Expand Down Expand Up @@ -693,6 +694,8 @@ private static String prettyFormatXML(String input) {
}

private static void initializeSystemProperties() {
if (SHAFT.Properties.timeouts == null)
DriverFactory.reloadProperties();
HTTP_SOCKET_TIMEOUT = SHAFT.Properties.timeouts.apiSocketTimeout();
// timeout between two consecutive data packets in seconds
HTTP_CONNECTION_TIMEOUT = SHAFT.Properties.timeouts.apiConnectionTimeout();
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/shaft/listeners/TestNGListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class TestNGListener implements IAlterSuiteListener, IAnnotationTransform
@Getter
private static XmlTest xmlTest;

private static Thread allureEnvironmentSetup;

public static ProjectStructureManager.RunType identifyRunType() {
Supplier<Stream<?>> stacktraceSupplier = () -> Arrays.stream((new Throwable()).getStackTrace()).map(StackTraceElement::getClassName);
var isUsingJunitDiscovery = stacktraceSupplier.get().anyMatch(org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.class.getCanonicalName()::equals);
Expand Down Expand Up @@ -76,7 +78,7 @@ public static void engineSetup(ProjectStructureManager.RunType runType) {
ReportManagerHelper.logEngineVersion();
Thread.ofVirtual().start(UpdateChecker::check);
Thread.ofVirtual().start(ImageProcessingActions::loadOpenCV);
Thread.ofVirtual().start(AllureManager::initializeAllureReportingEnvironment);
allureEnvironmentSetup = Thread.ofVirtual().start(AllureManager::initializeAllureReportingEnvironment);
Thread.ofVirtual().start(ReportManagerHelper::cleanExecutionSummaryReportDirectory);
ReportManagerHelper.setDiscreteLogging(SHAFT.Properties.reporting.alwaysLogDiscreetly());
ReportManagerHelper.setDebugMode(SHAFT.Properties.reporting.debugMode());
Expand Down Expand Up @@ -202,6 +204,11 @@ public void onExecutionFinish() {
Thread.ofVirtual().start(JiraHelper::reportExecutionStatusToJira);
Thread.ofVirtual().start(GoogleTink::encrypt);
ReportManagerHelper.logEngineClosure();
try {
allureEnvironmentSetup.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
AllureManager.openAllureReportAfterExecution();
AllureManager.generateAllureReportArchive();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/shaft/properties/internal/Internal.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
})
public interface Internal extends EngineProperties<Internal> {
@Key("shaftEngineVersion")
@DefaultValue("8.2.20240624")
@DefaultValue("8.3.20240803")
String shaftEngineVersion();

@Key("watermarkImagePath")
@DefaultValue("https://raw.githubusercontent.com/ShaftHQ/SHAFT_ENGINE/main/src/main/resources/images/shaft_white_bg.png")
String watermarkImagePath();

@Key("allureVersion")
@DefaultValue("2.27.0")
@DefaultValue("2.30.0") //https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
String allureVersion();
}
43 changes: 23 additions & 20 deletions src/main/java/com/shaft/tools/io/internal/AllureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class AllureManager {
private static String allureBinaryPath = "";
private static String allureOutPutDirectory = "";

private static final TerminalActions internalTerminalSession = TerminalActions.getInstance(false,false,true);
private static final FileActions internalFileSession = FileActions.getInstance(true);

public static void initializeAllureReportingEnvironment() {
ReportManager.logDiscrete("Initializing Allure Reporting Environment...");
/*
Expand All @@ -42,24 +45,24 @@ public static void openAllureReportAfterExecution() {
}

private static void copyAndOpenAllure() {
FileActions.getInstance(true).copyFolder(allureOutPutDirectory, allureReportPath);
FileActions.getInstance(true).deleteFile(allureOutPutDirectory);
internalFileSession.copyFolder(allureOutPutDirectory, allureReportPath);
internalFileSession.deleteFile(allureOutPutDirectory);
String newFileName = renameAllureReport();
openAllureReport(newFileName);
}

private static String renameAllureReport() {
String newFileName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss-SSS")) + "_AllureReport.html";
FileActions.getInstance(true).renameFile(System.getProperty("user.dir") + File.separator + allureReportPath + File.separator + "index.html", newFileName);
internalFileSession.renameFile(System.getProperty("user.dir") + File.separator + allureReportPath + File.separator + "index.html", newFileName);
return newFileName;
}

private static void openAllureReport(String newFileName) {
if (SHAFT.Properties.reporting.openAllureReportAfterExecution()) {
if (SystemUtils.IS_OS_WINDOWS) {
SHAFT.CLI.terminal().performTerminalCommand(".\\" + allureReportPath + File.separator + newFileName);
internalTerminalSession.performTerminalCommand(".\\" + allureReportPath + File.separator + newFileName);
} else {
SHAFT.CLI.terminal().performTerminalCommand("open ./" + allureReportPath + File.separator + newFileName);
internalTerminalSession.performTerminalCommand("open ./" + allureReportPath + File.separator + newFileName);
}
}
}
Expand All @@ -79,23 +82,23 @@ private static void downloadAndExtractAllureBinaries() {
// already exist
String allureVersion = SHAFT.Properties.internal.allureVersion();
allureBinaryPath = allureExtractionLocation + "allure-" + allureVersion + File.separator + "bin" + File.separator + "allure";
if (!FileActions.getInstance(true).doesFileExist(allureBinaryPath)) {
if (!internalFileSession.doesFileExist(allureBinaryPath)) {
try {
FileActions.getInstance(true).deleteFolder(allureExtractionLocation);
internalFileSession.deleteFolder(allureExtractionLocation);
} catch (AssertionError e) {
ReportManager.logDiscrete("Couldn't clear the allure extraction directory. Kindly terminate any running java process or restart your machine to fix this issue.");
ReportManagerHelper.logDiscrete(e);
}
// download allure binary
URL allureArchive = FileActions.getInstance(true).downloadFile(
URL allureArchive = internalFileSession.downloadFile(
"https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/" + allureVersion
+ "/allure-commandline-" + allureVersion + ".zip",
"target" + File.separator + "allureBinary.zip");
FileActions.getInstance(true).unpackArchive(allureArchive, allureExtractionLocation);
internalFileSession.unpackArchive(allureArchive, allureExtractionLocation);

if (!SystemUtils.IS_OS_WINDOWS) {
// make allure executable on Unix-based shells
TerminalActions.getInstance(false, false, true).performTerminalCommand("chmod u+x " + allureBinaryPath);
internalTerminalSession.performTerminalCommand("chmod u+x " + allureBinaryPath);
}
}
}
Expand All @@ -113,7 +116,7 @@ private static void writeGenerateReportShellFilesToProjectDirectory() {
"set path=" + allureExtractionLocation + "allure-" + allureVersion + "\\bin;%path%",
"allure serve " + allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1) + " -h localhost",
"pause", "exit");
FileActions.getInstance(true).writeToFile("", "generate_allure_report.bat", commandsToServeAllureReport);
internalFileSession.writeToFile("", "generate_allure_report.bat", commandsToServeAllureReport);
} else {
// create Unix-based sh file
commandsToServeAllureReport = Arrays
Expand All @@ -124,17 +127,17 @@ private static void writeGenerateReportShellFilesToProjectDirectory() {
"exit"

);
FileActions.getInstance(true).writeToFile("", "generate_allure_report.sh", commandsToServeAllureReport);
internalFileSession.writeToFile("", "generate_allure_report.sh", commandsToServeAllureReport);
// make allure executable on Unix-based shells
TerminalActions.getInstance(false, false, true).performTerminalCommand("chmod u+x generate_allure_report.sh");
internalTerminalSession.performTerminalCommand("chmod u+x generate_allure_report.sh");
}
}

private static void cleanAllureResultsDirectory() {
// clean allure-results directory before execution
if (SHAFT.Properties.reporting.cleanAllureResultsDirectoryBeforeExecution()) {
try {
FileActions.getInstance(true).deleteFolder(allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1));
internalFileSession.deleteFolder(allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1));
} catch (Exception t) {
ReportManager.log("Failed to delete allure-results as it is currently open. Kindly restart your device to unlock the directory.");
}
Expand All @@ -145,10 +148,10 @@ private static void overrideAllurePluginConfiguration() {
String allureVersion = SHAFT.Properties.internal.allureVersion();
// extract allure from SHAFT_Engine jar
URL allureSHAFTConfigArchive = ReportManagerHelper.class.getResource("/resources/allure/allureBinary_SHAFTEngineConfigFiles.zip");
FileActions.getInstance(true).unpackArchive(allureSHAFTConfigArchive,
internalFileSession.unpackArchive(allureSHAFTConfigArchive,
allureExtractionLocation + "allure-" + allureVersion + File.separator);
// deleting custom-logo.svg to avoid generating extra folder with report in single mode
FileActions.getInstance(true).deleteFile(allureExtractionLocation + "allure-" + allureVersion + File.separator + "plugins" + File.separator + "custom-logo-plugin" + File.separator + "static" + File.separator + "custom-logo.svg");
internalFileSession.deleteFile(allureExtractionLocation + "allure-" + allureVersion + File.separator + "plugins" + File.separator + "custom-logo-plugin" + File.separator + "static" + File.separator + "custom-logo.svg");

}

Expand All @@ -166,12 +169,12 @@ private static void writeAllureReport() {
+ allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1)
+ " -o " + allureOutPutDirectory;
}
FileActions.getInstance(true).createFolder(allureOutPutDirectory);
TerminalActions.getInstance(false, false, true).performTerminalCommand(commandToCreateAllureReport);
internalFileSession.createFolder(allureOutPutDirectory);
internalTerminalSession.performTerminalCommand(commandToCreateAllureReport);
}

private static void createAllureReportArchive() {
FileActions.getInstance(true).zipFiles(allureReportPath + "/", "generatedReport_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss-SSS")) + ".zip");
internalFileSession.zipFiles(allureReportPath + "/", "generatedReport_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss-SSS")) + ".zip");
}

private static void writeEnvironmentVariablesToAllureResultsDirectory() {
Expand Down Expand Up @@ -205,7 +208,7 @@ private static void writeEnvironmentVariablesToAllureResultsDirectory() {
}
}
propertiesFileBuilder.append("</environment>");
FileActions.getInstance(true).writeToFile(SHAFT.Properties.paths.allureResults(), "environment.xml",
internalFileSession.writeToFile(SHAFT.Properties.paths.allureResults(), "environment.xml",
RestActions.formatXML(propertiesFileBuilder.toString()));
}
}
15 changes: 15 additions & 0 deletions src/test/java/testPackage/legacy/BasicAPITests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package testPackage.legacy;

import com.shaft.driver.SHAFT;
import org.testng.annotations.Test;

public class BasicAPITests {
SHAFT.API api;

@Test
public void apiTest(){
api = new SHAFT.API("https://fakerestapi.azurewebsites.net");
api.get("/api/v1/Authors")
.performRequest();
}
}

0 comments on commit f475b44

Please sign in to comment.