Skip to content

Instantly share code, notes, and snippets.

@sirmordred
Last active June 17, 2022 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirmordred/4c505ddce96f7513bfbe49d38ef041be to your computer and use it in GitHub Desktop.
Save sirmordred/4c505ddce96f7513bfbe49d38ef041be to your computer and use it in GitHub Desktop.
Appium Recording Sample
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