Skip to content

Commit

Permalink
Fixed a NullRef exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ninadbstack committed Mar 31, 2023
1 parent b2f66b0 commit cc62b1f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/io/percy/appium/providers/AppAutomate.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,27 @@ public String screenshot(String name, ScreenshotOptions options) {
String percyScreenshotUrl = "";
String error = null;
String device = deviceName(options.getDeviceName(), result);
String osVersion = osVersion(result);

super.setDebugUrl(getDebugUrl(result));
try {
percyScreenshotUrl = super.screenshot(name, options,
result.getString("osVersion").split("\\.")[0], device);
percyScreenshotUrl = super.screenshot(name, options, osVersion, device);
} catch (Exception e) {
error = e.getMessage();
}
executePercyScreenshotEnd(name, percyScreenshotUrl, error);
return null;
}

public String osVersion(JSONObject result) {
return result != null ? result.getString("osVersion").split("\\.")[0] : null;
}

public String deviceName(String deviceName, JSONObject result) {
if (deviceName != null) {
return deviceName;
}
return result.getString("deviceName");
return result != null ? result.getString("deviceName") : null;
}

}
22 changes: 22 additions & 0 deletions src/test/java/io/percy/appium/providers/AppAutomateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,28 @@ public void testDeviceName() {
Assert.assertEquals(appAutomate.deviceName(null, result), "Samsung Galaxy S22");
}

@Test
public void testDeviceNameWithPassedDeviceName() {
JSONObject result = new JSONObject("{\"deviceName\":\"Samsung Galaxy S22\"}");
Assert.assertEquals(appAutomate.deviceName("Custom name", result), "Custom name");
}

@Test
public void testDeviceNameWithNullResult() {
Assert.assertEquals(appAutomate.deviceName(null, null), null);
}

@Test
public void testOsName() {
JSONObject result = new JSONObject("{\"osVersion\":\"13.6\"}");
Assert.assertEquals(appAutomate.osVersion(result), "13");
}

@Test
public void testOsNameWithNullResult() {
Assert.assertEquals(appAutomate.osVersion(null), null);
}

@Test
public void testDeviceNameWhenProvidedInParams() {
Assert.assertEquals(appAutomate.deviceName("Samsung Galaxy S22 Ultra", null), "Samsung Galaxy S22 Ultra");
Expand Down

0 comments on commit cc62b1f

Please sign in to comment.