本文主要讲解Appium 常用Api方法,具体使用后面文章对于重点Api进行详说,按照方法的作用,大概可以分为四大类。
系统相关元素(控件) *** 作相关元素(控件)查找手势 *** 作 系统相关
start_activity 打开一个应用,安卓的方法
start_activity(self, app_package, app_activity, **opts)
用法 driver.start_activity(app_package, app_activity)
install_app 安装应用
install_app(self, app_path) app_path为安装包路径
用法 driver.install_app(app_path)
is_app_installed 检查app是否有安装,返回 True or False
is_app_installed(self, bundle_id)
用法 driver.is_app_installed(“com.xxxx”)
remove_app 删除应用
remove_app(self, app_id)
用法 driver.remove_app(“com.xxx.”)
launch_app 启动在desired capabilities配置的应用
launch_app(self)
用法 driver.launch_app()
wait_activity 等待指定的activity出现直到超时,interval为查找频率(秒),即每隔几秒获取一次当前的activity,返回的True 或 False
wait_activity(self, activity, timeout, interval=1)
用法driver.wait_activity(‘.activity.xxx’,10,1)
current_activity 获取当前的activity
current_activity(self)
driver.current_activity()
background_app 后台运行app多少秒
background_app(self, seconds)
用法 driver.background_app(5) 置后台5秒后再运行
network_connection 返回网络类型 数值
network_connection(self)
用法 driver.network_connection
set_network_connection 设置网络类型
Value (Alias) | Data | Wifi | Airplane Mode| 0 (None) | 0 | 0 | 0 1 (Airplane Mode) | 0 | 0 | 1 2 (Wifi only) | 0 | 1 | 0 4 (Data only) | 1 | 0 | 0 6 (All network on) | 1 | 1 | 0
set_network_connection(self, connectionType)
用法:from appium.webdriver.connectiontype import ConnectionType
driver.set_network_connection(ConnectionType.WIFI_ONLY)
ConnectionType的类型有 NO_ConNECTION = 0 AIRPLANE_MODE = 1 WIFI_onLY = 2 DATA_onLY = 4 ALL_NETWORK_ON = 6
open_notifications 打系统通知栏(仅支持API 18 以上的安卓系统)
open_notifications(self)
用法 driver.open_notifications()
get_screenshot_as_file 将手机屏幕截图并保存电脑上的文件
get_screenshot_as_file(self, filename)
用法 driver.get_screenshot_as_file(r"d:/imge/demo.png")
get_window_size 获取手机的分辨率
get_window_size(self)
用法 driver.get_window_size()
page_source 获取当前页面的源码
page_source(self)
用法 driver.page_source
quit
quit(self)
用法 driver.quit()
element=driver.find_element(AppiumBy.ID, “ID”)
click 元素点击
用法 element.click()
clear 清除输入的内容
用法 element.clear()
send_keys 在元素中模拟输入(开启appium自带的输入法并配置了appium输入法后,可以输入中英文)
用法 element.send_keys(“文本内容”)
text 返回元素的文本值
用法 element.text
get_attribute 返回元素的文本值
用法 element.get_attribute(“class”)
size 获取元素的大小(高和宽)
用法 element.size
location 获取元素左上角的坐标
用法 element.location
元素(控件)查找参考 https://blog.csdn.net/u010454117/article/details/122673186 文章 手势 *** 作
滑动 *** 作
swipe(self,start_x, start_y, end_x, end_y, duration=None)
从x1点移动到x2点
duration为滑动动作执行时间,单位为毫秒
APP的坐标,左上角值最小(0,0),右下角值最大
用法 driver.swipe(100, 100, 200,200, 500)
手指点击屏幕 *** 作
轻敲
tap(self, element=None, x=None, y=None, count=1)
模拟手指点击 *** 作,element为元素 x,y为坐标,两者二选一
用法 TouchAction(driver).tap(element).perform() TouchAction(driver).tap(x=200,y=200).perform()
按下和抬起
按下 press(self, element=None, x=None, y=None)
抬起 release()
模拟手指按下和抬起 *** 作,element为元素 x,y为坐标,两者二选一
用法 TouchAction(driver).press(element).release().perform() TouchAction(driver).press(x=200,y=200).release().perform()
等待
wait(ms) 等待多少毫秒
用法 TouchAction(driver).press(element).wait().perform()
长按
long_press(self, element=None, x=None, y=None, duration=1000) element为元素 x,y为坐标,两者二选一
用法 TouchAction(driver).long_press(element).perform()
移动
move_to(self, element=None, x=None, y=None) element为元素 x,y为坐标,两者二选一
用法 TouchAction(driver).move_to().perform()
放大 *** 作
zoom(self, element=None, percent=200, steps=50)
在某控件上执行放大 *** 作,默认放大比例为200%
step表示放大动作分多少步完成,默认50
用法 driver.zoom(element)
缩小 *** 作
pinch(self, element=None, percent=200, steps=50)
在某控件上执行缩小 *** 作,默认缩小比例为200%
step表示缩小动作分多少步完成,默认50
用法 driver.pinch(element)
滚动 *** 作
scroll(self, origin_el, destination_el)
从元素origin_el滚动至元素destination_el
参数必须是控件,而不是控件信息
用法 driver.scroll(element1,element2)
拖曳 *** 作
drag_and_drop(self, origin_el, destination_el)
将元素origin_el拖到目标元素destination_el
参数必须是控件,而不是控件信息
用法 driver.drag_and_drop(element1,element2)
以上为内容纯属个人理解,如有不足,欢迎各位大神指正!
如果觉得文章不错,欢迎关注微信公众号,微信公众号定期推送相关测试技术文章
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)