Skip to content

Downgraded java version to support GS integration #19

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

Merged
merged 4 commits into from
Mar 24, 2025
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
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.lambdatest</groupId>
<artifactId>lambdatest-java-sdk</artifactId>
Expand Down Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.13</version> <!-- Use the latest stable version -->
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand Down Expand Up @@ -76,7 +76,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version> <!-- Use the latest version -->
<version>2.16.1</version>
</dependency>
</dependencies>
<build>
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/io/github/lambdatest/SmartUIAppSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.openqa.selenium.TakesScreenshot;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;
Expand All @@ -30,16 +31,15 @@ public SmartUIAppSnapshot() {
this.gson = new Gson();
}


public void start(Map<String, String> options) throws Exception{
try{
this.projectToken = getProjectToken(options);
log.info("Project token set as: " + this.projectToken);
} catch (Exception e){
log.severe(Constants.Errors.PROJECT_TOKEN_UNSET);
throw new Exception("Project token is a mandatory field");
throw new Exception("Project token is a mandatory field", e);
}
Map<String, String> envVars = System.getenv();
Map<String, String> envVars = new HashMap<>(System.getenv());
GitInfo git = GitUtils.getGitInfo(envVars);
// Authenticate user and create a build
try {
Expand All @@ -49,7 +49,7 @@ public void start(Map<String, String> options) throws Exception{
options.put("buildName", this.buildData.getName());
} catch(Exception e) {
log.severe("Couldn't create build: " + e.getMessage());
throw new IllegalStateException("Couldn't create build: " + e.getMessage());
throw new Exception("Couldn't create build: " + e.getMessage());
}
}
public void start() throws Exception{
Expand All @@ -69,7 +69,7 @@ public void start() throws Exception{
log.info("Build ID set : " + this.buildData.getBuildId() + "for Build name : "+ this.buildData.getName());
} catch(Exception e) {
log.severe("Couldn't create build: " + e.getMessage());
throw new IllegalStateException("Couldn't create build: " + e.getMessage());
throw new Exception("Couldn't create build due to: ", e);
}
}

Expand All @@ -90,7 +90,7 @@ private String getProjectToken(Map<String, String> options) {

public void smartuiAppSnapshot(AppiumDriver appiumDriver, String screenshotName, Map<String, String> options) throws Exception {
try {
if (Objects.isNull(appiumDriver)) {
if (appiumDriver == null) {
log.severe(Constants.Errors.SELENIUM_DRIVER_NULL +" during take snapshot");
throw new IllegalArgumentException(Constants.Errors.SELENIUM_DRIVER_NULL);
}
Expand All @@ -107,7 +107,7 @@ public void smartuiAppSnapshot(AppiumDriver appiumDriver, String screenshotName,
uploadSnapshotRequest.setScreenshotName(screenshotName);
uploadSnapshotRequest.setProjectToken(projectToken);
Dimension d = appiumDriver.manage().window().getSize();
int w = d.getWidth(), h = d.getWidth();
int w = d.getWidth(), h = d.getHeight();
uploadSnapshotRequest.setViewport(w+"x"+h);
log.info("Device viewport set to: "+ uploadSnapshotRequest.getViewport());
String platform = "", deviceName="", browserName ="";
Expand All @@ -117,10 +117,10 @@ public void smartuiAppSnapshot(AppiumDriver appiumDriver, String screenshotName,
if(options != null && options.containsKey("deviceName")){
deviceName = options.get("deviceName").trim();
}
if(Objects.isNull(deviceName) || deviceName.isEmpty()){
if(deviceName == null || deviceName.isEmpty()){
throw new IllegalArgumentException(Constants.Errors.DEVICE_NAME_NULL);
}
if(Objects.isNull(platform) || platform.isEmpty()){
if(platform == null || platform.isEmpty()){
if(deviceName.toLowerCase().startsWith("i")){
browserName = "iOS";
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/github/lambdatest/utils/GitUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.List;
import java.util.Map;

import java.util.logging.Logger;
import java.util.stream.Collectors;

public class GitUtils {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/github/lambdatest/utils/HttpClientUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;


Expand Down Expand Up @@ -72,8 +73,9 @@ private String delete(String url,Map<String, String> headers) throws IOException
return entity != null ? EntityUtils.toString(entity) : null;
}
catch (Exception e){
log.warning("Exception occured in delete "+ e.getMessage());}
return "Success";
log.warning("Exception occurred in Delete" + e);
throw e;
}
}

private String post(String url, String data) throws IOException {
Expand Down Expand Up @@ -173,7 +175,6 @@ public boolean isUserAuthenticated(String projectToken) throws IOException {
return true;
}
else{
log.warning("Error in authenticating user ...");
throw new IllegalArgumentException(Constants.Errors.USER_AUTH_ERROR);
}
}
Expand Down Expand Up @@ -209,19 +210,18 @@ public void stopBuild(String buildId, Map<String, String> headers) throws IOExce
}
}
String response = delete(Constants.SmartUIRoutes.HOST_URL + Constants.SmartUIRoutes.SMARTUI_FINALISE_BUILD_ROUTE +buildId, headers);
log.info("Response of stop Build: "+ response + "for buildId" + buildId);
}

public String uploadScreenshot(String url, File screenshot , UploadSnapshotRequest uploadScreenshotRequest, BuildData data) throws IOException {

try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
try {
HttpPost uploadRequest = new HttpPost(url);
uploadRequest.setHeader("projectToken", uploadScreenshotRequest.getProjectToken());

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.STRICT);

builder.addBinaryBody("screenshot", screenshot, ContentType.IMAGE_PNG, screenshot.getName());
builder.addBinaryBody("screenshot", screenshot, ContentType.create("image/png"), screenshot.getName());
builder.addTextBody("buildId", uploadScreenshotRequest.getBuildId());
builder.addTextBody("buildName", uploadScreenshotRequest.getBuildName());
builder.addTextBody("screenshotName", uploadScreenshotRequest.getScreenshotName());
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/github/lambdatest/utils/SmartUIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import java.io.File;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import io.github.lambdatest.models.*;
Expand All @@ -24,7 +25,7 @@ public boolean isSmartUIRunning() {
httpClient.isSmartUIRunning();
return true;
} catch (Exception e) {
log.severe(e.getMessage());
log.severe("Exception occurred " + e);
return false;
}
}
Expand Down Expand Up @@ -112,7 +113,7 @@ public BuildResponse build(GitInfo git ,String projectToken, Map<String, String>
if(Objects.nonNull(git)){
createBuildRequest.setGit(git);}
String createBuildJson = gson.toJson(createBuildRequest);
Map<String,String> header = new HashMap<>() ;
Map<String,String> header = new HashMap<String, String>() ;
header.put(Constants.PROJECT_TOKEN, projectToken);
String createBuildResponse = httpClient.createSmartUIBuild(createBuildJson, header);
BuildResponse buildData = gson.fromJson(createBuildResponse, BuildResponse.class);
Expand All @@ -124,7 +125,7 @@ public BuildResponse build(GitInfo git ,String projectToken, Map<String, String>

public void stopBuild(String buildId, String projectToken) throws Exception{
try{
Map<String,String> headers = new HashMap<>();
Map<String,String> headers = new HashMap<String, String>();
headers.put(Constants.PROJECT_TOKEN, projectToken);
httpClient.stopBuild(buildId, headers);
}
Expand Down