Skip to content

Commit

Permalink
Add an endpoint for pressing buttons (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcnt authored and KazuCocoa committed Oct 18, 2018
1 parent a270cdd commit b34cbcb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,20 @@ def long_press_keycode(self, keycode, metastate=None, flags=None):
self.execute(Command.LONG_PRESS_KEYCODE, data)
return self

def press_button(self, button_name):
"""Sends a physical button name to the device to simulate the user pressing. iOS only.
Possible button names can be found in
https://github.com/appium/WebDriverAgent/blob/master/WebDriverAgentLib/Categories/XCUIDevice%2BFBHelpers.h
:Args:
- button_name - the button name to be sent to the device
"""
data = {
'name': button_name
}
self.execute_script('mobile: pressButton', data)
return self

@property
def current_activity(self):
"""Retrieves the current activity running on the device.
Expand Down
8 changes: 8 additions & 0 deletions test/functional/ios/appium_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ def test_clear(self):
text = self.driver.find_element_by_accessibility_id('Normal').get_attribute('value')
self.assertEqual(text, def_text)

def test_press_button(self):
self.driver.press_button("Home")
if float(desired_capabilities.get_desired_capabilities(
desired_capabilities.BUNDLE_ID)['platformVersion']) < 11:
return
self.assertEqual(self.driver.query_app_state(desired_capabilities.BUNDLE_ID),
ApplicationState.RUNNING_IN_FOREGROUND)


if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(AppiumTests)
Expand Down

0 comments on commit b34cbcb

Please sign in to comment.