Skip to content

Commit

Permalink
Allure enhancements (#1485)
Browse files Browse the repository at this point in the history
* isolate AllureManager

* implement desired functionality

- SHAFT will now generate the report as a single html file under the allure-reports directory.
- The user can choose to clear the allure-results or not. both cases would work.
- If the user decides to clear the allure-results, then the allure-reports directory will contain one report per test run.
- If the user decides to keep the allure-results then the history will accumulate and the allure-report html files will be also accumulating.
- optimimzed logging for the target platform
- added platform icon functionality / to be implemented
- optimized the github actions yml file
- added method in file actions to rename files
- refactored attached important links to remove configuration manager
- fixed issue to enforce all terminal processes created by SHAFT to read the JAVA_HOME

* Update LocatorBuilderTest.java

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>

---------

Signed-off-by: Mohab Mohie <Mohab.MohieElDeen@outlook.com>
  • Loading branch information
MohabMohie committed Feb 9, 2024
1 parent fb95533 commit 88be461
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 524 deletions.
313 changes: 21 additions & 292 deletions .github/workflows/e2eTests.yml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/main/java/com/shaft/cli/FileActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ public void copyFile(String sourceFilePath, String destinationFilePath) {
passAction("Source File: \"" + sourceFilePath + "\" | Destination File: \"" + destinationFilePath + "\"");
}

public void renameFile(String filePath, String newFileName) {
try {
var targetFile = new File(filePath);
String targetDirectory = targetFile.getParentFile().getAbsolutePath();
FileUtils.copyFile(targetFile, new File(targetDirectory + File.separator + newFileName));
FileUtils.deleteQuietly(targetFile);
passAction("Target File Path: \"" + filePath + "\", file was renamed to \"" + newFileName + "\".");
} catch (IOException e) {
failAction(e);
}
}

/**
* Copies files from sourceDirectory to destinationDirectory using the provided
* terminalSession. References: <a href="https://www.computerhope.com/unix/ucp.htm">computer hope/unix/ucp.htm</a>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/shaft/cli/TerminalActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ private List<String> executeLocalCommand(List<String> commands, String longComma
ReportManager.logDiscrete("Executing: \"" + command + "\" locally.");
try {
ProcessBuilder pb = getProcessBuilder(command, finalDirectory, isWindows);
pb.environment().put("JAVA_HOME", System.getProperty("java.home"));
if (!asynchronous) {
pb.redirectErrorStream(true);
Process localProcess = pb.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
import io.github.bonigarcia.wdm.config.WebDriverManagerException;
import io.qameta.allure.Step;
import lombok.*;
import org.apache.logging.log4j.Level;
Expand Down Expand Up @@ -123,7 +124,7 @@ private static DriverType getDriverTypeFromName(String driverName) {
return DriverType.CHROME;
}

@SneakyThrows(java.lang.InterruptedException.class)
@SneakyThrows(InterruptedException.class)
private static int attemptRemoteServerPing() {
boolean serverReady = false;
var session = new SHAFT.API(TARGET_HUB_URL);
Expand Down Expand Up @@ -158,7 +159,7 @@ private static int attemptRemoteServerPing() {
return statusCode;
}

@SneakyThrows({java.net.MalformedURLException.class, InterruptedException.class})
@SneakyThrows({MalformedURLException.class, InterruptedException.class})
private static WebDriver attemptRemoteServerConnection(Capabilities capabilities) {
WebDriver driver = null;
boolean isRemoteConnectionEstablished = false;
Expand All @@ -168,12 +169,12 @@ private static WebDriver attemptRemoteServerConnection(Capabilities capabilities
try {
driver = connectToRemoteServer(capabilities, false);
isRemoteConnectionEstablished = true;
} catch (org.openqa.selenium.SessionNotCreatedException | URISyntaxException sessionNotCreatedException1) {
} catch (SessionNotCreatedException | URISyntaxException sessionNotCreatedException1) {
exception = sessionNotCreatedException1.getMessage();
try {
driver = connectToRemoteServer(capabilities, true);
isRemoteConnectionEstablished = true;
} catch (org.openqa.selenium.SessionNotCreatedException |
} catch (SessionNotCreatedException |
URISyntaxException sessionNotCreatedException2) {
// do nothing
ReportManagerHelper.logDiscrete(sessionNotCreatedException1, Level.DEBUG);
Expand Down Expand Up @@ -281,10 +282,12 @@ private void disableCacheEdgeAndChrome() {
}

private void createNewLocalDriverInstance(DriverType driverType, int retryAttempts) {
String initialLog = "Attempting to run locally on: \"" + Properties.platform.targetPlatform() + " | " + JavaHelper.convertToSentenceCase(driverType.getValue()) + "\"";
String targetPlatform = Properties.platform.targetPlatform().toLowerCase();
String initialLog = "Attempting to run locally on: \"" + targetPlatform + " | " + JavaHelper.convertToSentenceCase(driverType.getValue()) + "\"";
if (SHAFT.Properties.web.headlessExecution()) {
initialLog = initialLog + ", Headless Execution";
}
initialLog = initialLog.replace(targetPlatform, JavaHelper.convertToSentenceCase(targetPlatform) + getPlatformIcon(targetPlatform));
ReportManager.logDiscrete(initialLog + ".");
try {
ReportManager.logDiscrete(WEB_DRIVER_MANAGER_MESSAGE);
Expand Down Expand Up @@ -345,6 +348,18 @@ private void createNewLocalDriverInstance(DriverType driverType, int retryAttemp
}
}

//TODO: Implement
private String getPlatformIcon(String targetPlatform) {
return "";
// return switch (targetPlatform){
// case "linux" -> "<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAUCAYAAACEYr13AAADMklEQVQ4T42Uf0yNURjHv+c9b7f3jXT7sWGYSWmWoutHo6jMmB8ZMhTKjz8YW9ZqzIyVYbmEja3ZpGtLZsgwNJmhZcVifkSoRe7yq7f8qu7tnvO+dq57W+6yebb3j/Oc836e53yf5zkEAxsBYPhsDeSDcPqaBEAHEAVgqyzLvYyxYgDNgPv8X2BfgHcdCOAFAUapAQFQVfWTpmkWAJ880fogvgAKgANIDA0Nrta0Tld09Hje0vJO6e7uyQFwDIAMgHnTHhCgKMrsdRu33H739okxfVaqfvPGFVr74N5BADv/CyDLSmJh9ojqrDXUqH9l4vmHv8u1Tz4cArADgMjynxkIAYVFntgW0LhyMYfDNZJvLqS05mn7/W+dHUkegLim2wa8gp+fssFWeqokjLzmMYlZ9EF9o56xahnRdX0eY6yqP6Q/QEQX6lrS01dVl5ef8//l0MlgRSI/vnfoYyOiSH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aGqABVHoupQpzeEzd/c/mrYeSHwYCgDhO0zswCgQGtaRKVzUPlSUaPF3SmpNfOPU/e3ugafjCshaM/rPs8twXfW4CRAl5gFfrQFXioCd4DLpRCLYvez3NadVcqblRy4qJgbE7jqSci03gk+MShAx1zWEdqOUw6PRGIYsooHR/Cr60d/jfnCn5sAcAgiPZGYxGwXiienYHpUzet7IhhvFC7NmaOVbRS32F+Q0Gjw16w3USrjmtb8P0qJSTllnNlDKleEXDH3x01CRzdfpb0Uv9xeuaU3scAefQPH5koHk8KZVPLq+a954SBgU5dROiJ/KTKm7NaxW9RN5repfocoldI/0PwsF0ZRfTqgMiFY8XteSrszt6Kf26zyO5Tu5t3RKiPzjVb/EVYkWs9xx6A2AAAAAASUVORK5CYII=\">";
// case "windows" -> "<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAACzUlEQVQ4T7WUy2tTURDGf+c+kpg0bdL0nWdLdWEkigp1qS5qFUu1KWqxFFz5D6gLQepjISiC4qJWsdUSH8WlT3Qt4kbQjeDGvRtdWNPc15GTm2JaSxWpAxeGc2e+eXwzI/gloqZqwKKunlxA1tktV0PEch3Ek2k+f3yvHBc/bxUnk3C2hUQ8RVO6m3iul1iml1iqm8a2FJGWDjQzxK2hQn0mGpG2Vho7kjRnu0lk19PQmeXTqzn6T08S7cwQaAhjBEFoID3wHPAs8CTYPypMH9gsSG3rY/eJ8zQkMkRauwg2NladdFMZweOTowxcuIema7iOh5TSRxAghJ+Q+udYFtNDmwWF4iiHp+5T/gqeiuqClC4CibNQ5uWFY+w5exczGK51sr4q1V6J0AVOpeID5geLDF+dwypLNE1XYatRVVkK8MW5cQYmZjGC6/zslhC2EuDQCMVrj7DmPYSmGPbl3wEHixy8+nBlwLJfcv+ZGYzQnzO8U9wq2DJylCPTJazvflb1GdoLipQxBi+XMIPVdv0uih8d7Apc35UXpDYVyA+P41Yksta/KnMauLbNp+cP2LB3FN00q6StJMrWcxzezl4RdBa2sv3wcWxbIuobroxsiw/PZijsO4ZmBhBSIuVSltU0SE3gug6vJ8/XSr5dojL/e8lOGR6fGmPwUgkjtHrJzgJc3533x2ZNScn/j7EZvjaH9WONBlut3qEb9yl/W1x4icRbtnqzmNU5rI78UqKXr16ubwc7T1wkkkgTaekkGA1jBEAzwJqHJ6dGGThXQhg6nuP661fbQP84CDRD7XLtOPwKZ5JItRFNpokme0j0bKCpI8vHpyX6J24Sbc8QCBvoAd9DnS/XVqPls2+VF5g5sOVvD+w6Yrl24l0ZmjI9NGd6iWd7iXV109CaJNzcitADTO3fWN+PevD6d2eVSw7xeBOhli6i6Rxf3r35CRf6Tre38smdAAAAAElFTkSuQmCC\">";
// default -> "";
// };
}

private void createNewDockerizedDriverInstance(DriverType driverType) {
String initialLog = "Attempting to run dockerized on: \"" + Properties.platform.targetPlatform() + " | " + JavaHelper.convertToSentenceCase(driverType.getValue()) + "\"";
if (SHAFT.Properties.web.headlessExecution()) {
Expand Down Expand Up @@ -373,7 +388,7 @@ private void createNewDockerizedDriverInstance(DriverType driverType) {
// driver =ThreadGuard.protect(remoteWebDriver));
driver = remoteWebDriver;
ReportManager.log("Successfully Opened " + JavaHelper.convertToSentenceCase(driverType.getValue()) + ".");
} catch (io.github.bonigarcia.wdm.config.WebDriverManagerException exception) {
} catch (WebDriverManagerException exception) {
failAction("Failed to create new Dockerized Browser Session, are you sure Docker is available on your machine?", exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import java.util.stream.Stream;

import static com.shaft.listeners.internal.CucumberHelper.shaftSetup;
import static com.shaft.listeners.internal.CucumberHelper.shaftTeardown;
import static com.shaft.listeners.internal.CucumberHelper.shaftTearDown;
import static io.qameta.allure.util.ResultsUtils.*;

/**
Expand Down Expand Up @@ -143,7 +143,7 @@ private void handleFeatureStartedHandler(final TestSourceRead event) {
@SuppressWarnings("unused")
private void handleFeatureFinishedHandler(final TestRunFinished event) {
// custom code
shaftTeardown();
shaftTearDown();
// end of custom code
}

Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/shaft/listeners/JunitListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.shaft.listeners.internal.UpdateChecker;
import com.shaft.properties.internal.PropertiesHelper;
import com.shaft.tools.internal.security.GoogleTink;
import com.shaft.tools.io.internal.AllureManager;
import com.shaft.tools.io.internal.ExecutionSummaryReport;
import com.shaft.tools.io.internal.ProjectStructureManager;
import com.shaft.tools.io.internal.ReportManagerHelper;
Expand Down Expand Up @@ -39,7 +40,7 @@ public void testPlanExecutionStarted(TestPlan testPlan) {

@Override
public void testPlanExecutionFinished(TestPlan testPlan) {
engineTeardown();
engineTearDown();
}

@Override
Expand Down Expand Up @@ -87,28 +88,25 @@ private void engineSetup() {
UpdateChecker.check();
ImageProcessingActions.loadOpenCV();

ReportManagerHelper.initializeAllureReportingEnvironment();
AllureManager.initializeAllureReportingEnvironment();
ReportManagerHelper.cleanExecutionSummaryReportDirectory();

ReportManagerHelper.setDiscreteLogging(SHAFT.Properties.reporting.alwaysLogDiscreetly());
ReportManagerHelper.setDebugMode(SHAFT.Properties.reporting.debugMode());
}

private void engineTeardown() {
private void engineTearDown() {
ReportManagerHelper.setDiscreteLogging(true);
JiraHelper.reportExecutionStatusToJira();
GoogleTink.encrypt();
ReportManagerHelper.generateAllureReportArchive();
ReportManagerHelper.openAllureReportAfterExecution();
AllureManager.generateAllureReportArchive();
AllureManager.openAllureReportAfterExecution();
long executionEndTime = System.currentTimeMillis();
ExecutionSummaryReport.generateExecutionSummaryReport(passedTests.size(), failedTests.size(), skippedTests.size(), executionStartTime, executionEndTime);
ReportManagerHelper.logEngineClosure();
}

private void afterInvocation() {
// IssueReporter.updateTestStatusInCaseOfVerificationFailure(iTestResult);
// IssueReporter.updateIssuesLog(iTestResult);
// TestNGListenerHelper.updateConfigurationMethodLogs(iTestResult);
ReportManagerHelper.setDiscreteLogging(SHAFT.Properties.reporting.alwaysLogDiscreetly());
}

Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/shaft/listeners/TestNGListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import com.shaft.properties.internal.PropertiesHelper;
import com.shaft.tools.internal.security.GoogleTink;
import com.shaft.tools.io.ReportManager;
import com.shaft.tools.io.internal.ExecutionSummaryReport;
import com.shaft.tools.io.internal.IssueReporter;
import com.shaft.tools.io.internal.ProjectStructureManager;
import com.shaft.tools.io.internal.ReportManagerHelper;
import com.shaft.tools.io.internal.*;
import io.qameta.allure.Allure;
import lombok.Getter;
import org.testng.*;
Expand Down Expand Up @@ -79,7 +76,7 @@ public static void engineSetup(ProjectStructureManager.RunType runType) {
ReportManagerHelper.logEngineVersion();
Thread.ofVirtual().start(UpdateChecker::check);
Thread.ofVirtual().start(ImageProcessingActions::loadOpenCV);
Thread.ofVirtual().start(ReportManagerHelper::initializeAllureReportingEnvironment);
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 @@ -201,12 +198,12 @@ public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResu
@Override
public void onExecutionFinish() {
ReportManagerHelper.setDiscreteLogging(true);
Thread allureArchiveGeneration = Thread.ofVirtual().start(ReportManagerHelper::generateAllureReportArchive);
Thread allureArchiveGeneration = Thread.ofVirtual().start(AllureManager::generateAllureReportArchive);
long executionEndTime = System.currentTimeMillis();
Thread summaryReportGeneration = Thread.ofVirtual().start(() -> ExecutionSummaryReport.generateExecutionSummaryReport(passedTests.size(), failedTests.size(), skippedTests.size(), executionStartTime, executionEndTime));
Thread.ofVirtual().start(JiraHelper::reportExecutionStatusToJira);
Thread.ofVirtual().start(GoogleTink::encrypt);
Thread.ofVirtual().start(ReportManagerHelper::openAllureReportAfterExecution);
Thread.ofVirtual().start(AllureManager::openAllureReportAfterExecution);
Thread.ofVirtual().start(ReportManagerHelper::logEngineClosure);
try {
summaryReportGeneration.join();
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/com/shaft/listeners/internal/CucumberHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.shaft.gui.internal.image.ImageProcessingActions;
import com.shaft.properties.internal.PropertiesHelper;
import com.shaft.tools.internal.security.GoogleTink;
import com.shaft.tools.io.internal.CheckpointCounter;
import com.shaft.tools.io.internal.ProjectStructureManager;
import com.shaft.tools.io.internal.ReportHelper;
import com.shaft.tools.io.internal.ReportManagerHelper;
import com.shaft.tools.io.internal.*;
import org.testng.Reporter;
import org.testng.xml.XmlSuite;

Expand Down Expand Up @@ -48,7 +45,7 @@ public static void shaftSetup() {
UpdateChecker.check();
ImageProcessingActions.loadOpenCV();

ReportManagerHelper.initializeAllureReportingEnvironment();
AllureManager.initializeAllureReportingEnvironment();

ReportHelper.attachImportantLinks();
ReportHelper.attachPropertyFiles();
Expand All @@ -68,7 +65,7 @@ public static void shaftSetup() {
);
}

public static void shaftTeardown() {
public static void shaftTearDown() {
if (Reporter.getCurrentTestResult() == null) {
// running in native Cucumber mode
ReportHelper.attachEngineLog();
Expand All @@ -79,8 +76,8 @@ public static void shaftTeardown() {
ReportManagerHelper.setDiscreteLogging(true);
JiraHelper.reportExecutionStatusToJira();
GoogleTink.encrypt();
ReportManagerHelper.generateAllureReportArchive();
ReportManagerHelper.openAllureReportAfterExecution();
AllureManager.generateAllureReportArchive();
AllureManager.openAllureReportAfterExecution();
ReportManagerHelper.logEngineClosure();
}
}
Expand Down
Loading

0 comments on commit 88be461

Please sign in to comment.