Skip to content

Commit

Permalink
property init fixes (#1620)
Browse files Browse the repository at this point in the history
* enhance property files structure

* fix openCV initialization

* reposition allure listener meta file creation

* disabled new feature, reload props with any prop call

* hardcode the testNG listener
  • Loading branch information
MohabMohie authored May 23, 2024
1 parent 64732d3 commit 2bd00b6
Show file tree
Hide file tree
Showing 26 changed files with 41 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/shaft/driver/DriverFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void readLastMinuteUpdatedProperties() {
}
}

public static void reloadProperties() {
public static boolean reloadProperties() {
if (SHAFT.Properties.platform == null) {
System.out.println("Execution Listeners are not loaded properly... Self-Healing... Initializing minimalistic test run...");
var runType = TestNGListener.identifyRunType();
Expand All @@ -53,6 +53,7 @@ public static void reloadProperties() {
}
TestNGListener.engineSetup(runType);
}
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ public static void compareImageFolders(String referenceFolderPath, String testFo

public static byte[] highlightElementInScreenshot(byte[] targetScreenshot,
org.openqa.selenium.Rectangle elementLocation, Color highlightColor) {

// loadOpenCV();
Mat img = Imgcodecs.imdecode(new MatOfByte(targetScreenshot), Imgcodecs.IMREAD_COLOR);
Mat img;
try {
img = Imgcodecs.imdecode(new MatOfByte(targetScreenshot), Imgcodecs.IMREAD_COLOR);
} catch (java.lang.UnsatisfiedLinkError unsatisfiedLinkError){
loadOpenCV();
img = Imgcodecs.imdecode(new MatOfByte(targetScreenshot), Imgcodecs.IMREAD_COLOR);
}

int outlineThickness = 5;
double elementHeight = elementLocation.getHeight(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"file:src/main/resources/properties/default/browserStack.properties",
"classpath:browserStack.properties",
})
public interface BrowserStack extends EngineProperties {
public interface BrowserStack extends EngineProperties<BrowserStack> {
//Based on BrowserStack capability builder
// For Mobile Native https://www.browserstack.com/app-automate/capabilities?tag=w3c
// For Web https://www.browserstack.com/automate/capabilities?tag=selenium-4
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Cucumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@SuppressWarnings("unused")
@Config.Sources({"system:properties", "file:src/main/resources/properties/cucumber.properties", "file:src/main/resources/properties/default/cucumber.properties", "classpath:cucumber.properties"})
public interface Cucumber extends EngineProperties {
public interface Cucumber extends EngineProperties<Cucumber> {

@Key("cucumber.ansi-colors.disabled")
@DefaultValue("false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// https://matteobaccan.github.io/owner/
@HotReload(type = HotReloadType.ASYNC)
@LoadPolicy(Config.LoadType.MERGE)
public interface EngineProperties extends Config {
public interface EngineProperties<T> extends Config {
SetProperty set();

interface SetProperty {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/PlatformFlags.properties", "file:src/main/resources/properties/default/PlatformFlags.properties", "classpath:PlatformFlags.properties",})
public interface Flags extends EngineProperties {
public interface Flags extends EngineProperties<Flags> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Healenium.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/healenium.properties", "file:src/main/resources/properties/default/healenium.properties", "classpath:healenium.properties",})
public interface Healenium extends EngineProperties {
public interface Healenium extends EngineProperties<Healenium> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Internal.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"file:src/main/resources/properties/default/internal.properties",
"classpath:internal.properties",
})
public interface Internal extends EngineProperties {
public interface Internal extends EngineProperties<Internal> {
@Key("shaftEngineVersion")
@DefaultValue("8.2.20240411")
String shaftEngineVersion();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Jira.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/JiraXRay.properties", "file:src/main/resources/properties/default/JiraXRay.properties", "classpath:JiraXRay.properties"})
public interface Jira extends EngineProperties {
public interface Jira extends EngineProperties<Jira> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings({"unused"})
@Config.Sources({"system:properties", "file:src/main/resources/properties/LambdaTest.properties", "file:src/main/resources/properties/default/LambdaTest.properties", "classpath:LambdaTest.properties",})
public interface LambdaTest extends EngineProperties {
public interface LambdaTest extends EngineProperties<LambdaTest> {
//Based on LambdaTest capability builder
// For Web and Mobile Native https://www.lambdatest.com/capabilities-generator/

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Log4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/log4j2.properties", "file:src/main/resources/properties/default/log4j2.properties", "classpath:log4j2.properties"})
public interface Log4j extends EngineProperties {
public interface Log4j extends EngineProperties<Log4j> {

@Key("name")
@DefaultValue("PropertiesConfig")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Mobile.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"file:src/main/resources/properties/default/MobileCapabilities.properties",
"classpath:MobileCapabilities.properties",
})
public interface Mobile extends EngineProperties {
public interface Mobile extends EngineProperties<Mobile> {

private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Paths.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"file:src/main/resources/properties/default/path.properties",
"classpath:path.properties",
})
public interface Paths extends EngineProperties {
public interface Paths extends EngineProperties<Paths> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Pattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/pattern.properties", "file:src/main/resources/properties/default/pattern.properties", "classpath:pattern.properties",})
public interface Pattern extends EngineProperties {
public interface Pattern extends EngineProperties<Pattern> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"file:src/main/resources/properties/default/performance.properties",
"classpath:performance.properties",
})
public interface Performance extends EngineProperties {
public interface Performance extends EngineProperties<Performance> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"file:src/main/resources/properties/default/ExecutionPlatform.properties",
"classpath:ExecutionPlatform.properties",
})
public interface Platform extends EngineProperties {
public interface Platform extends EngineProperties<Platform> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/shaft/properties/internal/Properties.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.shaft.properties.internal;

import com.shaft.driver.DriverFactory;

public class Properties {
// private static final boolean reloadProperties = DriverFactory.reloadProperties();
public static BrowserStack browserStack;
public static Cucumber cucumber;
public static Platform platform;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Reporting.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/Reporting.properties", "file:src/main/resources/properties/default/Reporting.properties", "classpath:Reporting.properties"})
public interface Reporting extends EngineProperties {
public interface Reporting extends EngineProperties<Reporting> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/TestNG.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/TestNG.properties", "file:src/main/resources/properties/default/TestNG.properties", "classpath:TestNG.properties",})
public interface TestNG extends EngineProperties {
public interface TestNG extends EngineProperties<TestNG> {

@Key("setParallel")
@DefaultValue("NONE")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Timeouts.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/Timeouts.properties", "file:src/main/resources/properties/default/Timeouts.properties", "classpath:Timeouts.properties"})
public interface Timeouts extends EngineProperties {
public interface Timeouts extends EngineProperties<Timeouts> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Tinkey.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/tinkey.properties", "file:src/main/resources/properties/default/tinkey.properties", "classpath:tinkey.properties"})
public interface Tinkey extends EngineProperties {
public interface Tinkey extends EngineProperties<Tinkey> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Visuals.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/VisualValidations.properties", "file:src/main/resources/properties/default/VisualValidations.properties", "classpath:VisualValidations.properties"})
public interface Visuals extends EngineProperties {
public interface Visuals extends EngineProperties<Visuals> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/properties/internal/Web.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@SuppressWarnings("unused")
@Sources({"system:properties", "file:src/main/resources/properties/WebCapabilities.properties", "file:src/main/resources/properties/default/WebCapabilities.properties", "classpath:WebCapabilities.properties"})
public interface Web extends EngineProperties {
public interface Web extends EngineProperties<Web> {
private static void setProperty(String key, String value) {
var updatedProps = new java.util.Properties();
updatedProps.setProperty(key, value);
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/com/shaft/tools/io/internal/AllureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static void initializeAllureReportingEnvironment() {
overrideAllurePluginConfiguration();
writeGenerateReportShellFilesToProjectDirectory();
writeEnvironmentVariablesToAllureResultsDirectory();
createAllureListenersMetaFiles();
}

public static void openAllureReportAfterExecution() {
Expand Down Expand Up @@ -154,12 +153,6 @@ private static void overrideAllurePluginConfiguration() {

}

private static void createAllureListenersMetaFiles() {
FileActions.getInstance(true).createFolder(com.shaft.properties.internal.Properties.paths.services());
Arrays.asList("io.qameta.allure.listener.ContainerLifecycleListener", "io.qameta.allure.listener.FixtureLifecycleListener",
"io.qameta.allure.listener.StepLifecycleListener", "io.qameta.allure.listener.TestLifecycleListener").forEach(fileName -> FileActions.getInstance(true).writeToFile(Properties.paths.services(), fileName, "com.shaft.listeners.AllureListener"));
}

private static void writeAllureReport() {
String commandToCreateAllureReport;
allureBinaryPath = allureExtractionLocation + "allure-" + SHAFT.Properties.internal.allureVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.shaft.tools.io.ReportManager;

import java.nio.file.Paths;
import java.util.Arrays;

public class ProjectStructureManager {
public static void initialize(RunType runType) {
Expand Down Expand Up @@ -32,8 +33,15 @@ public static void initialize(RunType runType) {
FileActions.getInstance(true).writeToFile(Properties.paths.services(), "io.cucumber.plugin.ConcurrentEventListener", "com.shaft.listeners.CucumberFeatureListener");
}
}
createAllureListenersMetaFiles();
}
}

private static void createAllureListenersMetaFiles() {
FileActions.getInstance(true).createFolder(com.shaft.properties.internal.Properties.paths.services());
Arrays.asList("io.qameta.allure.listener.ContainerLifecycleListener", "io.qameta.allure.listener.FixtureLifecycleListener",
"io.qameta.allure.listener.StepLifecycleListener", "io.qameta.allure.listener.TestLifecycleListener").forEach(fileName -> FileActions.getInstance(true).writeToFile(Properties.paths.services(), fileName, "com.shaft.listeners.AllureListener"));
}

public enum RunType {TESTNG, JUNIT, CUCUMBER}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.shaft.listeners.TestNGListener

0 comments on commit 2bd00b6

Please sign in to comment.