Last active
June 17, 2022 14:57
-
-
Save sirmordred/4c505ddce96f7513bfbe49d38ef041be to your computer and use it in GitHub Desktop.
Appium Recording Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from appium import webdriver | |
"Setup for the test" | |
desired_caps = {} | |
desired_caps['platformName'] = 'Android' | |
desired_caps['platformVersion'] = '10.0' | |
desired_caps['deviceName'] = 'Huawei P40 Lite API 29' | |
# beware targeted app must be installed first, and since the app is already installed, launch test using package and activity name | |
desired_caps['appPackage'] = 'com.example.xxyy' | |
desired_caps['appActivity'] = 'com.example.xxyy.zz.www' | |
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) | |
driver.implicitly_wait(3) | |
time.sleep(3) | |
# Start recording | |
driver.execute_script('mobile: shell', { | |
'command': 'am', | |
'args': ['start', '-n', 'io.appium.settings/io.appium.settings.Settings', '-a', 'io.appium.settings.recording.ACTION_START', '--es', 'filename', 'abcd.mp4'], | |
'includeStderr': True, | |
'timeout': 5000 | |
}) | |
# Do what you want, execute tests | |
elmnt = driver.find_element_by_id('com.xx.yy:id/xxyybuttonname') | |
if elmnt.get_attribute('text').lower() == "XXXYYYY": | |
print("is equal") | |
else: | |
print("is not equal") | |
print(elmnt.get_attribute('text')) | |
driver.implicitly_wait(3) | |
time.sleep(3) | |
# Stop recording | |
driver.execute_script('mobile: shell', { | |
'command': 'am', | |
'args': ['start', '-n', 'io.appium.settings/io.appium.settings.Settings', '-a', 'io.appium.settings.recording.ACTION_STOP'], | |
'includeStderr': True, | |
'timeout': 5000 | |
}) | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment