Skip to content

Commit

Permalink
Sending failed event logs to cli (#139)
Browse files Browse the repository at this point in the history
* Sending failed event logs to cli

* addign language indentifier to client into

* adding more info
  • Loading branch information
prklm10 authored Oct 26, 2023
1 parent d346981 commit b0c7d0d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/java/io/percy/appium/AppPercy.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void screenshot(String name, Boolean fullScreen, ScreenshotOptions option
options.setFullScreen(fullScreen);
provider.screenshot(name, options);
} catch (Exception e) {
cliWrapper.postFailedEvent(e.getMessage());
log("Error taking screenshot " + name);
log(e.toString());
if (!ignoreErrors) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/percy/appium/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public Environment(AppiumDriver driver) {
this.driver = driver;
}

public String getClientInfo() {
public String getClientInfo(Boolean flag) {
if (flag) {
return SDK_NAME + "-java" + "/" + SDK_VERSION;
}
return SDK_NAME + "/" + SDK_VERSION;
}

Expand Down
30 changes: 24 additions & 6 deletions src/main/java/io/percy/appium/lib/CliWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public boolean healthcheck() {
} else {
if (minorVersion < 27) {
AppPercy.log("Percy CLI version, " + version
+ " is not minimum version required "
+ "Percy on Automate is available from 1.27.0-beta.0.",
"warn");
+ " is not minimum version required "
+ "Percy on Automate is available from 1.27.0-beta.0.",
"warn");
return false;
}
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public String postScreenshot(String name, JSONObject tag, List<Tile> tiles, Stri
data.put("externalDebugUrl", externalDebugUrl);
data.put("ignoredElementsData", ignoredElementsData);
data.put("consideredElementsData", consideredElementsData);
data.put("clientInfo", env.getClientInfo());
data.put("clientInfo", env.getClientInfo(false));
data.put("environmentInfo", env.getEnvironmentInfo());

StringEntity entity = new StringEntity(data.toString(), ContentType.APPLICATION_JSON);
Expand All @@ -113,16 +113,34 @@ public String postScreenshot(String name, JSONObject tag, List<Tile> tiles, Stri
return null;
}

public void postFailedEvent(String err) {
// Build a JSON object to POST back to the cli node process
JSONObject data = new JSONObject();
data.put("clientInfo", env.getClientInfo(true));
data.put("message", err);
data.put("errroKind", "sdk");

StringEntity entity = new StringEntity(data.toString(), ContentType.APPLICATION_JSON);

try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
HttpPost request = new HttpPost(PERCY_SERVER_ADDRESS + "/percy/events");
request.setEntity(entity);
httpClient.execute(request);
} catch (Exception ex) {
AppPercy.log(ex.toString(), "debug");
}
}

public String postScreenshotPOA(String name, String sessionId, String commandExecutorUrl,
Map<String, Object> capabilities, Map<String, Object> options) {
Map<String, Object> capabilities, Map<String, Object> options) {
// Build a JSON object to POST back to the cli node process
JSONObject data = new JSONObject();
data.put("snapshotName", name);
data.put("sessionId", sessionId);
data.put("commandExecutorUrl", commandExecutorUrl);
data.put("capabilities", capabilities);
data.put("options", options);
data.put("clientInfo", env.getClientInfo());
data.put("clientInfo", env.getClientInfo(false));
data.put("environmentInfo", env.getEnvironmentInfo());

StringEntity entity = new StringEntity(data.toString(), ContentType.APPLICATION_JSON);
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/io/percy/appium/EnvironmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ public void setup() {

@Test
public void testGetClientInfo() {
Assert.assertEquals(environment.getClientInfo(), "percy-appium-app/" + Environment.SDK_VERSION);
Assert.assertEquals(environment.getClientInfo(false), "percy-appium-app/" + Environment.SDK_VERSION);
}

@Test
public void testGetClientInfoWithFlagTrue() {
Assert.assertEquals(environment.getClientInfo(true), "percy-appium-app-java/" + Environment.SDK_VERSION);
}

@Test
Expand Down

0 comments on commit b0c7d0d

Please sign in to comment.