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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dist

.cache
__pycache__
.idea
2 changes: 2 additions & 0 deletions appium/webdriver/mobilecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class MobileCommand(object):
CLOSE_APP = 'closeApp'
END_TEST_COVERAGE = 'endTestCoverage'
LOCK = 'lock'
UNLOCK = 'unlock'
IS_LOCKED = 'isLocked'
SHAKE = 'shake'
TOUCH_ID = 'touchId'
TOGGLE_TOUCH_ID_ENROLLMENT = 'toggleTouchIdEnrollment'
Expand Down
31 changes: 25 additions & 6 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,17 +640,32 @@ def end_test_coverage(self, intent, path):
return self.execute(Command.END_TEST_COVERAGE, data)['value']

def lock(self, seconds):
"""Lock the device for a certain period of time. iOS only.
"""Lock the device. No changes are made if the device is already unlocked.

:Args:
- the duration to lock the device, in seconds
- seconds - the duration to lock the device, in seconds.
The device is going to be locked forever until `unlock` is called
if it equals or is less than zero, otherwise this call blocks until
the timeout expires and unlocks the screen automatically.
"""
data = {
'seconds': seconds,
}
self.execute(Command.LOCK, data)
self.execute(Command.LOCK, {'seconds': seconds})
return self

def unlock(self):
"""Unlock the device. No changes are made if the device
is already locked.
"""
self.execute(Command.UNLOCK)
return self

def is_locked(self):
"""Checks whether the device is locked.

:returns:
Either True or False
"""
return self.execute(Command.IS_LOCKED)['value']

def shake(self):
"""Shake the device.
"""
Expand Down Expand Up @@ -850,6 +865,10 @@ def _addCommands(self):
('POST', '/session/$sessionId/appium/app/end_test_coverage')
self.command_executor._commands[Command.LOCK] = \
('POST', '/session/$sessionId/appium/device/lock')
self.command_executor._commands[Command.UNLOCK] = \
('POST', '/session/$sessionId/appium/device/unlock')
self.command_executor._commands[Command.IS_LOCKED] = \
('POST', '/session/$sessionId/appium/device/is_locked')
self.command_executor._commands[Command.SHAKE] = \
('POST', '/session/$sessionId/appium/device/shake')
self.command_executor._commands[Command.TOUCH_ID] = \
Expand Down
8 changes: 8 additions & 0 deletions test/functional/android/appium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def tearDown(self):
if hasattr(self, 'zipfilename') and os.path.isfile(self.zipfilename):
os.remove(self.zipfilename)

def test_lock(self):
self.driver.lock(-1)
try:
self.assertTrue(self.driver.is_locked())
finally:
self.driver.unlock()
self.assertFalse(self.driver.is_locked())

def test_app_strings(self):
strings = self.driver.app_strings()
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
Expand Down
15 changes: 6 additions & 9 deletions test/functional/ios/appium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ def tearDown(self):
self.driver.quit()

def test_lock(self):
el = self.driver.find_element_by_id('ButtonsExplain')
self.assertIsNotNone(el)
self.driver.lock(0)
self.assertRaises(NoSuchElementException, self.driver.find_element_by_id, 'ButtonsExplain')
sleep(10)

# # this does not seem to ever unlock, so the assertion fails
# el = self.driver.find_element_by_id('ButtonsExplain')
# self.assertIsNotNone(el)
self.driver.lock(-1)
try:
self.assertTrue(self.driver.is_locked())
finally:
self.driver.unlock()
self.assertFalse(self.driver.is_locked())

def test_shake(self):
# what can we assert about this?
Expand Down