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

Cleanup atd #888

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
121 changes: 71 additions & 50 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import java.text.SimpleDateFormat
import org.codehaus.groovy.runtime.GStringImpl

import java.text.SimpleDateFormat

buildscript {
ext {
gradleVersion = "8.12"
Expand Down Expand Up @@ -31,20 +32,17 @@ plugins {
id "org.sonarqube" version "6.0.1.5171"
id "java"
id "idea"
id "com.github.johnrengelman.shadow" version '8.1.1'
id "com.gradleup.shadow" version '8.3.5'
id "maven-publish"
id "io.freefair.aspectj.post-compile-weaving" version "8.11"
}

group = 'com.github.znsio'
version '1.0.12'
version = '1.0.13-noATD'

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

repositories {
Expand All @@ -54,7 +52,7 @@ repositories {
}
mavenCentral()
maven {
url 'https://jitpack.io'
url = 'https://jitpack.io'
}
}

Expand Down Expand Up @@ -139,31 +137,13 @@ task downloadDependencies {
doLast {
println "Downloading required dependencies..."
def dependencies = [
// [
// name : "teswiz",
// type : "github",
// params: [
// repoUrl: "https://api.github.com/repos/znsio/teswiz/releases/latest",
// version: "$project.teswizVersion"
// ]
// ],
[
name : "AppiumTestDistribution",
type : "jitpack",
params: [
group : "com.github.AppiumTestDistribution",
artifact: "AppiumTestDistribution",
version : "$project.atdVersion",
fileNameSuffix: "-jar-with-dependencies"
]
],
[
name : "jadb",
type : "jitpack",
params: [
group : "com.github.vidstige",
artifact: "jadb",
version : "$project.jadbVersion",
group : "com.github.vidstige",
artifact : "jadb",
version : "$project.jadbVersion",
fileNameSuffix: ""
]
]
Expand All @@ -187,40 +167,73 @@ tasks.compileJava {
}

dependencies {
// Local JAR dependencies
implementation fileTree(dir: "$project.projectDir/libs", include: ['*.jar'])
implementation files(layout.buildDirectory.files("/classes/main"))
implementation files(layout.buildDirectory.files("/classes/test"))
implementation ("com.github.AppiumTestDistribution:AppiumTestDistribution:$project.atdVersion") {
exclude group: 'io.appium', module: 'java-client'
}
implementation "com.github.vidstige:jadb:$project.jadbVersion"

// Build-specific directories
implementation files(layout.buildDirectory.dir("classes/main"))
implementation files(layout.buildDirectory.dir("classes/test"))

// Logging
implementation "org.apache.logging.log4j:log4j-api:2.24.3"
implementation "org.apache.logging.log4j:log4j-core:2.24.3"
// implementation "org.apache.logging.log4j:log4j-1.2-api:2.24.3"

// JSON and YAML processing
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$project.fasterxmlJacksonVersion"
implementation "com.konghq:unirest-java:$project.unirestVersion"
// implementation "org.yaml:snakeyaml:$project.snakeyamlVersion"
implementation "com.flipkart.zjsonpatch:zjsonpatch:$project.jsonDiffVersion"

// Assertions and testing
implementation "org.assertj:assertj-core:$project.assertJVersion"
implementation "org.apache.commons:commons-lang3:$project.commonsLang3Version"
implementation "org.apache.commons:commons-rng-simple:$project.commonsRngSimpleVersion"
implementation "org.jetbrains:annotations:$project.jetbrainsAnnotationsVersion"
implementation "org.junit.jupiter:junit-jupiter:$project.junitVersion"
implementation "joda-time:joda-time:$project.jodaTimeVersion"
// implementation "org.junit.jupiter:junit-jupiter:$project.junitVersion"
// implementation "org.testng:testng:7.10.2"
implementation "io.cucumber:cucumber-java:7.20.1"
implementation "io.cucumber:cucumber-testng:7.20.1"

// Unirest for API testing
implementation "com.konghq:unirest-java:$project.unirestVersion"

// Appium and BrowserStack
// implementation "io.appium:java-client:9.3.0"
implementation "com.browserstack:browserstack-local-java:$project.browserStackLocalVersion"

// Applitools for visual testing
implementation "com.applitools:eyes-images-java5:$project.applitoolsImagesVersion"
implementation("com.applitools:eyes-appium-java5:$project.applitoolsAppiumVersion") {
// exclude group: 'io.appium', module: 'java-client'
}
implementation "net.masterthought:cucumber-reporting:$masterThoughtVersion"
implementation "com.applitools:eyes-appium-java5:$project.applitoolsAppiumVersion"

// Aspect-Oriented Programming (AOP)
implementation "org.aspectj:aspectjrt:$project.aspectJVersion"

// Specmatic and JSON Schema validation
implementation "in.specmatic:specmatic-core:${project.specmaticVersion}"
implementation "org.everit.json:org.everit.json.schema:1.5.1"
implementation 'com.jayway.jsonpath:json-path:2.9.0'

// Utility libraries
implementation "org.apache.commons:commons-lang3:$project.commonsLang3Version"
implementation "org.apache.commons:commons-rng-simple:$project.commonsRngSimpleVersion"
implementation "org.jetbrains:annotations:$project.jetbrainsAnnotationsVersion"
implementation "joda-time:joda-time:$project.jodaTimeVersion"
implementation "io.github.bonigarcia:webdrivermanager:$project.webDriverManagerVersion"
implementation "org.yaml:snakeyaml:$project.snakeyamlVersion"
implementation "com.flipkart.zjsonpatch:zjsonpatch:$project.jsonDiffVersion"

// Reporting
implementation "net.masterthought:cucumber-reporting:$masterThoughtVersion"
implementation 'com.epam.reportportal:agent-java-cucumber6:5.3.4'

// PDF handling
implementation "org.apache.pdfbox:pdfbox:$project.pdfBoxVersion"

// Lombok
implementation 'org.projectlombok:lombok:1.18.36'
}


shadowJar {
archiveBaseName.set("$project.name")
archiveClassifier.set('')
archiveVersion.set("$project.version")
zip64 true
zip64 = true
manifest {
attributes "Multi-Release": true
attributes "Main-Class": "com.znsio.e2e.runner.Runner"
Expand Down Expand Up @@ -360,8 +373,17 @@ tasks.register('run', JavaExec) {
}

test {
useJUnitPlatform()
doFirst {
println "Using LOG_DIR for tests: ${project.logDir}"
def logDir = new File("${project.logDir}")
systemProperty "LOG_DIR", "${project.logDir}"

if (!logDir.exists()) {
logDir.mkdirs()
println "Created log directory at: ${logDir.absolutePath}"
}
}
useTestNG()
outputs.upToDateWhen { false }

testLogging {
Expand All @@ -379,7 +401,6 @@ test {
if (System.getProperty('debug', 'false') == 'true') {
jvmArgs '-Xdebug', '-agentlib:jdwp=transport=dt_socket,server=n,address=192.168.29.248:9009,suspend=y'
}
println "Using LOG_DIR: ${project.logDir}"
reports {
html.required.set(true)
junitXml.required.set(true)
Expand All @@ -389,7 +410,7 @@ test {
}

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ['--release', '17']
options.compilerArgs += ['--release', '17', '-Xlint:deprecation']
}

tasks.withType(JavaExec).configureEach {
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/com/znsio/teswiz/context/SessionContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.znsio.teswiz.context;

import com.znsio.teswiz.listener.CucumberScenarioListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.ITestContext;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Optional;
import java.util.Properties;

import static com.znsio.teswiz.tools.OverriddenVariable.getOverriddenStringValue;


public class SessionContext {
static final String TEST_RUNNER = "testrunner";
private static final HashMap<String, TestExecutionContext> allTestsExecutionContext;
private static final Logger LOGGER = LogManager.getLogger(SessionContext.class.getName());
private static final Properties reportPortalProperties;
private static String reportPortalLaunchURL = "";

static {
LOGGER.info("SessionContext default constructor");
new SessionContext();
allTestsExecutionContext = new HashMap<>();
reportPortalProperties = loadReportPortalProperties();
LOGGER.info("Initialized SessionContext");
}

static synchronized void addContext(long threadId, TestExecutionContext testExecutionContext) {
allTestsExecutionContext.put(String.valueOf(threadId), testExecutionContext);
LOGGER.info(String.format("Adding context for thread - %s", threadId));
}

public static synchronized TestExecutionContext getTestExecutionContext(long threadId) {
return allTestsExecutionContext.get(String.valueOf(threadId));
}

public static synchronized void remove(long threadId) {
LOGGER.info(String.format("Removing context for thread - %s", threadId));
allTestsExecutionContext.remove(String.valueOf(threadId));
}

private static Properties loadReportPortalProperties() {
Properties properties = new Properties();
try {
String reportPortalPropertiesFile = "src/test/resources/reportportal.properties";
getOverriddenStringValue("REPORT_PORTAL_FILE", reportPortalPropertiesFile);
LOGGER.info("Using reportportal.properties file from "
+ reportPortalPropertiesFile);
File reportPortalFile = new File(reportPortalPropertiesFile);
String absolutePath = reportPortalFile.getAbsolutePath();
if (reportPortalFile.exists()) {
properties.load(new FileInputStream(absolutePath));
LOGGER.info("Loaded reportportal.properties file - " + absolutePath);
} else {
LOGGER.info("reportportal.properties file NOT FOUND - " + absolutePath);
}

} catch (IOException e) {
LOGGER.info("ERROR in loading reportportal.properties file\n" + e.getMessage());
throw new RuntimeException(e.getMessage());
}
return properties;
}

public static void setReportPortalLaunchURL(ITestContext iTestContext) {
Optional reportPortalListener = Arrays.stream(iTestContext.getSuite().getXmlSuite()
.getListeners().toArray()).filter(x ->
x.equals("com.epam.reportportal.testng.ReportPortalTestNGListener"))
.findFirst();
if (reportPortalListener.isPresent()) {
setReportPortalLaunchURL();
}
}

public static String getReportPortalLaunchURL() {
return reportPortalLaunchURL;
}

public static void setReportPortalLaunchURL() {
boolean isReportPortalEnabledInProperties =
(null == reportPortalProperties.getProperty("rp.enable")
|| (reportPortalProperties.getProperty("rp.enable")
.equalsIgnoreCase("true")));
if (isReportPortalEnabledInProperties) {
String rpLaunchId = System.getProperty("rp.launch.id");
LOGGER.debug(String.format("System property: rp.launch.id: '%s'",
rpLaunchId));
reportPortalLaunchURL = String.format("%s/ui/#%s/launches/all/%s",
reportPortalProperties.getProperty("rp.endpoint"),
reportPortalProperties.getProperty("rp.project"),
rpLaunchId);
LOGGER.info(String.format(
"**** ReportPortal URL - %s ****",
reportPortalLaunchURL));
}
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/znsio/teswiz/context/TestExecutionContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.znsio.teswiz.context;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;

public class TestExecutionContext {
private final String testName;
private final HashMap<String, Object> testExecutionState;
private final String NOT_SET = "NOT-YET-SET";
private static final Logger LOGGER = LogManager.getLogger(TestExecutionContext.class.getName());

public TestExecutionContext(String testName) {
SessionContext.addContext(Thread.currentThread().getId(), this);
this.testName = testName;
this.testExecutionState = new HashMap<>();
LOGGER.info(String.format("%s - TestExecution context created", testName));
}

public String getTestName() {
return testName;
}

public void addTestState(String key, Object details) {
testExecutionState.put(key, details);
}

public Object getTestState(String key) {
return testExecutionState.get(key);
}

public String getTestStateAsString(String key) {
return (String) testExecutionState.get(key);
}

public HashMap<String, Object> getAllTestState() {
return testExecutionState;
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/znsio/teswiz/entities/FileLocations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.znsio.teswiz.entities;

import java.io.File;

import static com.znsio.teswiz.tools.OverriddenVariable.getOverriddenStringValue;

public interface FileLocations {
String OUTPUT_DIRECTORY =
getOverriddenStringValue("OUTPUT_DIRECTORY") != null
? File.separator + getOverriddenStringValue("OUTPUT_DIRECTORY")
+ File.separator
: File.separator + "target" + File.separator;

String PARALLEL_XML_LOCATION = OUTPUT_DIRECTORY + "parallel.xml";

String SERVER_CONFIG = OUTPUT_DIRECTORY + "server.json";
String REPORTS_DIRECTORY = OUTPUT_DIRECTORY + "reports" + File.separator;

String SCREENSHOTS_DIRECTORY = OUTPUT_DIRECTORY + "screenshot" + File.separator;
String ANDROID_SCREENSHOTS_DIRECTORY = SCREENSHOTS_DIRECTORY + "android" + File.separator;
String IOS_SCREENSHOTS_DIRECTORY = SCREENSHOTS_DIRECTORY + "iOS" + File.separator;

String APPIUM_LOGS_DIRECTORY = OUTPUT_DIRECTORY + "appiumlogs" + File.separator;
String ADB_LOGS_DIRECTORY = OUTPUT_DIRECTORY + "adblogs" + File.separator;
String DEVICE_LOGS_DIRECTORY = "deviceLogs" + File.separator;
String TEST_LOGS_DIRECTORY = "testLogs" + File.separator;
String DERIVED_DATA = OUTPUT_DIRECTORY + "derivedData" + File.separator;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.znsio.teswiz.listener;

import com.appium.filelocations.FileLocations;
import com.context.SessionContext;
import com.context.TestExecutionContext;
import com.znsio.teswiz.context.SessionContext;
import com.znsio.teswiz.context.TestExecutionContext;
import com.znsio.teswiz.entities.FileLocations;
import com.znsio.teswiz.entities.Platform;
import com.znsio.teswiz.entities.TEST_CONTEXT;
import com.znsio.teswiz.runner.Runner;
Expand Down
Loading
Loading