Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix allure history and trends generation #1800

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/java/com/shaft/properties/internal/Allure.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
boolean automaticallyOpen(); //automaticallyOpen (used to be: openAllureReportAfterExecution)

@Key("allure.accumulateHistory")
@DefaultValue("false")
@DefaultValue("true")
boolean accumulateHistory(); //accumulateHistory (used to be: cleanAllureResultsDirectoryBeforeExecution)

@Key("allure.accumulateReports")
@DefaultValue("true")
boolean accumulateReports(); //allows html files to accumulate in the allure report directory

@Key("allure.cleanResultsDirectory")
@DefaultValue("true")
boolean cleanResultsDirectory();

@Key("allure.generateArchive")
@DefaultValue("false")
boolean generateArchive(); //generateArchive (used to be: generateAllureReportArchive)
Expand Down Expand Up @@ -62,6 +66,11 @@
return this;
}

public SetProperty cleanResultsDirectory(boolean value) {
setProperty("allure.cleanResultsDirectory", String.valueOf(value));
return this;

Check warning on line 71 in src/main/java/com/shaft/properties/internal/Allure.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/properties/internal/Allure.java#L70-L71

Added lines #L70 - L71 were not covered by tests
}

public SetProperty generateArchive(boolean value) {
setProperty("allure.generateArchive", String.valueOf(value));
return this;
Expand Down
58 changes: 46 additions & 12 deletions src/main/java/com/shaft/tools/io/internal/AllureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
private static void copyAndOpenAllure() {
internalFileSession.copyFolder(allureOutPutDirectory, allureReportPath);
internalFileSession.deleteFile(allureOutPutDirectory);
internalFileSession.deleteFile(System.getProperty("user.dir") + File.separator + "target" + File.separator + "allure-report-history");
String newFileName = renameAllureReport();
openAllureReport(newFileName);
}
Expand Down Expand Up @@ -137,8 +138,8 @@
}

private static void cleanAllureResultsDirectory() {
// clean allure-results directory before execution
if (!SHAFT.Properties.allure.accumulateHistory()) {
if (SHAFT.Properties.allure.cleanResultsDirectory()) {
// clean allure-results directory before execution
var allureResultsPath = allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1);
try {
internalFileSession.deleteFolder(allureResultsPath);
Expand Down Expand Up @@ -177,22 +178,55 @@
}

private static void writeAllureReport() {
String commandToCreateAllureReport;
allureBinaryPath = allureExtractionLocation + "allure-" + SHAFT.Properties.internal.allureVersion()
+ "/bin/allure";
allureOutPutDirectory = System.getProperty("user.dir") + File.separator + "target" + File.separator + allureReportPath;
var customReportName = SHAFT.Properties.allure.customTitle();
if (SystemUtils.IS_OS_WINDOWS) {
commandToCreateAllureReport = allureBinaryPath + ".bat" + " generate --single-file --clean '"
+ allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1)
+ "' -o '" + allureOutPutDirectory + "' --report-name '"+customReportName+"'";
internalFileSession.createFolder(allureOutPutDirectory);

String pathToLastHistoryDirectory = System.getProperty("user.dir") + File.separator + "target" + File.separator + "last-history";
if (SHAFT.Properties.allure.accumulateHistory()) {
// move existing history to the correct folder
if (internalFileSession.doesFileExist(pathToLastHistoryDirectory)) {//if not the first test run and history already exists
internalFileSession.copyFolder(pathToLastHistoryDirectory, allureResultsFolderPath + File.separator + "history");

Check warning on line 191 in src/main/java/com/shaft/tools/io/internal/AllureManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/tools/io/internal/AllureManager.java#L191

Added line #L191 was not covered by tests
} else {
internalFileSession.createFolder(pathToLastHistoryDirectory);
}

internalTerminalSession.performTerminalCommand(getCommandToCreateAllureReport(customReportName, true));
internalTerminalSession.performTerminalCommand(getCommandToCreateAllureReport(customReportName, false));
MohabMohie marked this conversation as resolved.
Show resolved Hide resolved
internalFileSession.copyFolder(System.getProperty("user.dir") + File.separator + "target" + File.separator + "allure-report-history" + File.separator + "history"
, pathToLastHistoryDirectory);
} else {
commandToCreateAllureReport = allureBinaryPath + " generate --single-file --clean "
+ allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1)
+ " -o " + allureOutPutDirectory + " --report-name "+customReportName;
internalFileSession.deleteFolder(pathToLastHistoryDirectory);
internalTerminalSession.performTerminalCommand(getCommandToCreateAllureReport(customReportName, false));

Check warning on line 202 in src/main/java/com/shaft/tools/io/internal/AllureManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/tools/io/internal/AllureManager.java#L201-L202

Added lines #L201 - L202 were not covered by tests
}
internalFileSession.createFolder(allureOutPutDirectory);
internalTerminalSession.performTerminalCommand(commandToCreateAllureReport);
}

private static String getCommandToCreateAllureReport(String customReportName, boolean isHistory) {
String commandToCreateAllureReport;
if (isHistory) {
if (SystemUtils.IS_OS_WINDOWS) {
commandToCreateAllureReport = allureBinaryPath + ".bat" + " generate '"
+ allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1)

Check warning on line 211 in src/main/java/com/shaft/tools/io/internal/AllureManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/tools/io/internal/AllureManager.java#L210-L211

Added lines #L210 - L211 were not covered by tests
+ "' -o '" + allureOutPutDirectory + "-history' --report-name '" + customReportName + "'";
} else {
commandToCreateAllureReport = allureBinaryPath + " generate "
+ allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1)
+ " -o " + allureOutPutDirectory + "-history --report-name " + customReportName;
}
} else {
if (SystemUtils.IS_OS_WINDOWS) {
commandToCreateAllureReport = allureBinaryPath + ".bat" + " generate --single-file --clean '"
+ allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1)

Check warning on line 221 in src/main/java/com/shaft/tools/io/internal/AllureManager.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/shaft/tools/io/internal/AllureManager.java#L220-L221

Added lines #L220 - L221 were not covered by tests
+ "' -o '" + allureOutPutDirectory + "' --report-name '" + customReportName + "'";
} else {
commandToCreateAllureReport = allureBinaryPath + " generate --single-file --clean "
+ allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1)
+ " -o " + allureOutPutDirectory + " --report-name " + customReportName;
}
}
return commandToCreateAllureReport;
}

private static void createAllureReportArchive() {
Expand Down
Loading