Skip to content

Commit

Permalink
Report folder name date time addition
Browse files Browse the repository at this point in the history
  • Loading branch information
grass-hopper-moc committed Aug 11, 2020
1 parent 15795f3 commit aa44c85
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.2.0 (2020-08-11)

* Add date and time to report folders [Issue 8](https://github.com/grasshopper7/extentreports-cucumber6-adapter/issues/8)
* Fix report folder name issue [Issue 9](https://github.com/grasshopper7/extentreports-cucumber5-adapter/issues/9)

## 1.1.0 (2020-07-21)

* Support for Json formatter [Issue 3](https://github.com/grasshopper7/extentreports-cucumber6-adapter/issues/3)
Expand Down
2 changes: 1 addition & 1 deletion extentreports-cucumber6-adapter/pom-nexus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>tech.grasshopper</groupId>
<artifactId>extentreports-cucumber6-adapter</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<name>extentreports-cucumber6-adapter</name>
<url>https://grasshopper.tech/2098/</url>
<description>Cucumber-JVM 6 adapter for Extent Framework</description>
Expand Down
2 changes: 1 addition & 1 deletion extentreports-cucumber6-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>tech.grasshopper</groupId>
<artifactId>extentreports-cucumber6-adapter</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<name>extentreports-cucumber6-adapter</name>
<url>https://grasshopper.tech/2098/</url>
<description>Cucumber-JVM 6 adapter for Extent Framework</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
*/
public class ExtentCucumberAdapter implements ConcurrentEventListener, StrictAware {

private static final String SCREENSHOT_DIR_PROPERTY = "screenshot.dir";
private static final String SCREENSHOT_REL_PATH_PROPERTY = "screenshot.rel.path";

private static Map<String, ExtentTest> featureMap = new ConcurrentHashMap<>();
private static ThreadLocal<ExtentTest> featureTestThreadLocal = new InheritableThreadLocal<>();
private static Map<String, ExtentTest> scenarioOutlineMap = new ConcurrentHashMap<>();
Expand All @@ -70,8 +67,6 @@ public class ExtentCucumberAdapter implements ConcurrentEventListener, StrictAwa
private static ThreadLocal<Boolean> isHookThreadLocal = new InheritableThreadLocal<>();
private static ThreadLocal<ExtentTest> stepTestThreadLocal = new InheritableThreadLocal<>();

private String screenshotDir;
private String screenshotRelPath;
private boolean strict = false;

@SuppressWarnings("serial")
Expand Down Expand Up @@ -139,11 +134,6 @@ public void receive(TestRunFinished event) {

public ExtentCucumberAdapter(String arg) {
ExtentService.getInstance();
Object prop = ExtentService.getProperty(SCREENSHOT_DIR_PROPERTY);
screenshotDir = prop == null ? "test-output/" : String.valueOf(prop);
prop = ExtentService.getProperty(SCREENSHOT_REL_PATH_PROPERTY);
screenshotRelPath = prop == null || String.valueOf(prop).isEmpty() ? screenshotDir : String.valueOf(prop);
screenshotRelPath = screenshotRelPath == null ? "" : screenshotRelPath;
}

@Override
Expand Down Expand Up @@ -256,9 +246,9 @@ private synchronized void handleEmbed(EmbedEvent event) {
stepTestThreadLocal.set(t);
}
stepTestThreadLocal.get().info("",
MediaEntityBuilder.createScreenCaptureFromPath(screenshotRelPath + f.getName()).build());
MediaEntityBuilder.createScreenCaptureFromPath(ExtentService.getScreenshotReportRelatvePath() + f.getName()).build());
// Screen shot for html report.
stepTestThreadLocal.get().addScreenCaptureFromPath(screenshotRelPath + f.getName());
stepTestThreadLocal.get().addScreenCaptureFromPath(ExtentService.getScreenshotReportRelatvePath() + f.getName());
} catch (URISyntaxException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -287,7 +277,7 @@ private static OutputStream createReportFileOutputStream(URL url) {

private URL toUrl(String fileName) {
try {
URL url = Paths.get(screenshotDir, fileName).toUri().toURL();
URL url = Paths.get(ExtentService.getScreenshotFolderName(), fileName).toUri().toURL();
return url;
} catch (IOException e) {
throw new CucumberException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Optional;
import java.util.Properties;
Expand Down Expand Up @@ -35,6 +37,14 @@ public static Object getProperty(String key) {
String sys = System.getProperty(key);
return sys == null ? (properties == null ? null : properties.get(key)) : sys;
}

public static String getScreenshotFolderName() {
return ExtentReportsLoader.SCREENSHOT_FOLDER_NAME;
}

public static String getScreenshotReportRelatvePath() {
return ExtentReportsLoader.SCREENSHOT_FOLDER_REPORT_RELATIVE_PATH;
}

@SuppressWarnings("unused")
private ExtentReports readResolve() {
Expand Down Expand Up @@ -99,10 +109,22 @@ private static class ExtentReportsLoader {
private static final String OUT_TABULAR_KEY = EXTENT_REPORTER + DELIM + TABULAR + DELIM + OUT;
private static final String OUT_JSONF_KEY = EXTENT_REPORTER + DELIM + JSONF + DELIM + OUT;

private static String SCREENSHOT_FOLDER_NAME;
private static String SCREENSHOT_FOLDER_REPORT_RELATIVE_PATH;
private static final String DEFAULT_SCREENSHOT_FOLDER_NAME = "test-output/";

private static final String SCREENSHOT_DIR_PROPERTY = "screenshot.dir";
private static final String SCREENSHOT_REL_PATH_PROPERTY = "screenshot.rel.path";

public static final String REPORTS_BASEFOLDER_NAME = "basefolder.name";
public static final String REPORTS_BASEFOLDER_DATETIMEPATTERN = "basefolder.datetimepattern";
private static final LocalDateTime FOLDER_CURRENT_TIMESTAMP = LocalDateTime.now();

static {
if (INSTANCE.getStartedReporters().isEmpty()) {
createViaProperties();
createViaSystem();
configureScreenshotProperties();
}
}

Expand Down Expand Up @@ -189,22 +211,51 @@ private static void createViaSystem() {
addSystemInfo(System.getProperties());
}

private static String getBaseFolderName() {
String folderpattern = "";
Object baseFolderPrefix = getProperty(REPORTS_BASEFOLDER_NAME);
Object baseFolderPatternSuffix = getProperty(REPORTS_BASEFOLDER_DATETIMEPATTERN);

if (baseFolderPrefix != null && !String.valueOf(baseFolderPrefix).isEmpty()
&& baseFolderPatternSuffix != null && !String.valueOf(baseFolderPatternSuffix).isEmpty()) {
DateTimeFormatter folderSuffix = DateTimeFormatter.ofPattern(String.valueOf(baseFolderPatternSuffix));
folderpattern = baseFolderPrefix + " " + folderSuffix.format(FOLDER_CURRENT_TIMESTAMP) + "/";
}
return folderpattern;
}

private static String getOutputPath(Properties properties, String key) {
String out;
if (properties != null && properties.get(key) != null)
out = String.valueOf(properties.get(key));
else
out = System.getProperty(key);
out = out == null || out.equals("null") || out.isEmpty() ? OUTPUT_PATH + key.split("\\.")[2] + "/" : out;
return getBaseFolderName() + out;
}

private static void configureScreenshotProperties() {
Object property = getProperty(SCREENSHOT_DIR_PROPERTY);
SCREENSHOT_FOLDER_NAME = property == null || String.valueOf(property).isEmpty()
? DEFAULT_SCREENSHOT_FOLDER_NAME
: String.valueOf(property);
SCREENSHOT_FOLDER_NAME = getBaseFolderName() + SCREENSHOT_FOLDER_NAME;

property = getProperty(SCREENSHOT_REL_PATH_PROPERTY);
SCREENSHOT_FOLDER_REPORT_RELATIVE_PATH = property == null || String.valueOf(property).isEmpty()
? SCREENSHOT_FOLDER_NAME
: String.valueOf(property);

// TODO: What does this line of code do?
//SCREENSHOT_FOLDER_REPORT_RELATIVE_PATH = SCREENSHOT_FOLDER_REPORT_RELATIVE_PATH == null ? "": SCREENSHOT_FOLDER_REPORT_RELATIVE_PATH;
}

private static void initAvent(Properties properties) {
String out = getOutputPath(properties, OUT_AVENT_KEY);
ExtentAventReporter avent = new ExtentAventReporter(out);
attach(avent, properties, CONFIG_AVENT_KEY);
}

private static String getOutputPath(Properties properties, String key) {
String out;
if (properties != null && properties.get(key) != null)
out = String.valueOf(properties.get(key));
else
out = System.getProperty(key);
out = out == null || out.equals("null") || out.isEmpty() ? OUTPUT_PATH + key.split("\\.")[2] + "/" : out;
return out;
}

private static void initBdd(Properties properties) {
String out = getOutputPath(properties, OUT_BDD_KEY);
ExtentBDDReporter bdd = new ExtentBDDReporter(out);
Expand Down

0 comments on commit aa44c85

Please sign in to comment.