1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-06 19:01:15 +01:00

Merge pull request #257 from jimboatarm/gmail-workload

Gmail: A workload to perform standard productivity tasks within Gmail
This commit is contained in:
setrofim 2016-12-01 14:46:12 +00:00 committed by GitHub
commit ace41d10a5
9 changed files with 470 additions and 0 deletions

2
wlauto/common/android/workload.py Normal file → Executable file
View File

@ -621,10 +621,12 @@ class AndroidUxPerfWorkload(AndroidUiAutoBenchmark):
device_path = self._path_on_device(fpath)
if self.force_push_assets or not self.device.file_exists(device_path):
self.device.push_file(fpath, device_path, timeout=300)
self.device.broadcast_media_mounted(self.device.working_directory)
def delete_assets(self):
for f in self.deployable_assets:
self.device.delete_file(self._path_on_device(f))
self.device.broadcast_media_mounted(self.device.working_directory)
def __init__(self, device, **kwargs):
super(AndroidUxPerfWorkload, self).__init__(device, **kwargs)

View File

@ -574,4 +574,45 @@ public class BaseUiAutomation extends UiAutomatorTestCase {
}
return object;
}
// Helper to select a folder in the gallery
public void selectGalleryFolder(String directory) throws Exception {
UiObject workdir =
new UiObject(new UiSelector().text(directory)
.className("android.widget.TextView"));
UiScrollable scrollView =
new UiScrollable(new UiSelector().scrollable(true));
// If the folder is not present wait for a short time for
// the media server to refresh its index.
boolean discovered = workdir.waitForExists(TimeUnit.SECONDS.toMillis(10));
if (!discovered && scrollView.exists()) {
// First check if the directory is visible on the first
// screen and if not scroll to the bottom of the screen to look for it.
discovered = scrollView.scrollIntoView(workdir);
// If still not discovered scroll back to the top of the screen and
// wait for a longer amount of time for the media server to refresh
// its index.
if (!discovered) {
// scrollView.scrollToBeggining() doesn't work for this
// particular scrollable view so use device method instead
for (int i = 0; i < 10; i++) {
uiDeviceSwipeUp(20);
}
discovered = workdir.waitForExists(TimeUnit.SECONDS.toMillis(60));
// Scroll to the bottom of the screen one last time
if (!discovered) {
discovered = scrollView.scrollIntoView(workdir);
}
}
}
if (discovered) {
workdir.clickAndWaitForNewWindow();
} else {
throw new UiObjectNotFoundException("Could not find folder : " + directory);
}
}
}

View File

@ -0,0 +1,71 @@
# 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
from wlauto.exceptions import ValidationError
class Gmail(AndroidUxPerfWorkload):
name = 'gmail'
package = 'com.google.android.gm'
min_apk_version = '6.7.128801648'
activity = ''
view = [package + '/com.google.android.gm.ConversationListActivityGmail',
package + '/com.google.android.gm.ComposeActivityGmail']
description = '''
A workload to perform standard productivity tasks within Gmail. The workload carries out
various tasks, such as creating new emails, attaching images and sending them.
Test description:
1. Open Gmail application
2. Click to create New mail
3. Attach an image from the local images folder to the email
4. Enter recipient details in the To field
5. Enter text in the Subject field
6. Enter text in the Compose field
7. Click the Send mail button
'''
parameters = [
Parameter('recipient', kind=str, default='wa-devnull@mailinator.com',
description='''
The email address of the recipient. Setting a void address
will stop any mesage failures clogging up your device inbox
'''),
Parameter('test_image', kind=str, default='uxperf_1600x1200.jpg',
description='''
An image to be copied onto the device that will be attached
to the email
'''),
]
# This workload relies on the internet so check that there is a working
# internet connection
requires_network = True
def __init__(self, device, **kwargs):
super(Gmail, self).__init__(device, **kwargs)
self.deployable_assets = [self.test_image]
self.clean_assets = True
def validate(self):
super(Gmail, self).validate()
self.uiauto_params['recipient'] = self.recipient
# 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))

Binary file not shown.

View File

@ -0,0 +1,39 @@
#!/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
# 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.gmail.jar
rm -f ../$package
if [[ -f bin/$package ]]; then
cp bin/$package ..
else
echo 'ERROR: UiAutomator JAR could not be found!'
exit 9
fi

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="com.arm.wlauto.uiauto.gmail" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: VERSION_TAG -->
<import file="${sdk.dir}/tools/ant/uibuild.xml" />
</project>

View File

@ -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

View File

