Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public class MobileCommand {
protected static final String GET_DEVICE_TIME;
protected static final String GET_SESSION;

protected static final String GET_PERFORMANCE_DATA;
protected static final String GET_SUPPORTED_PERFORMANCE_DATA_TYPES;


protected static final String HIDE_KEYBOARD;
protected static final String LOCK;
//iOS
Expand Down Expand Up @@ -92,6 +96,9 @@ public class MobileCommand {
GET_DEVICE_TIME = "getDeviceTime";
GET_SESSION = "getSession";

GET_PERFORMANCE_DATA = "getPerformanceData";
GET_SUPPORTED_PERFORMANCE_DATA_TYPES = "getSuppportedPerformanceDataTypes";

HIDE_KEYBOARD = "hideKeyboard";
LOCK = "lock";
SHAKE = "shake";
Expand Down Expand Up @@ -136,6 +143,11 @@ public class MobileCommand {
commandRepository.put(SET_SETTINGS, postC("/session/:sessionId/appium/settings"));
commandRepository.put(GET_DEVICE_TIME, getC("/session/:sessionId/appium/device/system_time"));
commandRepository.put(GET_SESSION,getC("/session/:sessionId/"));
commandRepository.put(GET_SUPPORTED_PERFORMANCE_DATA_TYPES,
postC("/session/:sessionId/appium/performanceData/types"));
commandRepository.put(GET_PERFORMANCE_DATA,
postC("/session/:sessionId/appium/getPerformanceData"));

//iOS
commandRepository.put(SHAKE, postC("/session/:sessionId/appium/device/shake"));
commandRepository.put(TOUCH_ID, postC("/session/:sessionId/appium/simulator/touch_id"));
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/io/appium/java_client/android/AndroidDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package io.appium.java_client.android;

import static io.appium.java_client.android.AndroidMobileCommandHelper.endTestCoverageCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.getPerformanceDataCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.getSupportedPerformanceDataTypesCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.openNotificationsCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleLocationServicesCommand;

Expand All @@ -31,9 +33,11 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.remote.http.HttpClient;

import java.net.URL;
import java.util.List;

/**
* @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.
Expand Down Expand Up @@ -152,6 +156,51 @@ public AndroidDriver(Capabilities desiredCapabilities) {
super(substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM));
}

/**
* returns the information type of the system state which is supported to read
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @heeseon
Everything is ok but... could you remove the code below and move java doc to the HasSupportedPerformanceDataType? It is not necessary to duplicate code of API implemented by default. I think there is no specific details of the AndroidDriver behaviour.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heeseon ping

* as like cpu, memory, network traffic, and battery.
* @return output - array like below
* [cpuinfo, batteryinfo, networkinfo, memoryinfo]
*
*/
public List<String> getSupportedPerformanceDataTypes() {
return CommandExecutionHelper.execute(this, getSupportedPerformanceDataTypesCommand());
}

/**
* returns the resource usage information of the application. the resource is one of the system state
* which means cpu, memory, network traffic, and battery.
*
* @param packageName the package name of the application
* @param dataType the type of system state which wants to read.
* It should be one of the supported performance data types,
* the return value of the function "getSupportedPerformanceDataTypes"
* @param dataReadTimeout the number of attempts to read
* @return table of the performance data, The first line of the table represents the type of data.
* The remaining lines represent the values of the data.
* in case of battery info : [[power], [23]]
* in case of memory info :
* [[totalPrivateDirty, nativePrivateDirty, dalvikPrivateDirty, eglPrivateDirty, glPrivateDirty,
* totalPss, nativePss, dalvikPss, eglPss, glPss, nativeHeapAllocatedSize, nativeHeapSize],
* [18360, 8296, 6132, null, null, 42588, 8406, 7024, null, null, 26519, 10344]]
* in case of network info :
* [[bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations, bucketDuration,],
* [1478091600000, null, 1099075, 610947, 928, 114362, 769, 0, 3600000],
* [1478095200000, null, 1306300, 405997, 509, 46359, 370, 0, 3600000]]
* in case of network info :
* [[st, activeTime, rb, rp, tb, tp, op, bucketDuration],
* [1478088000, null, null, 32115296, 34291, 2956805, 25705, 0, 3600],
* [1478091600, null, null, 2714683, 11821, 1420564, 12650, 0, 3600],
* [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600],
* [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
* in case of cpu info : [[user, kernel], [0.9, 1.3]]
* @throws if the performance data type is not supported, thows Error
*/
public List<List<Object>> getPerformanceData(String packageName, String dataType, int dataReadTimeout) {
return CommandExecutionHelper.execute(this,
getPerformanceDataCommand(packageName, dataType, dataReadTimeout));
}

/**
* This method is deprecated. It is going to be removed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openqa.selenium.internal.HasIdentity;

import java.util.AbstractMap;
import java.util.List;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied

import java.util.Map;

/**
Expand Down Expand Up @@ -63,6 +64,55 @@ public class AndroidMobileCommandHelper extends MobileCommand {
END_TEST_COVERAGE, prepareArguments(parameters, values));
}

/**
* returns the information type of the system state which is supported to read
* as like cpu, memory, network traffic, and battery.
* @return output - array like below
* [cpuinfo, batteryinfo, networkinfo, memoryinfo]
*
*/
public static Map.Entry<String, Map<String, ?>> getSupportedPerformanceDataTypesCommand() {
return new AbstractMap.SimpleEntry<>(
GET_SUPPORTED_PERFORMANCE_DATA_TYPES, ImmutableMap.<String, Object>of());
}

/**
* returns the resource usage information of the application. the resource is one of the system state
* which means cpu, memory, network traffic, and battery.
*
* @param packageName the package name of the application
* @param dataType the type of system state which wants to read.
* It should be one of the supported performance data types,
* the return value of the function "getSupportedPerformanceDataTypes"
* @param dataReadTimeout the number of attempts to read
* @return table of the performance data, The first line of the table represents the type of data.
* The remaining lines represent the values of the data.
* in case of battery info : [[power], [23]]
* in case of memory info :
* [[totalPrivateDirty, nativePrivateDirty, dalvikPrivateDirty, eglPrivateDirty, glPrivateDirty,
* totalPss, nativePss, dalvikPss, eglPss, glPss, nativeHeapAllocatedSize, nativeHeapSize],
* [18360, 8296, 6132, null, null, 42588, 8406, 7024, null, null, 26519, 10344]]
* in case of network info :
* [[bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations, bucketDuration,],
* [1478091600000, null, 1099075, 610947, 928, 114362, 769, 0, 3600000],
* [1478095200000, null, 1306300, 405997, 509, 46359, 370, 0, 3600000]]
* in case of network info :
* [[st, activeTime, rb, rp, tb, tp, op, bucketDuration],
* [1478088000, null, null, 32115296, 34291, 2956805, 25705, 0, 3600],
* [1478091600, null, null, 2714683, 11821, 1420564, 12650, 0, 3600],
* [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600],
* [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
* in case of cpu info : [[user, kernel], [0.9, 1.3]]
* @throws if the performance data type is not supported, thows Error
*/
public static Map.Entry<String, Map<String, ?>> getPerformanceDataCommand(
String packageName, String dataType, int dataReadTimeout) {
String[] parameters = new String[] {"packageName", "dataType", "dataReadTimeout"};
Object[] values = new Object[] {packageName, dataType, dataReadTimeout};
return new AbstractMap.SimpleEntry<>(
GET_PERFORMANCE_DATA, prepareArguments(parameters, values));
}

/**
* This method forms a {@link java.util.Map} of parameters to
* Retrieve the display density of the Android device.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.io.File;
import java.util.Map;
import java.util.List;

public class AndroidDriverTest extends BaseAndroidTest {

Expand Down Expand Up @@ -140,4 +141,33 @@ public class AndroidDriverTest extends BaseAndroidTest {
assertNotNull(driver.getDisplayDensity());
assertNotEquals(0, driver.getSystemBars().size());
}

@Test public void getSupportedPerformanceDataTypesTest() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I used assertEquals

driver.startActivity("io.appium.android.apis", ".ApiDemos");

List<String> supportedPerformanceDataTypes = driver.getSupportedPerformanceDataTypes();
assert(supportedPerformanceDataTypes.size() == 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be more readable to use assertEquals instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


}

@Test public void getPerformanceDataTest() {
driver.startActivity("io.appium.android.apis", ".ApiDemos");

List<String> supportedPerformanceDataTypes = driver.getSupportedPerformanceDataTypes();

for(int i = 0 ; i < supportedPerformanceDataTypes.size() ; ++ i){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not to use for .. in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i applied it.
but I think there is no reason to check the value of the table, because the values could be changed in appium-android-driver.
I have a plan to add some other values for example, heaphistogram....


String dataType = supportedPerformanceDataTypes.get(i);

List<List<Object>> valueTable = driver.getPerformanceData("com.example.android.apis", dataType, 60000);

int valueTableHeadLength = valueTable.get(0).size();

for(int j = 1 ; j < valueTable.size() ; ++ j){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. Use subList property to get a slice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the difference between List.get(i) and List.subList(i,i).
but I applied it.

and one more,
in case of this method,
there is no reason to check the head value of the returned table, because the implementation is dependent for the platform that means the head value could be changed.

assert(valueTableHeadLength == valueTable.get(j).size());
}
}

}

}