mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-03-21 01:59:13 +00:00
Move common methods to base classes
This commit is contained in:
parent
ef2d1d3afe
commit
403d8ea1bf
1
.gitignore
vendored
1
.gitignore
vendored
@ -28,3 +28,4 @@ pmu_logger.mod.c
|
|||||||
obj/
|
obj/
|
||||||
libs/armeabi
|
libs/armeabi
|
||||||
wlauto/workloads/*/uiauto/bin/
|
wlauto/workloads/*/uiauto/bin/
|
||||||
|
wlauto/external/uiauto/bin/
|
||||||
|
Binary file not shown.
BIN
wlauto/common/android/BaseUiAutomation$FindByCriteria.class
Normal file
BIN
wlauto/common/android/BaseUiAutomation$FindByCriteria.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
|
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
|
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 java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
|
||||||
@ -37,6 +38,14 @@ public class BaseUiAutomation extends UiAutomatorTestCase {
|
|||||||
public long waitTimeout = TimeUnit.SECONDS.toMillis(4);
|
public long waitTimeout = TimeUnit.SECONDS.toMillis(4);
|
||||||
public enum ScreenOrientation { RIGHT, NATURAL, LEFT };
|
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) {
|
public void sleep(int second) {
|
||||||
super.sleep(second * 1000);
|
super.sleep(second * 1000);
|
||||||
}
|
}
|
||||||
@ -276,4 +285,82 @@ public class BaseUiAutomation extends UiAutomatorTestCase {
|
|||||||
getUiDevice().getInstance().swipe(rect.centerX(), rect.centerY(),
|
getUiDevice().getInstance().swipe(rect.centerX(), rect.centerY(),
|
||||||
rect.centerX(), rect.centerY(), steps);
|
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) {
|
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",
|
List<String> command = Arrays.asList("dumpsys", "SurfaceFlinger", "--latency-clear",
|
||||||
packageView);
|
packageView);
|
||||||
executeCommand(command);
|
executeCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exitDumpsysSurfaceFlinger(String appPackage, File filename) {
|
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);
|
List<String> command = Arrays.asList("dumpsys", "SurfaceFlinger", "--latency", packageView);
|
||||||
exitDumpsys(command, filename);
|
exitDumpsys(command, filename);
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -30,9 +30,9 @@ import com.android.uiautomator.core.UiSelector;
|
|||||||
|
|
||||||
import com.arm.wlauto.uiauto.UxPerfUiAutomation;
|
import com.arm.wlauto.uiauto.UxPerfUiAutomation;
|
||||||
|
|
||||||
import static com.arm.wlauto.uiauto.googleslides.UiAutomation.FindByCriteria.BY_ID;
|
import static com.arm.wlauto.uiauto.BaseUiAutomation.FindByCriteria.BY_ID;
|
||||||
import static com.arm.wlauto.uiauto.googleslides.UiAutomation.FindByCriteria.BY_TEXT;
|
import static com.arm.wlauto.uiauto.BaseUiAutomation.FindByCriteria.BY_TEXT;
|
||||||
import static com.arm.wlauto.uiauto.googleslides.UiAutomation.FindByCriteria.BY_DESC;
|
import static com.arm.wlauto.uiauto.BaseUiAutomation.FindByCriteria.BY_DESC;
|
||||||
|
|
||||||
public class UiAutomation extends UxPerfUiAutomation {
|
public class UiAutomation extends UxPerfUiAutomation {
|
||||||
|
|
||||||
@ -49,10 +49,6 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
public static final String CLASS_IMAGE_BUTTON = "android.widget.ImageButton";
|
public static final String CLASS_IMAGE_BUTTON = "android.widget.ImageButton";
|
||||||
public static final String CLASS_TABLE_ROW = "android.widget.TableRow";
|
public static final String CLASS_TABLE_ROW = "android.widget.TableRow";
|
||||||
|
|
||||||
public enum FindByCriteria {
|
|
||||||
BY_ID, BY_TEXT, BY_DESC;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final int DIALOG_WAIT_TIME_MS = 3000;
|
public static final int DIALOG_WAIT_TIME_MS = 3000;
|
||||||
public static final int SLIDE_WAIT_TIME_MS = 200;
|
public static final int SLIDE_WAIT_TIME_MS = 200;
|
||||||
public static final int CLICK_REPEAT_INTERVAL_MS = 50;
|
public static final int CLICK_REPEAT_INTERVAL_MS = 50;
|
||||||
@ -188,7 +184,8 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
startDumpsys(ACTIVITY_SLIDES);
|
startDumpsys(ACTIVITY_SLIDES);
|
||||||
slideTimer = new Timer();
|
slideTimer = new Timer();
|
||||||
slideTimer.start();
|
slideTimer.start();
|
||||||
uiDeviceSwipeHorizontal(centerX + centerX/2, centerX - centerX/2, centerY);
|
uiDeviceSwipeHorizontal(centerX + centerX/2, centerX - centerX/2,
|
||||||
|
centerY, DEFAULT_SWIPE_STEPS);
|
||||||
slideTimer.end();
|
slideTimer.end();
|
||||||
results.put(testTag, slideTimer);
|
results.put(testTag, slideTimer);
|
||||||
endDumpsys(ACTIVITY_SLIDES, testTag);
|
endDumpsys(ACTIVITY_SLIDES, testTag);
|
||||||
@ -208,7 +205,8 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
startDumpsys(ACTIVITY_SLIDES);
|
startDumpsys(ACTIVITY_SLIDES);
|
||||||
slideTimer = new Timer();
|
slideTimer = new Timer();
|
||||||
slideTimer.start();
|
slideTimer.start();
|
||||||
uiDeviceSwipeHorizontal(centerX - centerX/2, centerX + centerX/2, centerY);
|
uiDeviceSwipeHorizontal(centerX - centerX/2, centerX + centerX/2,
|
||||||
|
centerY, DEFAULT_SWIPE_STEPS);
|
||||||
slideTimer.end();
|
slideTimer.end();
|
||||||
results.put(testTag, slideTimer);
|
results.put(testTag, slideTimer);
|
||||||
endDumpsys(ACTIVITY_SLIDES, testTag);
|
endDumpsys(ACTIVITY_SLIDES, testTag);
|
||||||
@ -234,7 +232,8 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
startDumpsys(ACTIVITY_SLIDES);
|
startDumpsys(ACTIVITY_SLIDES);
|
||||||
slideTimer = new Timer();
|
slideTimer = new Timer();
|
||||||
slideTimer.start();
|
slideTimer.start();
|
||||||
uiDeviceSwipeHorizontal(centerX + centerX/2, centerX - centerX/2, centerY);
|
uiDeviceSwipeHorizontal(centerX + centerX/2, centerX - centerX/2,
|
||||||
|
centerY, DEFAULT_SWIPE_STEPS);
|
||||||
slideTimer.end();
|
slideTimer.end();
|
||||||
results.put(testTag, slideTimer);
|
results.put(testTag, slideTimer);
|
||||||
endDumpsys(ACTIVITY_SLIDES, testTag);
|
endDumpsys(ACTIVITY_SLIDES, testTag);
|
||||||
@ -274,7 +273,7 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
clickView(BY_TEXT, "Droid Sans Mono");
|
clickView(BY_TEXT, "Droid Sans Mono");
|
||||||
clickView(BY_ID, PACKAGE_ID + "palette_back_button");
|
clickView(BY_ID, PACKAGE_ID + "palette_back_button");
|
||||||
UiObject decreaseFont = getViewByDesc("Decrease text");
|
UiObject decreaseFont = getViewByDesc("Decrease text");
|
||||||
repeatClickView(decreaseFont, 20);
|
repeatClickView(decreaseFont, 20, CLICK_REPEAT_INTERVAL_MS);
|
||||||
getUiDevice().pressBack();
|
getUiDevice().pressBack();
|
||||||
|
|
||||||
// get image from gallery and insert
|
// get image from gallery and insert
|
||||||
@ -387,80 +386,6 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void repeatClickView(UiObject view, int repeat) throws Exception {
|
|
||||||
if (repeat < 1 || !view.isClickable()) return;
|
|
||||||
while (repeat-- > 0) {
|
|
||||||
view.click();
|
|
||||||
SystemClock.sleep(CLICK_REPEAT_INTERVAL_MS); // 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uiDeviceSwipeHorizontal(int startX, int endX, int height) {
|
|
||||||
uiDeviceSwipeHorizontal(startX, endX, height, DEFAULT_SWIPE_STEPS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uiDeviceSwipeHorizontal(int startX, int endX, int height, int steps) {
|
|
||||||
getUiDevice().swipe(startX, height, endX, height, steps);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startDumpsys(String viewName) throws Exception {
|
public void startDumpsys(String viewName) throws Exception {
|
||||||
if (!dumpsysEnabled)
|
if (!dumpsysEnabled)
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user