diff --git a/wlauto/workloads/appshare/__init__.py b/wlauto/workloads/appshare/__init__.py new file mode 100755 index 00000000..8ce87a5f --- /dev/null +++ b/wlauto/workloads/appshare/__init__.py @@ -0,0 +1,183 @@ +# Copyright 2014-2016 ARM Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os + +from wlauto import AndroidUxPerfWorkload, Parameter, ExtensionLoader +from wlauto import AndroidUiAutoBenchmark, UiAutomatorWorkload +from wlauto.exceptions import ValidationError + + +class AppShare(AndroidUxPerfWorkload): + + name = 'appshare' + package = [] + activity = None + view = [] + description = ''' + Workload to test how responsive a device is when context switching between + application tasks. It combines workflows from googlephotos, gmail and + skype. + + ** Setup ** + Credentials for the user account used to log into the Skype app have to be provided + in the agenda, as well as the display name of the contact to call. + + For reliable testing, this workload requires a good and stable internet connection, + preferably on Wi-Fi. + + Although this workload attempts to be network independent it requires a + network connection (ideally, wifi) to run. This is because the welcome + screen UI is dependent on an existing connection. + + Test description: + 1. GooglePhotos is started in offline access mode + 1.1. The welcome screen is dismissed + 1.2. Any promotion popup is dismissed + 1.3. The provided ``test_image`` is selected and displayed + 2. The image is then shared across apps to Gmail + 2.1. The first run dialogue is dismissed + 2.2. Enter recipient details in the To field + 2.3. Enter text in the Subject field + 2.4. Enter text in the Body field + 2.5. Click the Send mail button + 3. Return to Googlephotos and login to Skype via share action + 4. Return to Googlephotos and share the ``test_image`` with Skype + 4.1. Search for the ``skype_contact_name`` from the Contacts list + 4.2. Dismiss any update popup that appears + 4.3. The image is posted in the Chat + ''' + + parameters = [ + Parameter('test_image', kind=str, default='uxperf_1600x1200.jpg', + description=''' + An image to be copied onto the device that will be shared + across multiple apps + '''), + Parameter('email_recipient', kind=str, default='wa-devnull@mailinator.com', + description=''' + The email address of the recipient to recieve the shared image + '''), + Parameter('skype_login_name', kind=str, mandatory=True, + description=''' + Account to use when logging into skype from which to share the image + '''), + Parameter('skype_login_pass', kind=str, mandatory=True, + description=''' + Password associated with the skype account + '''), + Parameter('skype_contact_name', kind=str, default='Echo / Sound Test Service', + description=''' + This is the contact display name as it appears in the people list + '''), + ] + + # This workload relies on the internet so check that there is a working + # internet connection + requires_network = True + + def __init__(self, device, **kwargs): + super(AppShare, self).__init__(device, **kwargs) + self.deployable_assets = [self.test_image] + self.clean_assets = True + loader = ExtensionLoader() + + # Initialise googlephotos + args_googlephotos = dict(kwargs) + del args_googlephotos['test_image'] + del args_googlephotos['email_recipient'] + del args_googlephotos['skype_login_name'] + del args_googlephotos['skype_login_pass'] + del args_googlephotos['skype_contact_name'] + args_googlephotos['markers_enabled'] = False + self.wl_googlephotos = loader.get_workload('googlephotos', device, **args_googlephotos) + self.view += self.wl_googlephotos.view + self.package.append(self.wl_googlephotos.package) + + # Initialise gmail + args_gmail = dict(kwargs) + del args_gmail['test_image'] + args_gmail['recipient'] = args_gmail.pop('email_recipient') + del args_gmail['skype_login_name'] + del args_gmail['skype_login_pass'] + del args_gmail['skype_contact_name'] + args_gmail['markers_enabled'] = False + self.wl_gmail = loader.get_workload('gmail', device, **args_gmail) + self.view += self.wl_gmail.view + self.package.append(self.wl_gmail.package) + + # Initialise skype + args_skype = dict(kwargs) + del args_skype['test_image'] + del args_skype['email_recipient'] + args_skype['login_name'] = args_skype.pop('skype_login_name') + args_skype['login_pass'] = args_skype.pop('skype_login_pass') + args_skype['contact_name'] = args_skype.pop('skype_contact_name') + args_skype['markers_enabled'] = False + self.wl_skype = loader.get_workload('skype', device, **args_skype) + self.view += self.wl_skype.view + self.package.append(self.wl_skype.package) + + def validate(self): + super(AppShare, self).validate() + # Set package to None as it doesnt allow it to be a list, + # and we are not using it in the java side, only in wa itself. + self.uiauto_params['package'] = None + self.uiauto_params['googlephotos_package'] = self.wl_googlephotos.package + self.uiauto_params['gmail_package'] = self.wl_gmail.package + self.uiauto_params['skype_package'] = self.wl_skype.package + self.uiauto_params['recipient'] = self.email_recipient + self.uiauto_params['my_id'] = self.skype_login_name + self.uiauto_params['my_pwd'] = self.skype_login_pass + self.uiauto_params['name'] = self.skype_contact_name.replace(' ', '0space0') + # Only accept certain image formats + if os.path.splitext(self.test_image.lower())[1] not in ['.jpg', '.jpeg', '.png']: + raise ValidationError('{} must be a JPEG or PNG file'.format(self.test_image)) + + def setup(self, context): + self.logger.info('Checking dependency Skype') + self.wl_skype.launch_main = False + self.wl_skype.deployable_assets = [] + self.wl_skype.init_resources(context) + # Bypass running skype through intent + AndroidUxPerfWorkload.setup(self.wl_skype, context) + + self.logger.info('Checking dependency Gmail') + self.wl_gmail.launch_main = False + self.wl_gmail.deployable_assets = [] + self.wl_gmail.init_resources(context) + self.wl_gmail.setup(context) + + self.logger.info('Checking dependency Googlephotos') + self.wl_googlephotos.launch_main = True + self.wl_googlephotos.deployable_assets = [] + self.wl_googlephotos.init_resources(context) + # Bypass googlephoto's asset setup + AndroidUxPerfWorkload.setup(self.wl_googlephotos, context) + + self.logger.info('Checking dependency AppShare') + super(AppShare, self).init_resources(context) + # Only setup uiautomator side, then push assets + # This prevents the requirement that AppShare must have an APK + UiAutomatorWorkload.setup(self, context) + self.push_assets(context) + + def teardown(self, context): + self.wl_skype.teardown(context) + self.wl_gmail.teardown(context) + # Bypass googlephoto's asset teardown + AndroidUxPerfWorkload.teardown(self.wl_googlephotos, context) + + super(AppShare, self).teardown(context) diff --git a/wlauto/workloads/appshare/com.arm.wlauto.uiauto.appshare.jar b/wlauto/workloads/appshare/com.arm.wlauto.uiauto.appshare.jar new file mode 100644 index 00000000..37c39483 Binary files /dev/null and b/wlauto/workloads/appshare/com.arm.wlauto.uiauto.appshare.jar differ diff --git a/wlauto/workloads/appshare/uiauto/build.sh b/wlauto/workloads/appshare/uiauto/build.sh new file mode 100755 index 00000000..aefd6ede --- /dev/null +++ b/wlauto/workloads/appshare/uiauto/build.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# CD into build dir if possible - allows building from any directory +script_path='.' +if `readlink -f $0 &>/dev/null`; then + script_path=`readlink -f $0 2>/dev/null` +fi +script_dir=`dirname $script_path` +cd $script_dir + +# Ensure build.xml exists before starting +if [[ ! -f build.xml ]]; then + echo 'Ant build.xml file not found! Check that you are in the right directory.' + exit 9 +fi + +# Copy base classes from wlauto dist +class_dir=bin/classes/com/arm/wlauto/uiauto +base_classes=`python -c "import os, wlauto; print os.path.join(os.path.dirname(wlauto.__file__), 'common', 'android', '*.class')"` +mkdir -p $class_dir +cp $base_classes $class_dir + +# Add appshare workload dependencies +apps=("googlephotos" "gmail" "skype") + +for app in "${apps[@]}"; do + module_path="wlauto.workloads.${app}" + app_path="'uiauto/bin/classes/com/arm/wlauto/uiauto/${app}'" + app_class_dir=`python -c "import os, ${module_path}; print os.path.join(os.path.dirname(${module_path}.__file__), ${app_path})"` + cp -r $app_class_dir $class_dir +done + +# 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 + +# If successful move JAR file to workload folder (overwrite previous) +package=com.arm.wlauto.uiauto.appshare.jar +rm -f ../$package +if [[ -f bin/$package ]]; then + cp bin/$package .. +else + echo 'ERROR: UiAutomator JAR could not be found!' + exit 9 +fi diff --git a/wlauto/workloads/appshare/uiauto/build.xml b/wlauto/workloads/appshare/uiauto/build.xml new file mode 100644 index 00000000..bc9858a3 --- /dev/null +++ b/wlauto/workloads/appshare/uiauto/build.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wlauto/workloads/appshare/uiauto/project.properties b/wlauto/workloads/appshare/uiauto/project.properties new file mode 100644 index 00000000..ce39f2d0 --- /dev/null +++ b/wlauto/workloads/appshare/uiauto/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-18 diff --git a/wlauto/workloads/appshare/uiauto/src/com/arm/wlauto/uiauto/UiAutomation.java b/wlauto/workloads/appshare/uiauto/src/com/arm/wlauto/uiauto/UiAutomation.java new file mode 100755 index 00000000..6316abb3 --- /dev/null +++ b/wlauto/workloads/appshare/uiauto/src/com/arm/wlauto/uiauto/UiAutomation.java @@ -0,0 +1,143 @@ +package com.arm.wlauto.uiauto.appshare; + +import android.os.Bundle; + +// Import the uiautomator libraries +import com.android.uiautomator.core.UiObject; +import com.android.uiautomator.core.UiScrollable; +import com.android.uiautomator.core.UiSelector; + +import com.arm.wlauto.uiauto.UxPerfUiAutomation; + +import static com.arm.wlauto.uiauto.BaseUiAutomation.FindByCriteria.BY_ID; +import static com.arm.wlauto.uiauto.BaseUiAutomation.FindByCriteria.BY_TEXT; +import static com.arm.wlauto.uiauto.BaseUiAutomation.FindByCriteria.BY_DESC; + +import java.util.concurrent.TimeUnit; + +public class UiAutomation extends UxPerfUiAutomation { + + // Create UIAutomation objects + private com.arm.wlauto.uiauto.googlephotos.UiAutomation googlephotos = + new com.arm.wlauto.uiauto.googlephotos.UiAutomation(); + + private com.arm.wlauto.uiauto.gmail.UiAutomation gmail = + new com.arm.wlauto.uiauto.gmail.UiAutomation(); + + private com.arm.wlauto.uiauto.skype.UiAutomation skype = + new com.arm.wlauto.uiauto.skype.UiAutomation(); + + public Bundle parameters; + + public void runUiAutomation() throws Exception { + // Override superclass value + this.uiAutoTimeout = TimeUnit.SECONDS.toMillis(10); + + parameters = getParams(); + + // Setup the three uiautomator classes with the correct information + // Also create a dummy parameter to disable marker api as they + // should not log actions themselves. + Bundle dummyParams = new Bundle(); + dummyParams.putString("markers_enabled", "false"); + googlephotos.parameters = dummyParams; + googlephotos.packageName = parameters.getString("googlephotos_package"); + googlephotos.packageID = googlephotos.packageName + ":id/"; + gmail.parameters = dummyParams; + gmail.packageName = parameters.getString("gmail_package"); + gmail.packageID = gmail.packageName + ":id/"; + skype.parameters = dummyParams; + skype.packageName = parameters.getString("skype_package"); + skype.packageID = skype.packageName + ":id/"; + + String recipient = parameters.getString("recipient"); + String loginName = parameters.getString("my_id"); + String loginPass = parameters.getString("my_pwd"); + String contactName = parameters.getString("name").replace("0space0", " "); + + setScreenOrientation(ScreenOrientation.NATURAL); + + setupGooglePhotos(); + sendToGmail(recipient); + logIntoSkype(loginName, loginPass); + // Skype won't allow us to login and share on first visit so invoke + // once more from googlephotos + pressBack(); + pressBack(); + sendToSkype(contactName); + + unsetScreenOrientation(); + } + + private void setupGooglePhotos() throws Exception { + googlephotos.dismissWelcomeView(); + googlephotos.closePromotionPopUp(); + selectGalleryFolder("wa-working"); + googlephotos.selectFirstImage(); + } + + private void sendToGmail(String recipient) throws Exception { + String gID = gmail.packageID; + + shareUsingApp("Gmail", "gmail"); + + gmail.clearFirstRunDialogues(); + + UiObject composeView = + new UiObject(new UiSelector().resourceId(gID + "compose")); + if (!composeView.waitForExists(uiAutoTimeout)) { + // After the initial share request on some devices Gmail returns back + // to the launching app, so we need to share the photo once more and + // wait for Gmail to sync. + shareUsingApp("Gmail", "gmail_retry"); + + gmail.clearFirstRunDialogues(); + } + + gmail.setToField(recipient); + gmail.setSubjectField(); + gmail.setComposeField(); + gmail.clickSendButton(); + } + + private void logIntoSkype(String loginName, String loginPass) throws Exception { + shareUsingApp("Skype", "skype_setup"); + + skype.handleLoginScreen(loginName, loginPass); + + sleep(10); // Pause while the app settles before returning + } + + private void sendToSkype(String contactName) throws Exception { + shareUsingApp("Skype", "skype"); + + skype.searchForContact(contactName); + skype.dismissUpdatePopupIfPresent(); + + sleep(10); // Pause while the app settles before returning + } + + private void shareUsingApp(String appName, String tagName) throws Exception { + String testTag = "share"; + ActionLogger logger = new ActionLogger(testTag + "_" + tagName, parameters); + + clickUiObject(BY_DESC, "Share", "android.widget.ImageView"); + UiScrollable applicationGrid = + new UiScrollable(new UiSelector().resourceId(googlephotos.packageID + "application_grid")); + UiObject openApp = + new UiObject(new UiSelector().text(appName) + .className("android.widget.TextView")); + // On some devices the application_grid has many entries, se we have to swipe up to make + // sure all the entries are visable. This will also stop entries at the bottom being + // obscured by the bottom action bar. + applicationGrid.swipeUp(10); + while (!openApp.exists()) { + // In the rare case the grid is larger than the screen swipe up + applicationGrid.swipeUp(10); + } + + logger.start(); + openApp.clickAndWaitForNewWindow(); + logger.stop(); + } +}