Skip to content

Commit

Permalink
optimize actions to launch immediately (#1458)
Browse files Browse the repository at this point in the history
* optimize actions to launch immediately

* remove extent report support

+ optimize logger file initialization
+ change allure back to the default reporter

* reformatting code

* screenshot and lazy loading optimizations

- screenshot logic optimization
- screenshot and animated gif classes restructure
- fix scaling issue with fullPageScreenshot using google cdp
- virtual thread implementation for faster waitForLazyLoading
-

* wait for attacheable report generation
  • Loading branch information
MohabMohie committed Jan 22, 2024
1 parent 2831d0a commit 7c6ef2c
Show file tree
Hide file tree
Showing 67 changed files with 1,223 additions and 1,533 deletions.
66 changes: 27 additions & 39 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.16.1</version> <!-- MAKE SURE TO UPDATE DriverFactoryHelper import devtools.v120.network.Network TO LATEST VERSION WITH UPDATING SELENIUM-->
<version>4.16.1
</version> <!-- MAKE SURE TO UPDATE DriverFactoryHelper import devtools.v120.network.Network TO LATEST VERSION WITH UPDATING SELENIUM-->
</dependency>

<!-- APPIUM -->
<dependency>
<groupId>io.appium</groupId>
Expand Down Expand Up @@ -193,10 +194,10 @@

<!-- EXCEL FILE MANIPULATION -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.5</version>
<exclusions>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.5</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand All @@ -205,21 +206,21 @@
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.5</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down Expand Up @@ -271,19 +272,6 @@
<version>1.9.21</version>
</dependency>

<!-- EXTENT REPORTS -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.1.1</version>
<exclusions>
<exclusion>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- PDF Validation -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
Expand Down Expand Up @@ -811,7 +799,7 @@
<executions>
<execution>
<id>attach-sources</id>
<!-- <phase>verify</phase>-->
<!-- <phase>verify</phase>-->
<goals>
<goal>jar-no-fork</goal>
</goals>
Expand Down Expand Up @@ -907,9 +895,9 @@
<!-- <phase>compile</phase>-->
<!-- <goals>-->
<!-- <goal>initReport</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- <execution>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- <execution>-->
<!-- <id>hlmReportB</id>-->
<!-- <phase>test</phase>-->
<!-- <goals>-->
Expand Down Expand Up @@ -1008,9 +996,9 @@
<failIfNoTests>false</failIfNoTests>
<trimStackTrace>false</trimStackTrace>
<useFile>false</useFile>
<argLine>
@{argLine} ${surefireArgLine}
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.21/aspectjweaver-1.9.21.jar"
<argLine>
@{argLine} ${surefireArgLine}
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.21/aspectjweaver-1.9.21.jar"
</argLine>
<properties>
<property>
Expand Down Expand Up @@ -1053,7 +1041,7 @@
</dependency>
</dependencies>
<configuration>
<encoding>UTF-8</encoding>
<encoding>UTF-8</encoding>
<systemPropertyVariables>
<testng.dtd.http>true</testng.dtd.http>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
Expand All @@ -1062,9 +1050,9 @@
<failIfNoTests>false</failIfNoTests>
<trimStackTrace>false</trimStackTrace>
<useFile>false</useFile>
<argLine>
@{argLine} ${surefireArgLine}
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.21/aspectjweaver-1.9.21.jar"
<argLine>
@{argLine} ${surefireArgLine}
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.21/aspectjweaver-1.9.21.jar"
</argLine>
<properties>
<property>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/shaft/api/BrowserStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static MutableCapabilities setupMobileWebExecution() {
var pathItems = System.getProperty("user.dir").split(Pattern.quote(File.separator));
var time = LocalDateTime.now();
browserstackOptions.put("projectName", ReportManagerHelper.getTestClassName());
browserstackOptions.put("buildName", pathItems[pathItems.length-1] + "_" + time.getYear() + time.getMonthValue() + time.getDayOfMonth());
browserstackOptions.put("buildName", pathItems[pathItems.length - 1] + "_" + time.getYear() + time.getMonthValue() + time.getDayOfMonth());

browserStackCapabilities.setCapability("bstack:options", browserstackOptions);

Expand Down Expand Up @@ -158,7 +158,7 @@ public static MutableCapabilities setupDesktopWebExecution() {
var pathItems = System.getProperty("user.dir").split(Pattern.quote(File.separator));
var time = LocalDateTime.now();
browserstackOptions.put("projectName", ReportManagerHelper.getTestClassName());
browserstackOptions.put("buildName", pathItems[pathItems.length-1] + "_" + time.getYear() + time.getMonthValue() + time.getDayOfMonth());
browserstackOptions.put("buildName", pathItems[pathItems.length - 1] + "_" + time.getYear() + time.getMonthValue() + time.getDayOfMonth());

browserStackCapabilities.setCapability("bstack:options", browserstackOptions);

Expand All @@ -181,7 +181,7 @@ private static MutableCapabilities setBrowserStackProperties(String username, St
var pathItems = System.getProperty("user.dir").split(Pattern.quote(File.separator));
var time = LocalDateTime.now();
browserstackOptions.put("projectName", ReportManagerHelper.getTestClassName());
browserstackOptions.put("buildName", pathItems[pathItems.length-1] + "_" + time.getYear() + time.getMonthValue() + time.getDayOfMonth());
browserstackOptions.put("buildName", pathItems[pathItems.length - 1] + "_" + time.getYear() + time.getMonthValue() + time.getDayOfMonth());

browserStackCapabilities.setCapability("bstack:options", browserstackOptions);
return browserStackCapabilities;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/shaft/api/LambdaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static MutableCapabilities setupNativeAppExecution(String username, Strin
lambdaTestCapabilities.setCapability("lt:options", lambdaTestOptions);
return lambdaTestCapabilities;
}

/**
* Use this method to set up all the needed capabilities to be able to test an already uploaded version of your native application.
* You can refer to the getting started guide for LambdaTest App Automate to get all the needed information here <a href="https://app-automate.LambdaTest.com/dashboard/v2/getting-started">LambdaTest: Getting Started</a>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/shaft/api/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public RequestBuilder useRelaxedHTTPSValidation() {
*/
@SuppressWarnings("UnusedReturnValue")
public RequestBuilder useRelaxedHTTPSValidation(String protocol) {
this.sessionConfig=config().and().sslConfig(SSLConfig.sslConfig().relaxedHTTPSValidation(protocol));
this.sessionConfig = config().and().sslConfig(SSLConfig.sslConfig().relaxedHTTPSValidation(protocol));
return this;
}

Expand Down Expand Up @@ -220,7 +220,6 @@ public RequestBuilder addHeader(String key, String value) {
return this;
}



/**
* Append a cookie to the current session to be used in the current and all the following requests. This feature is commonly used for authentication cookies.
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/com/shaft/api/RestActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class RestActions {
private static final String ERROR_INCORRECT_XML_PATH = "Incorrect xmlPath ";
private static final String ERROR_FAILED_TO_PARSE_JSON = "Failed to parse the JSON document";
private static final String GRAPHQL_END_POINT = "graphql";
@Getter
static Response lastResponse;
private static boolean AUTOMATICALLY_ASSERT_RESPONSE_STATUS_CODE = true;
private static int HTTP_SOCKET_TIMEOUT;
private static int HTTP_CONNECTION_TIMEOUT;
Expand All @@ -72,8 +74,6 @@ public class RestActions {
private final Map<String, Object> sessionCookies;
private final RestAssuredConfig sessionConfig;
private String headerAuthorization;
@Getter
static Response lastResponse;

public RestActions(String serviceURI) {
initializeSystemProperties();
Expand Down Expand Up @@ -173,7 +173,7 @@ public static String getResponseJSONValue(Response response, String jsonPath) {
try {
if (jsonPath.contains("?")) {
List<String> jsonValueAsList = JsonPath.read(response.asPrettyString(), jsonPath);
searchPool = String.valueOf(jsonValueAsList.get(0));
searchPool = String.valueOf(jsonValueAsList.getFirst());
} else {
var jsonValue = JsonPath.read(response.asPrettyString(), jsonPath);
searchPool = String.valueOf(jsonValue);
Expand Down Expand Up @@ -204,7 +204,7 @@ public static String getResponseJSONValue(Object response, String jsonPath) {
} else if (response instanceof Response responseObject) {
if (jsonPath.contains("?")) {
List<String> jsonValueAsList = JsonPath.read(responseObject.asPrettyString(), jsonPath);
searchPool = String.valueOf(jsonValueAsList.get(0));
searchPool = String.valueOf(jsonValueAsList.getFirst());
} else {
var jsonValue = JsonPath.read(responseObject.asPrettyString(), jsonPath);
searchPool = String.valueOf(jsonValue);
Expand Down Expand Up @@ -348,7 +348,7 @@ public static int getResponseStatusCode(Response response) {
}

public static long getResponseTime(Response response) {
long time = response.timeIn(TimeUnit.MILLISECONDS);
long time = response.timeIn(TimeUnit.MILLISECONDS);
passAction(String.valueOf(time));
return time;
}
Expand Down Expand Up @@ -438,8 +438,9 @@ public static boolean compareJSON(Response response, String referenceJsonFilePat
actualJsonArray);
case CONTAINS -> compareJSONContains(response, expectedJsonObject, expectedJsonArray,
actualJsonObject, jsonPathToTargetArray);
case EQUALS_IGNORING_ORDER -> compareJSONEqualsIgnoringOrder(expectedJsonObject, expectedJsonArray, actualJsonObject,
actualJsonArray);
case EQUALS_IGNORING_ORDER ->
compareJSONEqualsIgnoringOrder(expectedJsonObject, expectedJsonArray, actualJsonObject,
actualJsonArray);
};
} catch (IOException rootCauseException) {
failAction("Couldn't find the desired file. \"" + referenceJsonFilePath + "\".", rootCauseException);
Expand Down Expand Up @@ -766,8 +767,8 @@ private static boolean compareJSONEquals(org.json.simple.JSONObject expectedJson
}

private static boolean compareJSONEqualsIgnoringOrder(org.json.simple.JSONObject expectedJsonObject,
org.json.simple.JSONArray expectedJsonArray, org.json.simple.JSONObject actualJsonObject,
org.json.simple.JSONArray actualJsonArray) {
org.json.simple.JSONArray expectedJsonArray, org.json.simple.JSONObject actualJsonObject,
org.json.simple.JSONArray actualJsonArray) {
if (expectedJsonObject != null && actualJsonObject != null) {
// if expected is an object and actual is also an object
try {
Expand Down Expand Up @@ -1017,12 +1018,12 @@ private RequestSpecBuilder initializeBuilder(Map<String, Object> sessionCookies,
builder.addCookies(sessionCookies);
builder.addHeaders(sessionHeaders);
//Add configs
RestAssuredConfig userConfigs=sessionConfig.and().encoderConfig((new EncoderConfig()).defaultContentCharset("UTF-8")
.appendDefaultContentCharsetToContentTypeIfUndefined(appendDefaultContentCharsetToContentTypeIfUndefined)).and()
.httpClient(HttpClientConfig.httpClientConfig()
.setParam("http.connection.timeout", HTTP_CONNECTION_TIMEOUT * 1000)
.setParam("http.socket.timeout", HTTP_SOCKET_TIMEOUT * 1000)
.setParam("http.connection-manager.timeout", HTTP_CONNECTION_MANAGER_TIMEOUT * 1000));
RestAssuredConfig userConfigs = sessionConfig.and().encoderConfig((new EncoderConfig()).defaultContentCharset("UTF-8")
.appendDefaultContentCharsetToContentTypeIfUndefined(appendDefaultContentCharsetToContentTypeIfUndefined)).and()
.httpClient(HttpClientConfig.httpClientConfig()
.setParam("http.connection.timeout", HTTP_CONNECTION_TIMEOUT * 1000)
.setParam("http.socket.timeout", HTTP_SOCKET_TIMEOUT * 1000)
.setParam("http.connection-manager.timeout", HTTP_CONNECTION_MANAGER_TIMEOUT * 1000));
builder.setConfig(userConfigs);
// timeouts documentation
/*
Expand Down Expand Up @@ -1064,7 +1065,6 @@ public RestActions addCookieVariable(String key, String value) {
return this;
}



protected String prepareRequestURL(String serviceURI, String urlArguments, String serviceName) {
if (urlArguments != null && !urlArguments.isEmpty()) {
Expand All @@ -1084,7 +1084,7 @@ protected RequestSpecification prepareRequestSpecs(List<List<Object>> parameters

if (body != null && contentType != null && !body.toString().isEmpty()) {
prepareRequestBody(builder, body, contentType);
} else if (parameters != null && !parameters.isEmpty() && !parameters.get(0).get(0).equals("")) {
} else if (parameters != null && !parameters.isEmpty() && !parameters.getFirst().getFirst().equals("")) {
prepareRequestBody(builder, parameters, parametersType);
}
return builder.build();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shaft/cli/FileActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.zip.ZipOutputStream;

public class FileActions {
private boolean internalInstance = false;
private static final String ERROR_CANNOT_CREATE_DIRECTORY = "Could not create directory: ";
private boolean internalInstance = false;

public static FileActions getInstance() {
return getInstance(false);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/shaft/cucumber/ElementSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ public void waitForElementToBePresent(String locatorType, String locatorValue) {
* multiplied by the default element identification timeout (in the POM.xml
* file)
*
* @param locatorType can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}
* @param locatorValue the value/expression of the desired element locator
* @param locatorType can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}
* @param locatorValue the value/expression of the desired element locator
*/
@When("I Wait for the element found by {string}: {string} to be not present")
public void waitForElementToBeNotPresent(String locatorType, String locatorValue) {
Expand All @@ -268,9 +268,9 @@ public void waitForElementToBeNotPresent(String locatorType, String locatorValue
* multiplied by the default element identification timeout (in the POM.xml
* file)
*
* @param locatorType can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}
* @param locatorValue the value/expression of the desired element locator
* @param initialValue the initial text value of the target webElement
* @param locatorType can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}
* @param locatorValue the value/expression of the desired element locator
* @param initialValue the initial text value of the target webElement
*/
@When("I Wait for the text inside the element found by {string}: {string} to change from the initial value {string}")
public void waitForTextToChange(String locatorType, String locatorValue, String initialValue) {
Expand Down
Loading

0 comments on commit 7c6ef2c

Please sign in to comment.