mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-02-22 12:58:36 +00:00
Merge pull request #262 from jimboatarm/youtube-codetidy
Youtube: Codetidy to conform with the other workloads
This commit is contained in:
commit
5bed658045
@ -22,8 +22,9 @@ class Youtube(AndroidUxPerfWorkload):
|
|||||||
name = 'youtube'
|
name = 'youtube'
|
||||||
package = 'com.google.android.youtube'
|
package = 'com.google.android.youtube'
|
||||||
min_apk_version = '11.19.56'
|
min_apk_version = '11.19.56'
|
||||||
max_apk_version = None # works with latest (11.33.58) at time of publishing this
|
|
||||||
activity = ''
|
activity = ''
|
||||||
|
view = [package + '/com.google.android.apps.youtube.app.WatchWhileActivity',
|
||||||
|
package + '/com.google.android.apps.youtube.app.honeycomb.SettingsActivity']
|
||||||
description = '''
|
description = '''
|
||||||
A workload to perform standard productivity tasks within YouTube.
|
A workload to perform standard productivity tasks within YouTube.
|
||||||
|
|
||||||
@ -66,15 +67,13 @@ class Youtube(AndroidUxPerfWorkload):
|
|||||||
Parameter('search_term', kind=str,
|
Parameter('search_term', kind=str,
|
||||||
default='Big Buck Bunny 60fps 4K - Official Blender Foundation Short Film',
|
default='Big Buck Bunny 60fps 4K - Official Blender Foundation Short Film',
|
||||||
description='''
|
description='''
|
||||||
The search term to use when ``video_source`` is set to ``search``. Ignored otherwise.
|
The search term to use when ``video_source`` is set to ``search``.
|
||||||
|
Ignored otherwise.
|
||||||
'''),
|
'''),
|
||||||
]
|
]
|
||||||
|
|
||||||
view = [
|
# This workload relies on the internet so check that there is a working
|
||||||
package + '/com.google.android.apps.youtube.app.WatchWhileActivity',
|
# internet connection
|
||||||
package + '/com.google.android.apps.youtube.app.honeycomb.SettingsActivity',
|
|
||||||
]
|
|
||||||
|
|
||||||
requires_network = True
|
requires_network = True
|
||||||
|
|
||||||
def __init__(self, device, **kwargs):
|
def __init__(self, device, **kwargs):
|
||||||
@ -82,9 +81,9 @@ class Youtube(AndroidUxPerfWorkload):
|
|||||||
self.run_timeout = 300
|
self.run_timeout = 300
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if self.video_source == 'search' and not self.search_term:
|
super(Youtube, self).validate()
|
||||||
raise WorkloadError("Param 'search_term' must be specified when video source is 'search'")
|
|
||||||
|
|
||||||
self.uiauto_params['package'] = self.package
|
|
||||||
self.uiauto_params['video_source'] = self.video_source
|
self.uiauto_params['video_source'] = self.video_source
|
||||||
self.uiauto_params['search_term'] = self.search_term.replace(' ', '0space0')
|
self.uiauto_params['search_term'] = self.search_term.replace(' ', '0space0')
|
||||||
|
# Make sure search term is set if video source is 'search'
|
||||||
|
if (self.video_source == 'search') and not self.search_term:
|
||||||
|
raise WorkloadError("Param 'search_term' must be specified when video source is 'search'")
|
Binary file not shown.
@ -17,7 +17,6 @@ package com.arm.wlauto.uiauto.youtube;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
// Import the uiautomator libraries
|
// Import the uiautomator libraries
|
||||||
import com.android.uiautomator.core.UiObject;
|
import com.android.uiautomator.core.UiObject;
|
||||||
@ -32,54 +31,68 @@ import static com.arm.wlauto.uiauto.BaseUiAutomation.FindByCriteria.BY_DESC;
|
|||||||
|
|
||||||
public class UiAutomation extends UxPerfUiAutomation {
|
public class UiAutomation extends UxPerfUiAutomation {
|
||||||
|
|
||||||
public static final String CLASS_BUTTON = "android.widget.Button";
|
public Bundle parameters;
|
||||||
public static final String CLASS_TEXT_VIEW = "android.widget.TextView";
|
public String packageName;
|
||||||
|
public String packageID;
|
||||||
|
|
||||||
public static final int WAIT_TIMEOUT_1SEC = 1000;
|
|
||||||
public static final int VIDEO_SLEEP_SECONDS = 3;
|
|
||||||
public static final int LIST_SWIPE_COUNT = 5;
|
|
||||||
public static final String SOURCE_MY_VIDEOS = "my_videos";
|
public static final String SOURCE_MY_VIDEOS = "my_videos";
|
||||||
public static final String SOURCE_SEARCH = "search";
|
public static final String SOURCE_SEARCH = "search";
|
||||||
public static final String SOURCE_TRENDING = "trending";
|
public static final String SOURCE_TRENDING = "trending";
|
||||||
|
|
||||||
protected ActionLogger logger;
|
public static final int WAIT_TIMEOUT_1SEC = 1000;
|
||||||
protected Bundle parameters;
|
public static final int VIDEO_SLEEP_SECONDS = 3;
|
||||||
protected String packageName;
|
public static final int LIST_SWIPE_COUNT = 5;
|
||||||
protected String packageID;
|
|
||||||
protected String videoSource;
|
|
||||||
protected String searchTerm;
|
|
||||||
|
|
||||||
public void runUiAutomation() throws Exception {
|
public void runUiAutomation() throws Exception {
|
||||||
parameters = getParams();
|
parameters = getParams();
|
||||||
packageName = parameters.getString("package");
|
packageName = parameters.getString("package");
|
||||||
packageID = packageName + ":id/";
|
packageID = packageName + ":id/";
|
||||||
videoSource = parameters.getString("video_source");
|
|
||||||
searchTerm = parameters.getString("search_term");
|
String videoSource = parameters.getString("video_source");
|
||||||
|
String searchTerm = parameters.getString("search_term");
|
||||||
if (searchTerm != null) {
|
if (searchTerm != null) {
|
||||||
searchTerm = searchTerm.replaceAll("0space0", " ");
|
searchTerm = searchTerm.replace("0space0", " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
setScreenOrientation(ScreenOrientation.NATURAL);
|
setScreenOrientation(ScreenOrientation.NATURAL);
|
||||||
|
|
||||||
clearFirstRunDialogues();
|
clearFirstRunDialogues();
|
||||||
disableAutoplay();
|
disableAutoplay();
|
||||||
testPlayVideo(videoSource, searchTerm);
|
testPlayVideo(videoSource, searchTerm);
|
||||||
|
dismissAdvert();
|
||||||
|
checkPlayerError();
|
||||||
|
pausePlayVideo();
|
||||||
|
checkVideoInfo();
|
||||||
|
scrollRelated();
|
||||||
|
|
||||||
unsetScreenOrientation();
|
unsetScreenOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearFirstRunDialogues() throws Exception {
|
public void clearFirstRunDialogues() throws Exception {
|
||||||
UiObject laterButton = new UiObject(new UiSelector().textContains("Later").className(CLASS_TEXT_VIEW));
|
UiObject laterButton =
|
||||||
|
new UiObject(new UiSelector().textContains("Later")
|
||||||
|
.className("android.widget.TextView"));
|
||||||
if (laterButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
if (laterButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
||||||
laterButton.click();
|
laterButton.click();
|
||||||
}
|
}
|
||||||
UiObject cancelButton = new UiObject(new UiSelector().textContains("Cancel").className(CLASS_BUTTON));
|
|
||||||
|
UiObject cancelButton =
|
||||||
|
new UiObject(new UiSelector().textContains("Cancel")
|
||||||
|
.className("android.widget.Button"));
|
||||||
if (cancelButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
if (cancelButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
||||||
cancelButton.click();
|
cancelButton.click();
|
||||||
}
|
}
|
||||||
UiObject skipButton = new UiObject(new UiSelector().textContains("Skip").className(CLASS_TEXT_VIEW));
|
|
||||||
|
UiObject skipButton =
|
||||||
|
new UiObject(new UiSelector().textContains("Skip")
|
||||||
|
.className("android.widget.TextView"));
|
||||||
if (skipButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
if (skipButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
||||||
skipButton.click();
|
skipButton.click();
|
||||||
}
|
}
|
||||||
UiObject gotItButton = new UiObject(new UiSelector().textContains("Got it").className(CLASS_BUTTON));
|
|
||||||
|
UiObject gotItButton =
|
||||||
|
new UiObject(new UiSelector().textContains("Got it")
|
||||||
|
.className("android.widget.Button"));
|
||||||
if (gotItButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
if (gotItButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
||||||
gotItButton.click();
|
gotItButton.click();
|
||||||
}
|
}
|
||||||
@ -91,7 +104,8 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
clickUiObject(BY_TEXT, "General", true);
|
clickUiObject(BY_TEXT, "General", true);
|
||||||
|
|
||||||
// Don't fail fatally if autoplay toggle cannot be found
|
// Don't fail fatally if autoplay toggle cannot be found
|
||||||
UiObject autoplayToggle = new UiObject(new UiSelector().textContains("Autoplay"));
|
UiObject autoplayToggle =
|
||||||
|
new UiObject(new UiSelector().textContains("Autoplay"));
|
||||||
if (autoplayToggle.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
if (autoplayToggle.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
||||||
autoplayToggle.click();
|
autoplayToggle.click();
|
||||||
}
|
}
|
||||||
@ -99,64 +113,73 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
|
|
||||||
// Tablet devices use a split with General in the left pane and Autoplay in the right so no
|
// Tablet devices use a split with General in the left pane and Autoplay in the right so no
|
||||||
// need to click back twice
|
// need to click back twice
|
||||||
UiObject generalButton = new UiObject(new UiSelector().textContains("General").className(CLASS_TEXT_VIEW));
|
UiObject generalButton =
|
||||||
|
new UiObject(new UiSelector().textContains("General")
|
||||||
|
.className("android.widget.TextView"));
|
||||||
if (generalButton.exists()) {
|
if (generalButton.exists()) {
|
||||||
getUiDevice().pressBack();
|
getUiDevice().pressBack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPlayVideo(String source, String searchTerm) throws Exception {
|
public void testPlayVideo(String source, String searchTerm) throws Exception {
|
||||||
|
String testTag = "play";
|
||||||
|
ActionLogger logger = new ActionLogger(testTag + "_" + source, parameters);
|
||||||
|
|
||||||
if (SOURCE_SEARCH.equalsIgnoreCase(source)) {
|
if (SOURCE_SEARCH.equalsIgnoreCase(source)) {
|
||||||
clickUiObject(BY_DESC, "Search");
|
clickUiObject(BY_DESC, "Search");
|
||||||
UiObject textField = getUiObjectByResourceId(packageID + "search_edit_text");
|
UiObject textField = getUiObjectByResourceId(packageID + "search_edit_text");
|
||||||
textField.setText(searchTerm);
|
textField.setText(searchTerm);
|
||||||
getUiDevice().pressEnter();
|
getUiDevice().pressEnter();
|
||||||
|
|
||||||
startMeasurements("play_search");
|
|
||||||
// If a video exists whose title contains the exact search term, then play it
|
// If a video exists whose title contains the exact search term, then play it
|
||||||
// Otherwise click the first video in the search results
|
// Otherwise click the first video in the search results
|
||||||
UiObject thumbnail = new UiObject(new UiSelector().resourceId(packageID + "thumbnail"));
|
UiObject thumbnail =
|
||||||
UiObject matchedVideo = thumbnail.getFromParent(new UiSelector().textContains(searchTerm));
|
new UiObject(new UiSelector().resourceId(packageID + "thumbnail"));
|
||||||
|
UiObject matchedVideo =
|
||||||
|
thumbnail.getFromParent(new UiSelector().textContains(searchTerm));
|
||||||
|
|
||||||
|
logger.start();
|
||||||
if (matchedVideo.exists()) {
|
if (matchedVideo.exists()) {
|
||||||
matchedVideo.clickAndWaitForNewWindow();
|
matchedVideo.clickAndWaitForNewWindow();
|
||||||
} else {
|
} else {
|
||||||
thumbnail.clickAndWaitForNewWindow();
|
thumbnail.clickAndWaitForNewWindow();
|
||||||
}
|
}
|
||||||
endMeasurements();
|
logger.stop();
|
||||||
|
|
||||||
} else if (SOURCE_MY_VIDEOS.equalsIgnoreCase(source)) {
|
} else if (SOURCE_MY_VIDEOS.equalsIgnoreCase(source)) {
|
||||||
clickUiObject(BY_DESC, "Account");
|
clickUiObject(BY_DESC, "Account");
|
||||||
clickUiObject(BY_TEXT, "My Videos", true);
|
clickUiObject(BY_TEXT, "My Videos", true);
|
||||||
|
|
||||||
startMeasurements("play_myvideos");
|
logger.start();
|
||||||
clickUiObject(BY_ID, packageID + "thumbnail", true);
|
clickUiObject(BY_ID, packageID + "thumbnail", true);
|
||||||
endMeasurements();
|
logger.stop();
|
||||||
|
|
||||||
} else if (SOURCE_TRENDING.equalsIgnoreCase(source)) {
|
} else if (SOURCE_TRENDING.equalsIgnoreCase(source)) {
|
||||||
clickUiObject(BY_DESC, "Trending");
|
clickUiObject(BY_DESC, "Trending");
|
||||||
|
|
||||||
startMeasurements("play_trending");
|
logger.start();
|
||||||
clickUiObject(BY_ID, packageID + "thumbnail", true);
|
clickUiObject(BY_ID, packageID + "thumbnail", true);
|
||||||
endMeasurements();
|
logger.stop();
|
||||||
|
|
||||||
} else { // homepage videos
|
} else { // homepage videos
|
||||||
UiScrollable list = new UiScrollable(new UiSelector().resourceId(packageID + "results"));
|
UiScrollable list =
|
||||||
|
new UiScrollable(new UiSelector().resourceId(packageID + "results"));
|
||||||
if (list.exists()) {
|
if (list.exists()) {
|
||||||
list.scrollForward();
|
list.scrollForward();
|
||||||
}
|
}
|
||||||
startMeasurements("play_home");
|
|
||||||
clickUiObject(BY_ID, packageID + "thumbnail", true);
|
|
||||||
endMeasurements();
|
|
||||||
}
|
|
||||||
|
|
||||||
dismissAdvert();
|
logger.start();
|
||||||
checkPlayerError();
|
clickUiObject(BY_ID, packageID + "thumbnail", true);
|
||||||
pausePlayVideo();
|
logger.stop();
|
||||||
checkVideoInfo();
|
|
||||||
scrollRelated();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dismissAdvert() throws Exception {
|
public void dismissAdvert() throws Exception {
|
||||||
UiObject advert = new UiObject(new UiSelector().textContains("Visit advertiser"));
|
UiObject advert =
|
||||||
|
new UiObject(new UiSelector().textContains("Visit advertiser"));
|
||||||
if (advert.exists()) {
|
if (advert.exists()) {
|
||||||
UiObject skip = new UiObject(new UiSelector().textContains("Skip ad"));
|
UiObject skip =
|
||||||
|
new UiObject(new UiSelector().textContains("Skip ad"));
|
||||||
if (skip.waitForExists(WAIT_TIMEOUT_1SEC*5)) {
|
if (skip.waitForExists(WAIT_TIMEOUT_1SEC*5)) {
|
||||||
skip.click();
|
skip.click();
|
||||||
sleep(VIDEO_SLEEP_SECONDS);
|
sleep(VIDEO_SLEEP_SECONDS);
|
||||||
@ -165,8 +188,10 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkPlayerError() throws Exception {
|
public void checkPlayerError() throws Exception {
|
||||||
UiObject playerError = new UiObject(new UiSelector().resourceId(packageID + "player_error_view"));
|
UiObject playerError =
|
||||||
UiObject tapToRetry = new UiObject(new UiSelector().textContains("Tap to retry"));
|
new UiObject(new UiSelector().resourceId(packageID + "player_error_view"));
|
||||||
|
UiObject tapToRetry =
|
||||||
|
new UiObject(new UiSelector().textContains("Tap to retry"));
|
||||||
if (playerError.waitForExists(WAIT_TIMEOUT_1SEC) || tapToRetry.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
if (playerError.waitForExists(WAIT_TIMEOUT_1SEC) || tapToRetry.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
||||||
throw new RuntimeException("Video player encountered an error and cannot continue.");
|
throw new RuntimeException("Video player encountered an error and cannot continue.");
|
||||||
}
|
}
|
||||||
@ -182,7 +207,8 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkVideoInfo() throws Exception {
|
public void checkVideoInfo() throws Exception {
|
||||||
UiObject expandButton = new UiObject(new UiSelector().resourceId(packageID + "expand_button"));
|
UiObject expandButton =
|
||||||
|
new UiObject(new UiSelector().resourceId(packageID + "expand_button"));
|
||||||
if (!expandButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
if (!expandButton.waitForExists(WAIT_TIMEOUT_1SEC)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -193,28 +219,24 @@ public class UiAutomation extends UxPerfUiAutomation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void scrollRelated() throws Exception {
|
public void scrollRelated() throws Exception {
|
||||||
// ListView of related videos and (maybe) comments
|
String testTag = "scroll";
|
||||||
UiScrollable list = new UiScrollable(new UiSelector().resourceId(packageID + "watch_list"));
|
|
||||||
if (list.isScrollable()) {
|
|
||||||
startMeasurements("scroll_down");
|
|
||||||
list.flingToEnd(LIST_SWIPE_COUNT);
|
|
||||||
endMeasurements();
|
|
||||||
|
|
||||||
startMeasurements("scroll_up");
|
// ListView of related videos and (maybe) comments
|
||||||
|
UiScrollable list =
|
||||||
|
new UiScrollable(new UiSelector().resourceId(packageID + "watch_list"));
|
||||||
|
if (list.isScrollable()) {
|
||||||
|
ActionLogger logger = new ActionLogger(testTag + "_down", parameters);
|
||||||
|
logger.start();
|
||||||
|
list.flingToEnd(LIST_SWIPE_COUNT);
|
||||||
|
logger.stop();
|
||||||
|
|
||||||
|
logger = new ActionLogger(testTag + "_up", parameters);
|
||||||
|
logger.start();
|
||||||
list.flingToBeginning(LIST_SWIPE_COUNT);
|
list.flingToBeginning(LIST_SWIPE_COUNT);
|
||||||
endMeasurements();
|
logger.stop();
|
||||||
}
|
}
|
||||||
// After flinging, give the window enough time to settle down before
|
// After flinging, give the window enough time to settle down before
|
||||||
// the next step, or else UiAutomator fails to find views in time
|
// the next step, or else UiAutomator fails to find views in time
|
||||||
sleep(VIDEO_SLEEP_SECONDS);
|
sleep(VIDEO_SLEEP_SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startMeasurements(String testTag) throws Exception {
|
|
||||||
logger = new ActionLogger(testTag, parameters);
|
|
||||||
logger.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void endMeasurements() throws Exception {
|
|
||||||
logger.stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user