Skip to content

Commit b34cbcb

Browse files
dcntKazuCocoa
authored andcommitted
Add an endpoint for pressing buttons (#262)
1 parent a270cdd commit b34cbcb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

appium/webdriver/webdriver.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,20 @@ def long_press_keycode(self, keycode, metastate=None, flags=None):
717717
self.execute(Command.LONG_PRESS_KEYCODE, data)
718718
return self
719719

720+
def press_button(self, button_name):
721+
"""Sends a physical button name to the device to simulate the user pressing. iOS only.
722+
Possible button names can be found in
723+
https://github.com/appium/WebDriverAgent/blob/master/WebDriverAgentLib/Categories/XCUIDevice%2BFBHelpers.h
724+
725+
:Args:
726+
- button_name - the button name to be sent to the device
727+
"""
728+
data = {
729+
'name': button_name
730+
}
731+
self.execute_script('mobile: pressButton', data)
732+
return self
733+
720734
@property
721735
def current_activity(self):
722736
"""Retrieves the current activity running on the device.

test/functional/ios/appium_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ def test_clear(self):
146146
text = self.driver.find_element_by_accessibility_id('Normal').get_attribute('value')
147147
self.assertEqual(text, def_text)
148148

149+
def test_press_button(self):
150+
self.driver.press_button("Home")
151+
if float(desired_capabilities.get_desired_capabilities(
152+
desired_capabilities.BUNDLE_ID)['platformVersion']) < 11:
153+
return
154+
self.assertEqual(self.driver.query_app_state(desired_capabilities.BUNDLE_ID),
155+
ApplicationState.RUNNING_IN_FOREGROUND)
156+
149157

150158
if __name__ == "__main__":
151159
suite = unittest.TestLoader().loadTestsFromTestCase(AppiumTests)

0 commit comments

Comments
 (0)