From 7eaedea1d7ac9a4103c616a85351599a290df37f Mon Sep 17 00:00:00 2001 From: Kevin Jin Date: Thu, 30 Oct 2014 17:45:01 -0700 Subject: add manualtest for DroidDriver It's a convenient way to reproduce and debug failures without the dependency on real apps. Change-Id: Ib8d84b5f2c501e04cf95205c3943d0baf56346ef --- manualtest/.classpath | 10 ++++ manualtest/.project | 33 ++++++++++++ manualtest/Android.mk | 18 +++++++ manualtest/AndroidManifest.xml | 19 +++++++ manualtest/BUILD | 63 ++++++++++++++++++++++ manualtest/project.properties | 14 +++++ manualtest/res/.README.txt | 2 + .../android/droiddriver/manualtest/ManualTest.java | 45 ++++++++++++++++ 8 files changed, 204 insertions(+) create mode 100644 manualtest/.classpath create mode 100644 manualtest/.project create mode 100644 manualtest/Android.mk create mode 100644 manualtest/AndroidManifest.xml create mode 100644 manualtest/BUILD create mode 100644 manualtest/project.properties create mode 100644 manualtest/res/.README.txt create mode 100644 manualtest/src/com/google/android/droiddriver/manualtest/ManualTest.java (limited to 'manualtest') diff --git a/manualtest/.classpath b/manualtest/.classpath new file mode 100644 index 0000000..fe82c97 --- /dev/null +++ b/manualtest/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/manualtest/.project b/manualtest/.project new file mode 100644 index 0000000..8c53fde --- /dev/null +++ b/manualtest/.project @@ -0,0 +1,33 @@ + + + ManualDD + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/manualtest/Android.mk b/manualtest/Android.mk new file mode 100644 index 0000000..57f9bb2 --- /dev/null +++ b/manualtest/Android.mk @@ -0,0 +1,18 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) +LOCAL_PACKAGE_NAME := ManualDD + +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := \ + $(call all-java-files-under, src) + +LOCAL_STATIC_JAVA_LIBRARIES := \ + droiddriver + +LOCAL_INSTRUMENTATION_FOR := ManualDD + +LOCAL_SDK_VERSION := 19 + +include $(BUILD_PACKAGE) + diff --git a/manualtest/AndroidManifest.xml b/manualtest/AndroidManifest.xml new file mode 100644 index 0000000..702627e --- /dev/null +++ b/manualtest/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/manualtest/BUILD b/manualtest/BUILD new file mode 100644 index 0000000..8c5411e --- /dev/null +++ b/manualtest/BUILD @@ -0,0 +1,63 @@ +# +# Description: +# Tests for DroidDriver test framework + +licenses(["notice"]) # Apache License 2.0, Google-owned + +filegroup( + name = "opensource_filegroup", + srcs = glob(["src/**/*.java"]) + ["AndroidManifest.xml"], + visibility = ["//third_party/java_src/android_libs/droiddriver/opensource:__pkg__"], +) + +android_resources( + name = "resources", + custom_package = "com.google.android.apps.common.testing.ui.testapp.tests", + inline_constants = 0, + manifest = "AndroidManifest.xml", + resources = glob(["res/**"]), + resources_dir = "res", +) + +android_library( + name = "resource_compiletime", + srcs = [":resources"], + neverlink = 1, +) + +# Common android test library, containing: +# project under test library and resources compile-time targets, and +# test project dependencies. +android_library( + name = "test_lib", + srcs = [":resources"], + resources = ":resources", + deps = [ + "//third_party/java/android_libs/droiddriver", + "//third_party/java_src/android_libs/droiddriver/samples/testapp:test_lib", + ], +) + +android_test( + name = "LocalAttachedTests", + size = "medium", + srcs = glob( + ["src/**/*.java"], + ), + args = [ + "--device_broker_type=LOCAL_ADB_SERVER", + ], + resources = ":resources", + shard_count = 1, + tags = [ + "local", + "manual", + "notap", + ], + # unused - actually we used whatever we're attached to. + target_devices = ["//tools/android/emulated_devices/generic_phone:android_7_arm"], + deps = [ + ":test_lib", + "//third_party/java_src/android_libs/droiddriver/samples/testapp", + ], +) diff --git a/manualtest/project.properties b/manualtest/project.properties new file mode 100644 index 0000000..4ab1256 --- /dev/null +++ b/manualtest/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-19 diff --git a/manualtest/res/.README.txt b/manualtest/res/.README.txt new file mode 100644 index 0000000..912f51b --- /dev/null +++ b/manualtest/res/.README.txt @@ -0,0 +1,2 @@ +This file keeps eclipse happy as it doesn't seem able to create the res folder it doesn't actually need. It can be removed if the res folder ever gets real content. +Starting the file with a dot keeps aapt (res compiler) happy. diff --git a/manualtest/src/com/google/android/droiddriver/manualtest/ManualTest.java b/manualtest/src/com/google/android/droiddriver/manualtest/ManualTest.java new file mode 100644 index 0000000..e7e16ce --- /dev/null +++ b/manualtest/src/com/google/android/droiddriver/manualtest/ManualTest.java @@ -0,0 +1,45 @@ +package com.google.android.droiddriver.manualtest; + +import android.app.Activity; + +import com.google.android.droiddriver.actions.TextAction; +import com.google.android.droiddriver.finders.By; +import com.google.android.droiddriver.finders.Finder; +import com.google.android.droiddriver.helpers.BaseDroidDriverTest; +import com.google.android.droiddriver.helpers.DroidDrivers; + +/** + * This is for manually testing DroidDriver. It is not meant for continuous + * testing. Instead it is used for debugging failures. It assumes the device is + * in a condition that is ready to reproduce a failure. For example, + * {@link #testSetTextForPassword} assumes the password_edit field is displayed + * on screen. + *

+ * Run it as (optionally with -e debug true) + * + *

+ * adb shell am instrument -w com.google.android.droiddriver.manualtest/com.google.android.droiddriver.runner.TestRunner
+ * 
+ */ +public class ManualTest extends BaseDroidDriverTest { + public ManualTest() { + super(Activity.class); + } + + public void testSetTextForPassword() { + Finder password_edit = By.resourceId("com.google.android.gsf.login:id/password_edit"); + driver.on(password_edit).perform( + new TextAction("A fake password that is not empty and needs to be cleared by setText")); + String password = "1"; + driver.on(password_edit).setText(password); + // This won't work because password_edit does not reveal text to + // Accessibility service. But you can see the length changed on screen. + // assertEquals(password, driver.on(password_edit).getText()); + assertEquals(null, driver.on(password_edit).getText()); + } + + @Override + protected final void classSetUp() { + DroidDrivers.init(DroidDrivers.newDriver(getInstrumentation())); + } +} -- cgit v1.2.3