From 8ec549a54c87afebf857bac74de2d1340b5dccc7 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 26 Apr 2017 17:17:22 -0700 Subject: Add directory containing playstore system images. This change will allow the script to download and unzip playstore system images to folder with tag google_apis_playstore. TEST: local BUG: b/37355517 Change-Id: Icaa8a31d571dead18d7787535dcd30ba52e70241 --- emu_test/utils/download_unzip_image.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/emu_test/utils/download_unzip_image.py b/emu_test/utils/download_unzip_image.py index e96491f9..feb8748a 100644 --- a/emu_test/utils/download_unzip_image.py +++ b/emu_test/utils/download_unzip_image.py @@ -17,10 +17,13 @@ args = parser.parse_args() def get_dst_dir(remote_path): file_name = os.path.basename(remote_path) emulator_branches = ["emu-master-dev", "emu-2.0-release", "emu-2.2-release", "emu-2.3-release"] + # sdk_google_phone contains the playstore system images. if file_name.startswith('sdk-repo-linux-system-images') or file_name.startswith('sdk-repo-linux-addon') \ - or file_name.startswith('sdk-repo-darwin-system-images'): + or file_name.startswith('sdk-repo-darwin-system-images') or file_name.startswith('sdk_google_phone'): branch_name = remote_path.split('/')[-4] - if 'google' in branch_name and 'addon' in branch_name: + if 'user' in branch_name: + tag = 'google_apis_playstore' + elif 'google' in branch_name and 'addon' in branch_name: tag = 'google_apis' elif 'google_atv' in branch_name: tag = 'android-tv' -- cgit v1.2.3 From 41fc85c5bf5fab6a0563310b61e8a94ef03c183b Mon Sep 17 00:00:00 2001 From: David Date: Mon, 1 May 2017 13:43:58 -0700 Subject: Remove avd flag to run test without flag. There is an existing api that creates the avd by default. Removing flag as it's not needed. TEST: locally. Change-Id: Ic92feda1029a684fde7d47f7ce6461317786ff4d --- emu_test/test_avd/launch_avd.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/emu_test/test_avd/launch_avd.py b/emu_test/test_avd/launch_avd.py index 75aa79c0..b3337924 100644 --- a/emu_test/test_avd/launch_avd.py +++ b/emu_test/test_avd/launch_avd.py @@ -18,6 +18,8 @@ import unittest import util +from emu_test.utils.emu_testcase import EmuBaseTestCase, AVDConfig + log = logging.getLogger('launch_avd') def arg_parser(): @@ -27,9 +29,6 @@ def arg_parser(): parser.add_argument('-t', '--timeout', type=int, dest='timeout_in_seconds', action='store', default=600, help='an integer for timeout in seconds, default is 600') - parser.add_argument('--avd', type=str, dest='avd', action='store', - required=True, - help='run test for given AVD') parser.add_argument('--exec', type=str, dest='emulator_exec', action='store', default='emulator', help='path of emulator executable, default is system emulator') @@ -37,8 +36,7 @@ def arg_parser(): return parser class TimeoutError(Exception): - """Exception raised for timeout - + """Exception raised for timeout. Attributes: cmd -- cmd which timed out timeout -- value of timeout @@ -49,12 +47,10 @@ class TimeoutError(Exception): self.timeout = timeout def run_with_timeout(cmd, timeout): - """Run command with specified timeout. - + """Run command with specified timeout. Args: cmd - Required : command to run - timeout - Required : timeout (in seconds) - + timeout - Required : timeout (in seconds) Returns: Tuple of form (returncode, output, err), where: * returncode is the exit code of the command @@ -145,11 +141,12 @@ def launch_emu_and_wait(avd, emu_args): return success -class LaunchAVDTest(unittest.TestCase): - def test_launch_avd(self): +class LaunchAVDTest(EmuBaseTestCase): + def test_launch_avd(self, avd_config): + self.avd_config = avd_config + self.assertEqual(self.create_avd(avd_config), 0) args = arg_parser().parse_args() - avd = args.avd - return launch_emu_and_wait(avd, args) + return launch_emu_and_wait(avd_config, args) if __name__ == '__main__': console_handler = logging.StreamHandler(sys.stdout) @@ -157,4 +154,4 @@ if __name__ == '__main__': log.addHandler(console_handler) log.setLevel(logging.DEBUG) suite = unittest.TestLoader().loadTestsFromTestCase(LaunchAVDTest) - unittest.TextTestRunner(verbosity=2).run(suite) + unittest.TextTestRunner(verbosity=2).run(suite) \ No newline at end of file -- cgit v1.2.3 From 168b10612428c54476a161b0ca24da81a3f8a714 Mon Sep 17 00:00:00 2001 From: Jim Kaye Date: Mon, 1 May 2017 10:51:49 -0700 Subject: Update expected response to console 'help' command The emulator added two commands: help-verbose and ping. Update the expected response to 'help' to include the new commands. Add tests for 'help-verbose'. Add a test for the 'ping' command. Change-Id: I18657acb22d9c1fc163574d7a7d051110b1c7d3a --- emu_test/test_console/testcase_help.py | 18 +++++++++ emu_test/test_console/testcase_ping.py | 72 ++++++++++++++++++++++++++++++++++ emu_test/test_console/utils/util.py | 21 +++++++--- 3 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 emu_test/test_console/testcase_ping.py diff --git a/emu_test/test_console/testcase_help.py b/emu_test/test_console/testcase_help.py index 18e2f516..56ac6aed 100644 --- a/emu_test/test_console/testcase_help.py +++ b/emu_test/test_console/testcase_help.py @@ -40,6 +40,20 @@ class HelpTest(testcase_base.BaseConsoleTest): 'Failed to properly list all command options.', False, '', 'Pattern: \n%s' % expected_output, output) + def _help_verbose_command(self, expected_output): + """Executes help-verbose command and verifies output. + + Args: + expected_output: Expected console output for help-vebose command. + """ + is_command_successful, output = util.execute_console_command( + self.telnet, util.CMD_HELP_VERBOSE, expected_output) + + self.assert_cmd_successful( + is_command_successful, + 'Failed to properly list all command options.', + False, '', 'Pattern: \n%s' % expected_output, output) + def _auth_user_for_emulator_console(self): """Authorization user.""" auth_token = util.get_auth_token() @@ -68,8 +82,12 @@ class HelpTest(testcase_base.BaseConsoleTest): """ print 'Running test: %s' % (inspect.stack()[0][3]) self._help_command(util.REGEX_HELP_DISPLAY_NO_AUTH) + self._help_verbose_command(util.REGEX_HELP_VERBOSE_DISPLAY_NO_AUTH) + self._auth_user_for_emulator_console() + self._help_command(util.REGEX_HELP_DISPLAY_AUTH) + self._help_verbose_command(util.REGEX_HELP_VERBOSE_DISPLAY_AUTH) if __name__ == '__main__': diff --git a/emu_test/test_console/testcase_ping.py b/emu_test/test_console/testcase_ping.py new file mode 100644 index 00000000..322adb71 --- /dev/null +++ b/emu_test/test_console/testcase_ping.py @@ -0,0 +1,72 @@ +"""Tests for the ping command.""" + +import inspect +import time +import unittest + +import testcase_base +from utils import util + +CMD_PING = 'ping\n' +PING_RESPONSE = 'I am alive!.*\nOK' + + + +class PingTest(testcase_base.BaseConsoleTest): + """Tests for the ping command.""" + + def __init__(self, method_name=None, avd=None): + if method_name: + super(PingTest, self).__init__(method_name) + else: + super(PingTest, self).__init__() + self.avd = avd + + def _execute_command_and_verify(self, command, expected_output, assert_msg): + """Executes console command and verify output. + + Args: + command: Console command to be executed. + expected_output: Expected console output. + assert_msg: Assertion message. + """ + is_command_successful, output = util.execute_console_command( + self.telnet, command, expected_output) + + self.assert_cmd_successful(is_command_successful, assert_msg, False, '', + 'Pattern:\n%s' % expected_output, output) + + def _auth_user_for_emulator_console(self): + """Authorize user.""" + auth_token = util.get_auth_token() + self.telnet = util.telnet_emulator() + self.telnet.write('%s %s\n' % (util.AUTH, auth_token)) + util.wait_on_windows() + if (not util.check_read_until( + self.telnet.read_until(util.OK, util.TIMEOUT_S))): + sys.exit(-1) + + def test_ping(self): + """Test for command: ping + + Test Rail ID: ? + Test steps: + 1. Launch an emulator avd + 2. From command prompt, run: ping + 3. Verify 1 + 4. Copy the auth_token value from ~/.emulator_console_auth_token + 5. Run: auth auth_token + 6. Run: ping + 7. Verify 1 + Verify: + 1. The ping response is displayed + """ + print 'Running test: %s' % (inspect.stack()[0][3]) + assert_msg = 'Failed to properly display the ping response.' + self._execute_command_and_verify(CMD_PING, PING_RESPONSE, assert_msg) + self._auth_user_for_emulator_console() + self._execute_command_and_verify(CMD_PING, PING_RESPONSE, assert_msg) + +if __name__ == '__main__': + print '======= Ping Test =======' + unittest.main() diff --git a/emu_test/test_console/utils/util.py b/emu_test/test_console/utils/util.py index 79495bf9..8efa0fdd 100644 --- a/emu_test/test_console/utils/util.py +++ b/emu_test/test_console/utils/util.py @@ -56,14 +56,25 @@ EVENTS_EV_TYPES_FILENAME = os.path.join(EVENT_DIR, 'EVENTS_EV_TYPES') PORT_NO_REDIR = 'no active redirections\r\nOK' PORT_REDIR_ADD = 'tcp:5556 => 5554 \r\nOK' CMD_HELP = 'help\n' -REGEX_HELP_DISPLAY_NO_AUTH = (r'.*\n.*\n.*help.*\n.*avd.*\n.*auth.*\n' - r'.*quit\|exit.*\n.*\n.*\nOK') -REGEX_HELP_DISPLAY_AUTH = (r'.*\n.*\n.*help.*\n.*event.*\n.*geo.*\n.*gsm.*\n' - r'.*cdma.*\n.*crash.*\n.*crash-on-exit.*\n' +REGEX_HELP_DISPLAY_NO_AUTH = (r'.*\n.*help.*\n.*help-verbose.*\n.*ping.*\n' + r'.*avd.*\n.*auth.*\n.*quit\|exit.*\n.*\n.*\n.*\nOK') +REGEX_HELP_DISPLAY_AUTH = (r'.*\n.*help.*\n.*help-verbose.*\n.*ping.*\n.*event.*\n' + r'.*geo.*\n.*gsm.*\n.*cdma.*\n.*crash.*\n.*crash-on-exit.*\n' r'.*kill.*\n.*network.*\n' r'.*power.*\n.*quit\|exit.*\n.*redir.*\n' r'.*sms.*\n.*avd.*\n.*qemu.*\n.*sensor.*\n.' - r'*finger.*\n.*debug.*\n.*rotate.*\n.*\n.*\nOK') + r'*finger.*\n.*debug.*\n.*rotate.*\n.*\n.*\n.*\nOK') +CMD_HELP_VERBOSE = 'help-verbose\n' +REGEX_HELP_VERBOSE_DISPLAY_NO_AUTH = ( + r'.*\n.*\n.*help.*\n.*help-verbose.*\n.*ping.*\n' + r'.*avd.*\n.*auth.*\n.*quit\|exit.*\n.*\n.*\nOK') +REGEX_HELP_VERBOSE_DISPLAY_AUTH = ( + r'.*\n.*\n.*help.*\n.*help-verbose.*\n.*ping.*\n.*event.*\n' + r'.*geo.*\n.*gsm.*\n.*cdma.*\n.*crash.*\n.*crash-on-exit.*\n' + r'.*kill.*\n.*network.*\n' + r'.*power.*\n.*quit\|exit.*\n.*redir.*\n' + r'.*sms.*\n.*avd.*\n.*qemu.*\n.*sensor.*\n.' + r'*finger.*\n.*debug.*\n.*rotate.*\n.*\n.*\nOK') AUTH = 'auth' CMD_RANDOM_AUTH_TOKEN = '%s axxB123cc\n' % AUTH CMD_EMPTY_AUTH_TOKEN = '%s \n' % AUTH -- cgit v1.2.3 From a663e8a589ff590b2a378b1965764a8c77adcd6f Mon Sep 17 00:00:00 2001 From: David Date: Mon, 1 May 2017 17:37:18 -0700 Subject: Add two system image UI tests for Play Store. Add test to install a app and launch from the play store. Add test to verify payment prompt when installing a paid app in play store. TEST: local Change-Id: If97395104792ed60ad677da0e9be1bb60cf0b3b4 --- .../systemimage/uitest/smoke/PlayStoreTest.java | 124 ++++++++++++++++++++- .../watchers/PlayStoreConfirmationWatcher.java | 60 ---------- .../devtools/systemimage/uitest/common/Res.java | 2 +- .../systemimage/uitest/utils/PlayStoreUtil.java | 36 +++--- .../watchers/PlayStoreConfirmationWatcher.java | 69 ++++++++++++ 5 files changed, 210 insertions(+), 81 deletions(-) delete mode 100644 system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/unittest/watchers/PlayStoreConfirmationWatcher.java create mode 100644 system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/watchers/PlayStoreConfirmationWatcher.java diff --git a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java index 34e43559..45b9a062 100644 --- a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java +++ b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/PlayStoreTest.java @@ -19,9 +19,7 @@ package com.android.devtools.systemimage.uitest.smoke; import android.app.Instrumentation; import android.support.test.runner.AndroidJUnit4; import android.support.test.uiautomator.UiDevice; -import android.support.test.uiautomator.UiObject; import android.support.test.uiautomator.UiObjectNotFoundException; -import android.support.test.uiautomator.UiScrollable; import android.support.test.uiautomator.UiSelector; import com.android.devtools.systemimage.uitest.annotations.TestInfo; @@ -29,7 +27,7 @@ import com.android.devtools.systemimage.uitest.common.Res; import com.android.devtools.systemimage.uitest.framework.SystemImageTestFramework; import com.android.devtools.systemimage.uitest.utils.PlayStoreUtil; import com.android.devtools.systemimage.uitest.utils.Wait; -import com.android.devtools.systemimage.uitest.unittest.watchers.PlayStoreConfirmationWatcher; +import com.android.devtools.systemimage.uitest.watchers.PlayStoreConfirmationWatcher; import org.junit.Ignore; import org.junit.Rule; @@ -65,6 +63,7 @@ public class PlayStoreTest { * 3. Confirm that Play Store is present, then launch. * 5. Search for free app in store. * 6. If app is available for install, begin installation. + * 7. Uninstall the app. * Verify: * 1a. If Install button is displayed, allow installation to complete then * confirm that the Open button to launch the app is present. @@ -98,6 +97,125 @@ public class PlayStoreTest { assertTrue("Unable to uninstall the application from Google Play", PlayStoreUtil.uninstallApplication(instrumentation)); + + PlayStoreUtil.resetPlayStore(instrumentation); + device.pressHome(); + } + } + } + + /** + * Verify that an app can be installed and launched from Play Store. + *

