Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ MANIFEST

build
dist

.cache
__pycache__
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,15 @@ assertFalse(el.is_displayed())
```


#### Retrieving the current running activity
#### Retrieving the current running package and activity

The property method `driver.current_package` returns the name of the current
package running on the device.

```python
package = driver.current_package
assertEquals('com.example.android.apis', package)
```

The property method `driver.current_activity` returns the name of the current
activity running on the device.
Expand Down
3 changes: 2 additions & 1 deletion appium/webdriver/mobilecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MobileCommand(object):
KEY_EVENT = 'keyEvent' # Needed for Selendroid
LONG_PRESS_KEYCODE = 'longPressKeyCode'
GET_CURRENT_ACTIVITY = 'getCurrentActivity'
GET_CURRENT_PACKAGE = 'getCurrentPackage'
SET_IMMEDIATE_VALUE = 'setImmediateValue'
PULL_FILE = 'pullFile'
PULL_FOLDER = 'pullFolder'
Expand All @@ -59,4 +60,4 @@ class MobileCommand(object):
UPDATE_SETTINGS = 'updateSettings'
SET_LOCATION = 'setLocation'
GET_DEVICE_TIME = 'getDeviceTime'
CLEAR = 'clear'
CLEAR = 'clear'
10 changes: 9 additions & 1 deletion appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,16 @@ def long_press_keycode(self, keycode, metastate=None):

@property
def current_activity(self):
"""Retrieves the current activity on the device.
"""Retrieves the current activity running on the device.
"""
return self.execute(Command.GET_CURRENT_ACTIVITY)['value']

@property
def current_package(self):
"""Retrieves the current package running on the device.
"""
return self.execute(Command.GET_CURRENT_PACKAGE)['value']

def wait_activity(self, activity, timeout, interval=1):
"""Wait for an activity: block until target activity presents
or time out.
Expand Down Expand Up @@ -817,6 +823,8 @@ def _addCommands(self):
('POST', '/session/$sessionId/appium/device/long_press_keycode')
self.command_executor._commands[Command.GET_CURRENT_ACTIVITY] = \
('GET', '/session/$sessionId/appium/device/current_activity')
self.command_executor._commands[Command.GET_CURRENT_PACKAGE] = \
('GET', '/session/$sessionId/appium/device/current_package')
self.command_executor._commands[Command.SET_IMMEDIATE_VALUE] = \
('POST', '/session/$sessionId/appium/element/$id/value')
self.command_executor._commands[Command.PULL_FILE] = \
Expand Down
4 changes: 4 additions & 0 deletions test/functional/android/appium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def test_current_activity(self):
activity = self.driver.current_activity
self.assertEqual('.ApiDemos', activity)

def test_current_package(self):
package = self.driver.current_package
self.assertEqual('com.example.android.apis', package)

def test_pull_file(self):
data = self.driver.pull_file('data/local/tmp/strings.json')
strings = json.loads(data.decode('base64', 'strict'))
Expand Down