-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSmartUIUtil.java
74 lines (62 loc) · 2.18 KB
/
SmartUIUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package io.github.lambdatest.utils;
import java.util.logging.Logger;
import org.json.JSONObject;
import com.google.gson.Gson;
import io.github.lambdatest.constants.Constants;
import io.github.lambdatest.models.Snapshot;
import io.github.lambdatest.models.SnapshotData;
import java.util.HashMap;
import java.util.Map;
import java.io.IOException;
public class SmartUIUtil {
private final HttpClientUtil httpClient;
private Logger log;
public SmartUIUtil() {
this.httpClient = new HttpClientUtil();
this.log = LoggerUtil.createLogger("lambdatest-java-sdk");
}
public boolean isSmartUIRunning() {
try {
httpClient.isSmartUIRunning();
return true;
} catch (Exception e) {
log.severe(e.getMessage());
return false;
}
}
public String fetchDOMSerializer() throws Exception {
try {
return httpClient.fetchDOMSerializer();
} catch (Exception e) {
log.severe(e.getMessage());
throw new Exception(Constants.Errors.FETCH_DOM_FAILED, e);
}
}
public String postSnapshot(Object snapshotDOM, Map<String, Object> options, String url, String snapshotName, String testType) throws Exception {
// Create Snapshot and SnapshotData objects
Snapshot snapshot = new Snapshot();
snapshot.setDom(snapshotDOM);
snapshot.setName(snapshotName);
snapshot.setOptions(options);
snapshot.setURL(url);
SnapshotData data = new SnapshotData();
data.setSnapshot(snapshot);
data.setTestType(testType);
// Serialize to JSON using Gson
Gson gson = new Gson();
String jsonData = gson.toJson(data);
try {
return httpClient.postSnapshot(jsonData);
} catch (Exception e) {
return null;
}
}
public static String getSmartUIServerAddress() {
String smartUiServerAddress = System.getenv(Constants.SMARTUI_SERVER_ADDRESS);
if (smartUiServerAddress != null && !smartUiServerAddress.isEmpty()) {
return smartUiServerAddress;
} else {
return "http://localhost:49152";
}
}
}