From cb57859d92c05093ac981ca8de9bf6dbd314cc92 Mon Sep 17 00:00:00 2001 From: Eric Millin Date: Tue, 9 Sep 2014 15:34:49 -0400 Subject: [PATCH] Added start_activity and tests --- README.md | 11 +++++++++++ appium/webdriver/mobilecommand.py | 1 + appium/webdriver/webdriver.py | 23 +++++++++++++++++++++++ test/functional/android/appium_tests.py | 17 +++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/README.md b/README.md index 7b6ffeed..30eba9c4 100644 --- a/README.md +++ b/README.md @@ -360,6 +360,17 @@ assertIsNotNone(el) ### Other methods +#### Start an arbitrary activity + +The `driver.start_activity` method opens arbitrary activities on a device. +If the activity is not part of the application under test, it will also +launch the activity's application. + +```python +driver.start_activity('com.foo.app', '.MyActivity') +``` + + #### Retrieving application strings The property method `driver.app_strings` returns the application strings from diff --git a/appium/webdriver/mobilecommand.py b/appium/webdriver/mobilecommand.py index edd79526..b4b09499 100644 --- a/appium/webdriver/mobilecommand.py +++ b/appium/webdriver/mobilecommand.py @@ -51,3 +51,4 @@ class MobileCommand(object): RESET = 'reset' HIDE_KEYBOARD = 'hideKeyboard' REPLACE_KEYS = 'replaceKeys' + START_ACTIVITY = 'startActivity' diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 6e39b45a..69f68c46 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -530,6 +530,27 @@ def close_app(self): self.execute(Command.CLOSE_APP) return self + def start_activity(self, app_package, app_activity, app_wait_package='', app_wait_activity=''): + """Opens an arbitrary activity during a test. If the activity belongs to + another application, that application is started and the activity is opened. + + This is an Android-only method. + + :Args: + - app_package - The package containing the activity to start. + - app_activity - The activity to start. + - app_wait_package - Begin automation after this package starts. + - app_wait_activity - Begin automation after this activity starts. + """ + data = { + 'appPackage': app_package, + 'appActivity': app_activity, + 'appWaitPackage': app_wait_package, + 'appWaitActivity': app_wait_activity + } + self.execute(Command.START_ACTIVITY, data) + return self + def end_test_coverage(self, intent, path): """Ends the coverage collection and pull the coverage.ec file from the device. Android only. @@ -684,6 +705,8 @@ def _addCommands(self): ('POST', '/session/$sessionId/appium/device/install_app') self.command_executor._commands[Command.REMOVE_APP] = \ ('POST', '/session/$sessionId/appium/device/remove_app') + self.command_executor._commands[Command.START_ACTIVITY] = \ + ('POST', '/session/$sessionId/appium/device/start_activity') self.command_executor._commands[Command.LAUNCH_APP] = \ ('POST', '/session/$sessionId/appium/app/launch') self.command_executor._commands[Command.CLOSE_APP] = \ diff --git a/test/functional/android/appium_tests.py b/test/functional/android/appium_tests.py index de1713c6..6160804a 100644 --- a/test/functional/android/appium_tests.py +++ b/test/functional/android/appium_tests.py @@ -195,6 +195,23 @@ def test_send_keys(self): self.assertEqual('original text and new text', el.text) + def test_start_activity_this_app(self): + self.driver.start_activity("io.appium.android.apis", ".ApiDemos") + self._assert_activity_contains('Demos') + + self.driver.start_activity("io.appium.android.apis", ".accessibility.AccessibilityNodeProviderActivity") + self._assert_activity_contains('Node') + + def test_start_activity_other_app(self): + self.driver.start_activity("io.appium.android.apis", ".ApiDemos") + self._assert_activity_contains('Demos') + + self.driver.start_activity("com.android.contacts", ".ContactsListActivity") + self._assert_activity_contains('Contact') + + def _assert_activity_contains(self, activity): + current = self.driver.current_activity() + self.assertTrue(activity in current) if __name__ == "__main__": suite = unittest.TestLoader().loadTestsFromTestCase(AppiumTests)