Android Apps Performance Testing Using Appium

How to use driver.getPerformanceData method in Appium Android Driver

((AndroidDriver)driver).getPerformanceData("<package>", "<perf type>", <timeout>);

Get Performance Data Types

List<String> performanceTypes = driver.getSupportedPerformanceDataTypes();
List<List<Object>> data = driver.getPerformanceData("com.makemytrip", "memoryinfo", 10);
private HashMap<String, Integer> getMemoryInfo(AndroidDriver driver) throws Exception {
List<List<Object>> data = driver.getPerformanceData("com.makemytrip", "memoryinfo", 10);
HashMap<String, Integer> readableData = new HashMap<>();
for (int i = 0; i < data.get(0).size(); i++) {
int val;
if (data.get(1).get(i) == null) {
val = 0;
} else {
val = Integer.parseInt((String) data.get(1).get(i));
}
readableData.put((String) data.get(0).get(i), val);
}
return readableData;
}
//totalPss = Proportional Set Size
HashMap<String, Integer> memoryInfo = getMemoryInfo(driver);
int setSize = memoryInfo.get("totalPss");
@Test
public void testMemoryUsage() throws Exception {
// get the usage at one point in time
int totalPss1 = getMemoryInfo(driver).get(PSS_TYPE);
// then get it again after waiting a while
utility.threadSleep(MEMORY_USAGE_WAIT);
int totalPss2 = getMemoryInfo(driver).get(PSS_TYPE);
// finally, verify that we haven't increased usage more than 5%
Assert.assertThat((double) totalPss2, Matchers.lessThan(totalPss1 * 1.05));
}
/**
* Get Memory Info
*
* @param driver
* @return
* @throws Exception
*/
private HashMap<String, Integer> getMemoryInfo(AndroidDriver driver) throws Exception {
List<List<Object>> data = driver.getPerformanceData(PKG, PERF_TYPE, MEMORY_CAPTURE_WAIT);
HashMap<String, Integer> readableData = new HashMap<>();
for (int i = 0; i < data.get(0).size(); i++) {
int val;
if (data.get(1).get(i) == null) {
val = 0;
} else {
val = Integer.parseInt((String) data.get(1).get(i));
}
readableData.put((String) data.get(0).get(i), val);
}
return readableData;
}

--

--

https://stackoverflow.com/users/5372079/abhishek-dhoundiya

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store