diff --git a/src/main/java/io/percy/appium/AppPercy.java b/src/main/java/io/percy/appium/AppPercy.java index e9fd2ee..d44beb7 100644 --- a/src/main/java/io/percy/appium/AppPercy.java +++ b/src/main/java/io/percy/appium/AppPercy.java @@ -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) { diff --git a/src/main/java/io/percy/appium/Environment.java b/src/main/java/io/percy/appium/Environment.java index 086bcdd..c946c0d 100644 --- a/src/main/java/io/percy/appium/Environment.java +++ b/src/main/java/io/percy/appium/Environment.java @@ -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; } diff --git a/src/main/java/io/percy/appium/lib/CliWrapper.java b/src/main/java/io/percy/appium/lib/CliWrapper.java index 7a3057b..c6b8329 100644 --- a/src/main/java/io/percy/appium/lib/CliWrapper.java +++ b/src/main/java/io/percy/appium/lib/CliWrapper.java @@ -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; } } @@ -95,7 +95,7 @@ public String postScreenshot(String name, JSONObject tag, List 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); @@ -113,8 +113,26 @@ public String postScreenshot(String name, JSONObject tag, List 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 capabilities, Map options) { + Map capabilities, Map options) { // Build a JSON object to POST back to the cli node process JSONObject data = new JSONObject(); data.put("snapshotName", name); @@ -122,7 +140,7 @@ public String postScreenshotPOA(String name, String sessionId, String commandExe 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); diff --git a/src/test/java/io/percy/appium/EnvironmentTest.java b/src/test/java/io/percy/appium/EnvironmentTest.java index e8da0fc..23165fb 100644 --- a/src/test/java/io/percy/appium/EnvironmentTest.java +++ b/src/test/java/io/percy/appium/EnvironmentTest.java @@ -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