mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-10-19 02:04:03 +01:00
Move common methods to base classes
This commit is contained in:
6
wlauto/external/uiauto/build.sh
vendored
6
wlauto/external/uiauto/build.sh
vendored
@@ -16,6 +16,12 @@
|
||||
|
||||
|
||||
|
||||
# Build and return appropriate exit code if failed
|
||||
ant build
|
||||
exit_code=$?
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
echo "ERROR: 'ant build' exited with code $exit_code"
|
||||
exit $exit_code
|
||||
fi
|
||||
|
||||
cp bin/classes/com/arm/wlauto/uiauto/*.class ../../common/android
|
||||
|
@@ -23,6 +23,7 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
|
||||
@@ -37,6 +38,14 @@ public class BaseUiAutomation extends UiAutomatorTestCase {
|
||||
public long waitTimeout = TimeUnit.SECONDS.toMillis(4);
|
||||
public enum ScreenOrientation { RIGHT, NATURAL, LEFT };
|
||||
|
||||
public static final int CLICK_REPEAT_INTERVAL_MINIMUM = 5;
|
||||
public static final int CLICK_REPEAT_INTERVAL_DEFAULT = 50;
|
||||
|
||||
/*
|
||||
* Used by clickView() methods in order to provide a consistent API
|
||||
*/
|
||||
public enum FindByCriteria { BY_ID, BY_TEXT, BY_DESC; }
|
||||
|
||||
public void sleep(int second) {
|
||||
super.sleep(second * 1000);
|
||||
}
|
||||
@@ -276,4 +285,82 @@ public class BaseUiAutomation extends UiAutomatorTestCase {
|
||||
getUiDevice().getInstance().swipe(rect.centerX(), rect.centerY(),
|
||||
rect.centerX(), rect.centerY(), steps);
|
||||
}
|
||||
|
||||
public void uiDeviceSwipeVertical(int startY, int endY, int xCoordinate, int steps) {
|
||||
getUiDevice().swipe(startY, xCoordinate, endY, xCoordinate, steps);
|
||||
}
|
||||
|
||||
public void uiDeviceSwipeHorizontal(int startX, int endX, int yCoordinate, int steps) {
|
||||
getUiDevice().swipe(startX, yCoordinate, endX, yCoordinate, steps);
|
||||
}
|
||||
|
||||
public void repeatClickView(UiObject view, int repeatCount, int intervalInMillis) throws Exception {
|
||||
int repeatInterval = intervalInMillis > CLICK_REPEAT_INTERVAL_MINIMUM ? intervalInMillis : CLICK_REPEAT_INTERVAL_DEFAULT;
|
||||
if (repeatCount < 1 || !view.isClickable()) {
|
||||
return;
|
||||
}
|
||||
while (repeatCount-- > 0) {
|
||||
view.click();
|
||||
SystemClock.sleep(repeatInterval); // in order to register as separate click
|
||||
}
|
||||
}
|
||||
|
||||
public UiObject clickView(FindByCriteria criteria, String matching) throws Exception {
|
||||
return clickView(criteria, matching, null, false);
|
||||
}
|
||||
|
||||
public UiObject clickView(FindByCriteria criteria, String matching, boolean wait) throws Exception {
|
||||
return clickView(criteria, matching, null, wait);
|
||||
}
|
||||
|
||||
public UiObject clickView(FindByCriteria criteria, String matching, String clazz) throws Exception {
|
||||
return clickView(criteria, matching, clazz, false);
|
||||
}
|
||||
|
||||
public UiObject clickView(FindByCriteria criteria, String matching, String clazz, boolean wait) throws Exception {
|
||||
UiObject view;
|
||||
switch (criteria) {
|
||||
case BY_ID:
|
||||
view = clazz == null ? getViewById(matching) : getUiObjectByResourceId(matching, clazz);
|
||||
break;
|
||||
case BY_DESC:
|
||||
view = clazz == null ? getViewByDesc(matching) : getUiObjectByDescription(matching, clazz);
|
||||
break;
|
||||
case BY_TEXT:
|
||||
default:
|
||||
view = clazz == null ? getViewByText(matching) : getUiObjectByText(matching, clazz);
|
||||
break;
|
||||
}
|
||||
if (wait) {
|
||||
view.clickAndWaitForNewWindow();
|
||||
} else {
|
||||
view.click();
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public UiObject getViewByText(String text) throws Exception {
|
||||
UiObject object = new UiObject(new UiSelector().textContains(text));
|
||||
if (!object.waitForExists(waitTimeout)) {
|
||||
throw new UiObjectNotFoundException("Could not find view with text: " + text);
|
||||
};
|
||||
return object;
|
||||
}
|
||||
|
||||
public UiObject getViewByDesc(String desc) throws Exception {
|
||||
UiObject object = new UiObject(new UiSelector().descriptionContains(desc));
|
||||
if (!object.waitForExists(waitTimeout)) {
|
||||
throw new UiObjectNotFoundException("Could not find view with description: " + desc);
|
||||
};
|
||||
return object;
|
||||
}
|
||||
|
||||
public UiObject getViewById(String id) throws Exception {
|
||||
UiObject object = new UiObject(new UiSelector().resourceId(id));
|
||||
if (!object.waitForExists(waitTimeout)) {
|
||||
throw new UiObjectNotFoundException("Could not find view with resource ID: " + id);
|
||||
};
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -110,14 +110,20 @@ public class UxPerfUiAutomation extends BaseUiAutomation {
|
||||
}
|
||||
|
||||
public void initDumpsysSurfaceFlinger(String appPackage) {
|
||||
String packageView = getSurfaceFlingerView(appPackage);
|
||||
initDumpsysSurfaceFlinger(appPackage, getSurfaceFlingerView(appPackage));
|
||||
}
|
||||
|
||||
public void initDumpsysSurfaceFlinger(String appPackage, String packageView) {
|
||||
List<String> command = Arrays.asList("dumpsys", "SurfaceFlinger", "--latency-clear",
|
||||
packageView);
|
||||
executeCommand(command);
|
||||
}
|
||||
|
||||
public void exitDumpsysSurfaceFlinger(String appPackage, File filename) {
|
||||
String packageView = getSurfaceFlingerView(appPackage);
|
||||
exitDumpsysSurfaceFlinger(appPackage, getSurfaceFlingerView(appPackage), filename);
|
||||
}
|
||||
|
||||
public void exitDumpsysSurfaceFlinger(String appPackage, String packageView, File filename) {
|
||||
List<String> command = Arrays.asList("dumpsys", "SurfaceFlinger", "--latency", packageView);
|
||||
exitDumpsys(command, filename);
|
||||
}
|
||||
|
Reference in New Issue
Block a user