Skip to content

Commit

Permalink
removed complex_find, added get_settings, update_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonahss committed Sep 19, 2014
1 parent 41a9297 commit ee03b24
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 34 deletions.
42 changes: 27 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ assertIsNotNone(el)
#### 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
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
Expand Down Expand Up @@ -483,19 +483,6 @@ self.assertEqual(data, data_ret)
```


#### Complex find in Android

Appium supports a way to do complex searches for elements on an Android device.
This is accessed through `driver.complex_find`. The arguments and use case,
to borrow from Winston Churchill, remain a riddle, wrapped in a mystery, inside
an enigma.

```python
el = self.driver.complex_find([[[2, 'Ani']]])
self.assertIsNotNone(el)
```


#### End test coverage

There is functionality in the Android emulator to instrument certain activities.
Expand All @@ -518,3 +505,28 @@ argument is the number of seconds to wait before unlocking.
#### Shake the device

To shake the device, use `driver.shake`.


#### Appium Settings

Settings are a new concept introduced by appium. They are currently not a part of the Mobile JSON Wire Protocol, or the Webdriver spec.

Settings are a way to specify the behavior of the appium server.

Settings are:

Mutable, they can be changed during a session
Only relevant during the session they are applied. They are reset for each new session.
Control the way the appium server behaves during test automation. They do not apply to controlling the app or device under test.

See [the docs](https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/settings.md) for more information.

To get settings:
```python
settings = driver.get_settings()
```

To set settings:
```python
driver.update_settings({"some setting": "the value"})
```
3 changes: 2 additions & 1 deletion appium/webdriver/mobilecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class MobileCommand(object):
PULL_FILE = 'pullFile'
PULL_FOLDER = 'pullFolder'
PUSH_FILE = 'pushFile'
COMPLEX_FIND = 'complexFind'
BACKGROUND = 'background'
IS_APP_INSTALLED = 'isAppInstalled'
INSTALL_APP = 'installApp'
Expand All @@ -52,3 +51,5 @@ class MobileCommand(object):
HIDE_KEYBOARD = 'hideKeyboard'
REPLACE_KEYS = 'replaceKeys'
START_ACTIVITY = 'startActivity'
GET_SETTINGS = 'getSettings'
UPDATE_SETTINGS = 'updateSettings'
35 changes: 22 additions & 13 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,6 @@ def push_file(self, path, base64data):
self.execute(Command.PUSH_FILE, data)
return self

def complex_find(self, selector):
"""Performs a find for elements in the current application.
:Args:
- selector - an array of selection criteria
"""
data = {
'selector': selector,
}
return self.execute(Command.COMPLEX_FIND, data)['value']

def background_app(self, seconds):
"""Puts the application in the background on the device for a certain
duration.
Expand Down Expand Up @@ -664,6 +653,24 @@ def active_ime_engine(self):
"""
return self.execute(Command.GET_ACTIVE_IME_ENGINE, {})['value']

def get_settings(self):
"""Returns the appium server Settings for the current session.
Do not get Settings confused with Desired Capabilities, they are
separate concepts. See https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/settings.md
"""
return self.execute(Command.GET_SETTINGS, {})['value']

def update_settings(self, settings):
"""Set settings for the current session.
For more on settings, see: https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/settings.md
:Args:
- settings - dictionary of settings to apply to the current test session
"""
data = {"settings": settings}

self.execute(Command.UPDATE_SETTINGS, data)
return self

def _addCommands(self):
self.command_executor._commands[Command.CONTEXTS] = \
Expand Down Expand Up @@ -695,8 +702,6 @@ def _addCommands(self):
('POST', '/session/$sessionId/appium/device/pull_folder')
self.command_executor._commands[Command.PUSH_FILE] = \
('POST', '/session/$sessionId/appium/device/push_file')
self.command_executor._commands[Command.COMPLEX_FIND] = \
('POST', '/session/$sessionId/appium/app/complex_find')
self.command_executor._commands[Command.BACKGROUND] = \
('POST', '/session/$sessionId/appium/app/background')
self.command_executor._commands[Command.IS_APP_INSTALLED] = \
Expand Down Expand Up @@ -739,6 +744,10 @@ def _addCommands(self):
('GET', '/session/$sessionId/ime/active_engine')
self.command_executor._commands[Command.REPLACE_KEYS] = \
('POST', '/session/$sessionId/appium/element/$elementId/replace_value')
self.command_executor._commands[Command.GET_SETTINGS] = \
('GET', '/session/$sessionId/appium/settings')
self.command_executor._commands[Command.UPDATE_SETTINGS] = \
('POST', '/session/$sessionId/appium/settings')


# monkeypatched method for WebElement
Expand Down
14 changes: 9 additions & 5 deletions test/functional/android/appium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ def test_pull_folder(self):
myzip.read('1.txt')
myzip.read('2.txt')

def test_complex_find(self):
# this only works with a three dimensional array like here.
el = self.driver.complex_find([[[2, 'Ani']]])
self.assertIsNotNone(el)

def test_background_app(self):
self.driver.background_app(1)
sleep(5)
Expand Down Expand Up @@ -213,6 +208,15 @@ def _assert_activity_contains(self, activity):
current = self.driver.current_activity()
self.assertTrue(activity in current)

def test_get_settings(self):
settings = self.driver.get_settings()
self.assertIsNotNone(settings)

def test_update_settings(self):
self.driver.update_settings({"cyberdelia": "open"})
settings = self.driver.get_settings()
self.assertEqual(settings["cyberdelia"], "open")

if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(AppiumTests)
unittest.TextTestRunner(verbosity=2).run(suite)

0 comments on commit ee03b24

Please sign in to comment.