Skip to content

Commit 41a9297

Browse files
committed
Merge pull request #55 from 0x1mason/2969
Added start_activity and tests
2 parents 787d7df + cb57859 commit 41a9297

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,17 @@ assertIsNotNone(el)
360360
### Other methods
361361
362362
363+
#### Start an arbitrary activity
364+
365+
The `driver.start_activity` method opens arbitrary activities on a device.
366+
If the activity is not part of the application under test, it will also
367+
launch the activity's application.
368+
369+
```python
370+
driver.start_activity('com.foo.app', '.MyActivity')
371+
```
372+
373+
363374
#### Retrieving application strings
364375

365376
The property method `driver.app_strings` returns the application strings from

appium/webdriver/mobilecommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ class MobileCommand(object):
5151
RESET = 'reset'
5252
HIDE_KEYBOARD = 'hideKeyboard'
5353
REPLACE_KEYS = 'replaceKeys'
54+
START_ACTIVITY = 'startActivity'

appium/webdriver/webdriver.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,27 @@ def close_app(self):
530530
self.execute(Command.CLOSE_APP)
531531
return self
532532

533+
def start_activity(self, app_package, app_activity, app_wait_package='', app_wait_activity=''):
534+
"""Opens an arbitrary activity during a test. If the activity belongs to
535+
another application, that application is started and the activity is opened.
536+
537+
This is an Android-only method.
538+
539+
:Args:
540+
- app_package - The package containing the activity to start.
541+
- app_activity - The activity to start.
542+
- app_wait_package - Begin automation after this package starts.
543+
- app_wait_activity - Begin automation after this activity starts.
544+
"""
545+
data = {
546+
'appPackage': app_package,
547+
'appActivity': app_activity,
548+
'appWaitPackage': app_wait_package,
549+
'appWaitActivity': app_wait_activity
550+
}
551+
self.execute(Command.START_ACTIVITY, data)
552+
return self
553+
533554
def end_test_coverage(self, intent, path):
534555
"""Ends the coverage collection and pull the coverage.ec file from the device.
535556
Android only.
@@ -684,6 +705,8 @@ def _addCommands(self):
684705
('POST', '/session/$sessionId/appium/device/install_app')
685706
self.command_executor._commands[Command.REMOVE_APP] = \
686707
('POST', '/session/$sessionId/appium/device/remove_app')
708+
self.command_executor._commands[Command.START_ACTIVITY] = \
709+
('POST', '/session/$sessionId/appium/device/start_activity')
687710
self.command_executor._commands[Command.LAUNCH_APP] = \
688711
('POST', '/session/$sessionId/appium/app/launch')
689712
self.command_executor._commands[Command.CLOSE_APP] = \

test/functional/android/appium_tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,23 @@ def test_send_keys(self):
195195

196196
self.assertEqual('original text and new text', el.text)
197197

198+
def test_start_activity_this_app(self):
199+
self.driver.start_activity("io.appium.android.apis", ".ApiDemos")
200+
self._assert_activity_contains('Demos')
201+
202+
self.driver.start_activity("io.appium.android.apis", ".accessibility.AccessibilityNodeProviderActivity")
203+
self._assert_activity_contains('Node')
204+
205+
def test_start_activity_other_app(self):
206+
self.driver.start_activity("io.appium.android.apis", ".ApiDemos")
207+
self._assert_activity_contains('Demos')
208+
209+
self.driver.start_activity("com.android.contacts", ".ContactsListActivity")
210+
self._assert_activity_contains('Contact')
211+
212+
def _assert_activity_contains(self, activity):
213+
current = self.driver.current_activity()
214+
self.assertTrue(activity in current)
198215

199216
if __name__ == "__main__":
200217
suite = unittest.TestLoader().loadTestsFromTestCase(AppiumTests)

0 commit comments

Comments
 (0)