Skip to content

Commit 0a40589

Browse files
authored
Merge pull request appium#175 from appium/isaac-current-package
Add method for getting current package
2 parents c9f5128 + 52af2e6 commit 0a40589

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ MANIFEST
1414

1515
build
1616
dist
17+
18+
.cache
19+
__pycache__

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,15 @@ assertFalse(el.is_displayed())
470470
```
471471

472472

473-
#### Retrieving the current running activity
473+
#### Retrieving the current running package and activity
474+
475+
The property method `driver.current_package` returns the name of the current
476+
package running on the device.
477+
478+
```python
479+
package = driver.current_package
480+
assertEquals('com.example.android.apis', package)
481+
```
474482

475483
The property method `driver.current_activity` returns the name of the current
476484
activity running on the device.

appium/webdriver/mobilecommand.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class MobileCommand(object):
3636
KEY_EVENT = 'keyEvent' # Needed for Selendroid
3737
LONG_PRESS_KEYCODE = 'longPressKeyCode'
3838
GET_CURRENT_ACTIVITY = 'getCurrentActivity'
39+
GET_CURRENT_PACKAGE = 'getCurrentPackage'
3940
SET_IMMEDIATE_VALUE = 'setImmediateValue'
4041
PULL_FILE = 'pullFile'
4142
PULL_FOLDER = 'pullFolder'
@@ -59,4 +60,4 @@ class MobileCommand(object):
5960
UPDATE_SETTINGS = 'updateSettings'
6061
SET_LOCATION = 'setLocation'
6162
GET_DEVICE_TIME = 'getDeviceTime'
62-
CLEAR = 'clear'
63+
CLEAR = 'clear'

appium/webdriver/webdriver.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,16 @@ def long_press_keycode(self, keycode, metastate=None):
446446

447447
@property
448448
def current_activity(self):
449-
"""Retrieves the current activity on the device.
449+
"""Retrieves the current activity running on the device.
450450
"""
451451
return self.execute(Command.GET_CURRENT_ACTIVITY)['value']
452452

453+
@property
454+
def current_package(self):
455+
"""Retrieves the current package running on the device.
456+
"""
457+
return self.execute(Command.GET_CURRENT_PACKAGE)['value']
458+
453459
def wait_activity(self, activity, timeout, interval=1):
454460
"""Wait for an activity: block until target activity presents
455461
or time out.
@@ -817,6 +823,8 @@ def _addCommands(self):
817823
('POST', '/session/$sessionId/appium/device/long_press_keycode')
818824
self.command_executor._commands[Command.GET_CURRENT_ACTIVITY] = \
819825
('GET', '/session/$sessionId/appium/device/current_activity')
826+
self.command_executor._commands[Command.GET_CURRENT_PACKAGE] = \
827+
('GET', '/session/$sessionId/appium/device/current_package')
820828
self.command_executor._commands[Command.SET_IMMEDIATE_VALUE] = \
821829
('POST', '/session/$sessionId/appium/element/$id/value')
822830
self.command_executor._commands[Command.PULL_FILE] = \

test/functional/android/appium_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def test_current_activity(self):
6767
activity = self.driver.current_activity
6868
self.assertEqual('.ApiDemos', activity)
6969

70+
def test_current_package(self):
71+
package = self.driver.current_package
72+
self.assertEqual('com.example.android.apis', package)
73+
7074
def test_pull_file(self):
7175
data = self.driver.pull_file('data/local/tmp/strings.json')
7276
strings = json.loads(data.decode('base64', 'strict'))

0 commit comments

Comments
 (0)