Appium系列分享,第一篇,常用API接口
1.创建新的会话(session)
#python Android
from appium import webdriver
desired_caps = {
‘platformName‘: ‘Android‘,
‘platformVersion‘: ‘7.0‘,
‘deviceName‘: ‘Android Emulator‘,
‘automationName‘: ‘UiAutomator2‘,
‘app‘: PATH(‘/path/to/app‘)
}
driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps)
#python IOS 篇
from appium import webdriver
disapp = {
"platformName": "ios",
"platformVersion": "13.3",
"app": "/Users/lileilei/Library/Developer/Xcode/DerivedData/KnowingLife-algbavbxvxbalpfghgvtdxzyehwr/Build/Products/Debug-iphonesimulator/KnowingLife.app",
"automationName": "XCUITest",
"udid": "6A367568-AE13-49A0-BEE2-3B1AD623AB3E",
"deviceName": "iPhone 11 Pro Max"
}
driver = webdriver.Remote(‘http://0.0.0.0:4723/wd/hub‘, disapp)
2.终止会话
driver.quit()
3.后退
driver.back()
4.屏幕截图
screenshotBase64 = self.driver.get_screenshot_as_base64()
5.获得页面源码
source = self.driver.page_source
6.设置超时
driver.set_page_load_timeout(5000)
7.设置隐式等待超时时间
driver.implicitly_wait(5)
8.设置脚本超时时间
driver.set_script_timeout(5000)
9.获取显示方面,横屏竖屏
orientation = driver.orientation
10.设置显示方向
driver.orientation = "LANDSCAPE"
11.获得地理位置
location = driver.location()
12.设置地理位置
driver.set_location(49, 123, 10)
13.获得可用的日志类型
log_types = driver.log_types
14.获得日志对象
logs = driver.get_log(‘driver‘);
15.记录事件
driver.log_event(‘appium‘, ‘funEvent‘)