@ -0,0 +1,211 @@
/* 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.
*/
package com.arm.wlauto.uiauto.gmail;
import android.os.Bundle;
// Import the uiautomator libraries
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.arm.wlauto.uiauto.UxPerfUiAutomation;
import java.util.concurrent.TimeUnit;
public class UiAutomation extends UxPerfUiAutomation {
public Bundle parameters;
public String packageName;
public String packageID;
private int networkTimeoutSecs = 30;
private long networkTimeout = TimeUnit.SECONDS.toMillis(networkTimeoutSecs);
public void runUiAutomation() throws Exception {
parameters = getParams();
packageName = parameters.getString("package");
packageID = packageName + ":id/";
String recipient = parameters.getString("recipient");
setScreenOrientation(ScreenOrientation.NATURAL);
clearFirstRunDialogues();
clickNewMail();
attachImage();
setToField(recipient);
setSubjectField();
setComposeField();
clickSendButton();
unsetScreenOrientation();
}
public void clearFirstRunDialogues() throws Exception {
// The first run dialogues vary on different devices so check if they are there and dismiss
UiObject gotItBox =
new UiObject(new UiSelector().resourceId(packageID + "welcome_tour_got_it")
.className("android.widget.TextView"));
if (gotItBox.exists()) {
gotItBox.clickAndWaitForNewWindow(uiAutoTimeout);
}
UiObject takeMeToBox =
new UiObject(new UiSelector().textContains("Take me to Gmail")
.className("android.widget.TextView"));
if (takeMeToBox.exists()) {
takeMeToBox.clickAndWaitForNewWindow(uiAutoTimeout);
}
UiObject syncNowButton =
new UiObject(new UiSelector().textContains("Sync now")
.className("android.widget.Button"));
if (syncNowButton.exists()) {
syncNowButton.clickAndWaitForNewWindow(uiAutoTimeout);
// On some devices we need to wait for a sync to occur after clearing the data
// We also need to sleep here since waiting for a new window is not enough
sleep(10);
}
// Wait an obnoxiously long period of time for the sync operation to finish
// If it still fails, then there is a problem with the app obtaining the data it needs
// Recommend restarting the phone and/or clearing the app data
UiObject gettingMessages =
new UiObject(new UiSelector().textContains("Getting your messages")
.className("android.widget.TextView"));
UiObject waitingSync =
new UiObject(new UiSelector().textContains("Waiting for sync")
.className("android.widget.TextView"));
if (!waitUntilNoObject(gettingMessages, networkTimeoutSecs*4) ||
!waitUntilNoObject(waitingSync, networkTimeoutSecs*4)) {
throw new UiObjectNotFoundException("Device cannot sync! Try rebooting or clearing app data");
}
}
public void clickNewMail() throws Exception {
String testTag = "click_new";
ActionLogger logger = new ActionLogger(testTag, parameters);
UiObject conversationView =
new UiObject(new UiSelector().resourceId(packageID + "conversation_list_view")
.className("android.widget.ListView"));
if (!conversationView.waitForExists(networkTimeout)) {
throw new UiObjectNotFoundException("Could not find \"conversationView\".");
}
UiObject newMailButton =
getUiObjectByDescription("Compose", "android.widget.ImageButton");
logger.start();
newMailButton.clickAndWaitForNewWindow(uiAutoTimeout);
logger.stop();
}
public void attachImage() throws Exception {
String testTag = "attach_img";
ActionLogger logger = new ActionLogger(testTag, parameters);
UiObject attachIcon =
getUiObjectByResourceId(packageID + "add_attachment", "android.widget.TextView");
logger.start();
attachIcon.click();
UiObject attachFile =
getUiObjectByText("Attach file", "android.widget.TextView");
attachFile.clickAndWaitForNewWindow(uiAutoTimeout);
UiObject waFolder =
new UiObject(new UiSelector().textContains("wa-working")
.className("android.widget.TextView"));
// Some devices use a FrameLayout as oppoised to a view Group so treat them differently
if (!waFolder.waitForExists(uiAutoTimeout)) {
UiObject rootMenu =
new UiObject(new UiSelector().descriptionContains("Show roots")
.className("android.widget.ImageButton"));
// Portrait devices will roll the menu up so click the root menu icon
if (rootMenu.exists()) {
rootMenu.click();
}
UiObject imagesEntry =
new UiObject(new UiSelector().textContains("Images")
.className("android.widget.TextView"));
// Go to the 'Images' section
if (imagesEntry.waitForExists(uiAutoTimeout)) {
imagesEntry.click();
}
// Find and select the folder
selectGalleryFolder("wa-working");
}
UiObject imageFileButton =
new UiObject(new UiSelector().resourceId("com.android.documentsui:id/grid")
.className("android.widget.GridView")
.childSelector(new UiSelector().index(0)
.className("android.widget.FrameLayout")));
imageFileButton.click();
imageFileButton.waitUntilGone(uiAutoTimeout);
logger.stop();
}
public void setToField(String recipient) throws Exception {
String testTag = "text_to";
ActionLogger logger = new ActionLogger(testTag, parameters);
UiObject toField = getUiObjectByText("To", "android.widget.TextView");
logger.start();
toField.setText(recipient);
getUiDevice().getInstance().pressEnter();
logger.stop();
}
public void setSubjectField() throws Exception {
String testTag = "text_subject";
ActionLogger logger = new ActionLogger(testTag, parameters);
UiObject subjectField = getUiObjectByText("Subject", "android.widget.EditText");
logger.start();
// Click on the subject field is required on some platforms to exit the To box cleanly
subjectField.click();
subjectField.setText("This is a test message");
getUiDevice().getInstance().pressEnter();
logger.stop();
}
public void setComposeField() throws Exception {
String testTag = "text_body";
ActionLogger logger = new ActionLogger(testTag, parameters);
UiObject composeField = getUiObjectByText("Compose email", "android.widget.EditText");
logger.start();
composeField.setText("This is a test composition");
getUiDevice().getInstance().pressEnter();
logger.stop();
}
public void clickSendButton() throws Exception {
String testTag = "click_send";
ActionLogger logger = new ActionLogger(testTag, parameters);
UiObject sendButton = getUiObjectByDescription("Send", "android.widget.TextView");
logger.start();
sendButton.clickAndWaitForNewWindow(uiAutoTimeout);
logger.stop();
sendButton.waitUntilGone(networkTimeoutSecs);
}
}