+ * TR ID: C14603433 + *

+ *

+     *   Test Steps:
+     *   1. Start an emulator and launch home screen.
+     *   2. Open Apps.
+     *   3. Confirm that Play Store is present, then launch.
+     *   5. Search for free app in store.
+     *   6. If app is available for install, begin installation.
+     *   7. Launch the application.
+     *   7. Close and uninstall the app.
+     *   Verify:
+     *      1. App is installed without errors.
+     *      2. App is launched without errors.
+     *   
+ */ + @Ignore("Testing play store requires google login that may trigger 2-auth factor. Test to be initiated manually by tester.") + @Test + @TestInfo(id = "14578827") + public void testAppInstallationAndLaunch() throws Exception { + Instrumentation instrumentation = testFramework.getInstrumentation(); + final UiDevice device = UiDevice.getInstance(instrumentation); + final String application = "Trello"; + + if (testFramework.getApi() >= 24 && testFramework.isGoogleApiImage()) { + device.pressHome(); + device.findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow(); + + boolean playStoreInstalled = PlayStoreUtil.isPlayStoreInstalled(instrumentation); + + if (playStoreInstalled) { + PlayStoreUtil.searchGooglePlay(instrumentation, application); + PlayStoreUtil.selectFromGooglePlay( + instrumentation, "App: "+application); + + new PlayStoreConfirmationWatcher(device).checkForCondition(); + + assertTrue("Unable to install the application from Google Play", + PlayStoreUtil.installApplication(instrumentation)); + + device.findObject(new UiSelector().text("OPEN")).clickAndWaitForNewWindow(); + assertTrue("App could not be opened", + new Wait().until(new Wait.ExpectedCondition() { + @Override + public boolean isTrue() throws UiObjectNotFoundException { + return device.findObject(new UiSelector() + .packageName("com.trello")).exists(); + } + })); + + device.pressBack(); + + assertTrue("Unable to uninstall the application from Google Play", + PlayStoreUtil.uninstallApplication(instrumentation)); + + PlayStoreUtil.resetPlayStore(instrumentation); + device.pressHome(); + } + } + } + + /** + * Verify that Google Play can reach the payment method prompt during paid app installation. + *

+ * TR ID: C14603432 + *

+ *

+     *   Test Steps:
+     *   1. Start an emulator and launch home screen.
+     *   2. Open Apps.
+     *   3. Confirm that Play Store is present, then launch.
+     *   4. Search for pay app in store.
+     *   Verify:
+     *      1. Confirm that user is presented with a Pay Button with a $.
+     *   
+ */ + @Ignore("Testing play store requires google login that may trigger 2-auth factor. Test to be initiated manually by tester.") + @Test + @TestInfo(id = "14578827") + public void testPayAppVerification() throws Exception { + Instrumentation instrumentation = testFramework.getInstrumentation(); + final UiDevice device = UiDevice.getInstance(instrumentation); + final String application = "Weather Live"; + + if (testFramework.getApi() >= 24 && testFramework.isGoogleApiImage()) { + device.pressHome(); + device.findObject(new UiSelector().description("Apps")).clickAndWaitForNewWindow(); + + boolean playStoreInstalled = PlayStoreUtil.isPlayStoreInstalled(instrumentation); + + if (playStoreInstalled) { + PlayStoreUtil.searchGooglePlay(instrumentation, application); + PlayStoreUtil.selectFromGooglePlay(instrumentation, "App: "+application); + + new PlayStoreConfirmationWatcher(device).checkForCondition(); + + assertTrue( + "Target application is not a pay app", new Wait().until( + new Wait.ExpectedCondition() { + @Override + public boolean isTrue() throws UiObjectNotFoundException { + return device.findObject(new UiSelector() + .resourceId( + Res.GOOGLE_PLAY_BUY_BUTTON_RES).textContains("$")).exists(); + } + })); + + PlayStoreUtil.resetPlayStore(instrumentation); + device.pressHome(); } } } diff --git a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/unittest/watchers/PlayStoreConfirmationWatcher.java b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/unittest/watchers/PlayStoreConfirmationWatcher.java deleted file mode 100644 index ff203529..00000000 --- a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/unittest/watchers/PlayStoreConfirmationWatcher.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2016 The Android Open Source Project - * - * 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.android.devtools.systemimage.uitest.unittest.watchers; - - -import android.support.test.uiautomator.UiDevice; -import android.support.test.uiautomator.UiObject; -import android.support.test.uiautomator.UiObjectNotFoundException; -import android.support.test.uiautomator.UiSelector; -import android.support.test.uiautomator.UiWatcher; - -import com.android.devtools.systemimage.uitest.common.Res; -import com.android.devtools.systemimage.uitest.utils.Wait; - -/** - * VPN app popup watcher that monitors and dismisses the VPN popup dialog. - *

- * Note that this watcher should only be registered before playing the VPN app. - */ -public class PlayStoreConfirmationWatcher implements UiWatcher { - private final UiDevice mDevice; - - public PlayStoreConfirmationWatcher(UiDevice device) { - this.mDevice = device; - } - - @Override - public boolean checkForCondition() { - UiObject confirmBox = mDevice.findObject(new UiSelector().text("CONFIRM")); - UiObject okBox = mDevice.findObject(new UiSelector().text("OK")); - try { - if (confirmBox.exists()) { - confirmBox.click(); - } - if (okBox.exists()) { - okBox.click(); - return true; - } - else { - return false; - } - } catch (UiObjectNotFoundException e) { - throw new AssertionError("Failed to dismiss the VPN popup dialog"); - } - } -} \ No newline at end of file diff --git a/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/common/Res.java b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/common/Res.java index 32da225a..f852b00e 100644 --- a/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/common/Res.java +++ b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/common/Res.java @@ -71,8 +71,8 @@ public class Res { public static final String GOOGLE_PLAY_IDLE_RES = "com.android.vending:id/search_box_idle_text"; public static final String GOOGLE_PLAY_INPUT_RES = "com.android.vending:id/search_box_text_input"; - public static final String GOOGLE_PLAY_NAV_RES = "com.android.vending:id/navigation_button"; public static final String GOOGLE_PLAY_BUY_BUTTON_RES = "com.android.vending:id/buy_button"; + public static final String GOOGLE_PLAY_CONTINUE_BUTTON_RES = "com.android.vending:id/continue_button"; public static final String DIALER_BUTTON_RES = "com.android.dialer:id/dialpad_floating_action_button"; diff --git a/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/utils/PlayStoreUtil.java b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/utils/PlayStoreUtil.java index 3fbc99ba..91eb4f62 100644 --- a/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/utils/PlayStoreUtil.java +++ b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/utils/PlayStoreUtil.java @@ -24,6 +24,7 @@ import android.support.test.uiautomator.UiScrollable; import android.support.test.uiautomator.UiSelector; import com.android.devtools.systemimage.uitest.common.Res; +import com.android.devtools.systemimage.uitest.watchers.PlayStoreConfirmationWatcher; import java.util.concurrent.TimeUnit; @@ -61,28 +62,28 @@ public class PlayStoreUtil { } /** - * Launches Google Play and then searches for an application + * Backtracks to the opening Play Store screen. + */ + public static void resetPlayStore(Instrumentation instrumentation) { + final UiDevice device = UiDevice.getInstance(instrumentation); + + for (int i = 0; i < 5; i++) { + device.pressBack(); + } + } + + /** + * Launches Play Store and then searches for an application. */ public static void searchGooglePlay(Instrumentation instrumentation, String appName) throws Exception { final UiDevice device = UiDevice.getInstance(instrumentation); final String playStore = "Play Store"; final String application = appName; - device.findObject(new UiSelector().text(playStore)).clickAndWaitForNewWindow(); - boolean backButtonExists = new Wait().until(new Wait.ExpectedCondition() { - @Override - public boolean isTrue() throws UiObjectNotFoundException { - return device.findObject( - new UiSelector().resourceId(Res.GOOGLE_PLAY_NAV_RES) - .description("Back")).exists(); - } - }); - - if (backButtonExists) { - device.findObject( - new UiSelector().resourceId(Res.GOOGLE_PLAY_NAV_RES) - .description("Back")).click(); - } + device.findObject(new UiSelector().text(playStore)).clickAndWaitForNewWindow(); + resetPlayStore(instrumentation); + device.pressHome(); + device.findObject(new UiSelector().text(playStore)).clickAndWaitForNewWindow(); boolean idleTextFieldExists = new Wait().until(new Wait.ExpectedCondition() { @Override @@ -115,7 +116,7 @@ public class PlayStoreUtil { } /** - * Selects an application listed in Google Play + * Selects an application listed in the Play Store. */ public static void selectFromGooglePlay(Instrumentation instrumentation, String appDescription) throws Exception { final UiDevice device = UiDevice.getInstance(instrumentation); @@ -162,6 +163,7 @@ public class PlayStoreUtil { } device.findObject(new UiSelector().text("INSTALL")).clickAndWaitForNewWindow(); + new PlayStoreConfirmationWatcher(device).checkForCondition(); UiObject openButton = device.findObject(new UiSelector().text("OPEN")); boolean isAppInstalled = openButton.waitForExists(TimeUnit.SECONDS.toMillis(60)); diff --git a/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/watchers/PlayStoreConfirmationWatcher.java b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/watchers/PlayStoreConfirmationWatcher.java new file mode 100644 index 00000000..b4b7c627 --- /dev/null +++ b/system_image_uitests/app/src/main/java/com/android/devtools/systemimage/uitest/watchers/PlayStoreConfirmationWatcher.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2016 The Android Open Source Project + * + * 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.android.devtools.systemimage.uitest.watchers; + +import android.support.test.uiautomator.UiDevice; +import android.support.test.uiautomator.UiObjectNotFoundException; +import android.support.test.uiautomator.UiSelector; +import android.support.test.uiautomator.UiWatcher; + +import java.util.concurrent.TimeUnit; + +/** + * VPN app popup watcher that monitors and dismisses the VPN popup dialog. + *

+ * Note that this watcher should only be registered before playing the VPN app. + */ +public class PlayStoreConfirmationWatcher implements UiWatcher { + private final UiDevice mDevice; + + public PlayStoreConfirmationWatcher(UiDevice device) { + this.mDevice = device; + } + + @Override + public boolean checkForCondition() { + boolean condition = false; + boolean isSuccess = + mDevice.findObject(new UiSelector().text("CONTINUE")) + .waitForExists(TimeUnit.MILLISECONDS.convert(3L, TimeUnit.SECONDS)); + try { + if (isSuccess) { + mDevice.findObject(new UiSelector().text("CONTINUE")).click(); + condition = true; + } + isSuccess = + mDevice.findObject(new UiSelector().text("CONFIRM")) + .waitForExists(TimeUnit.MILLISECONDS.convert(3L, TimeUnit.SECONDS)); + if (isSuccess) { + mDevice.findObject(new UiSelector().text("CONFIRM")).click(); + condition = true; + } + isSuccess = + mDevice.findObject(new UiSelector().text("SKIP")) + .waitForExists(TimeUnit.MILLISECONDS.convert(3L, TimeUnit.SECONDS)); + if (isSuccess) { + mDevice.findObject(new UiSelector().text("SKIP")).click(); + condition = true; + } + } + catch (UiObjectNotFoundException e) { + throw new AssertionError("Failed to dismiss the play store popup dialogs"); + } + return condition; + } +} \ No newline at end of file -- cgit v1.2.3