appium笔记

driver

desired_caps

driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)

获取屏幕分辨率

size = driver.get_window_size()
width = size['width']
height = size['height']

截图

driver.get_screenshot_as_file(pic_path)

滑动屏幕

start_x,start_y,end_x,end_y

TouchAction(driver).press(x=start_x, y=start_y).move_to(x=end_x, y=end_y).release().perform()

driver.swipe(start_x, start_y, end_x, end_y, 400) #最后的数字越大,滑动步数越多,滑动越慢

点击坐标

click_x,click_y

TouchAction(driver).tap(x=click_x, y=click_y).perform()

其他

driver.quit()

driver.back()

driver.switch_to.alert.accept()

查找控件

find_elements返回类型list,没有找到时返回[]

基本

driver.find_elements_by_accessibility_id(content-desc)
    
driver.find_elements_by_id(resource-id)

driver.find_elements_by_xpath(xpath)

driver.find_elements_by_android_uiautomator(UiSelector)

xpath

//class//class[contains(@index,index)]

//class//class[contains(@text,text)]

//class//class[contains(@content-desc,content-desc)]

//class//class[contains(@resource-id,resource-id)]

//class[contains(@content-desc, content-desc)]/following-sibling::class
//class[contains(@content-desc, content-desc)]/preceding-sibling::class
//class[contains(@content-desc, content-desc)]/parent::class
//class[contains(@content-desc, content-desc)]/child::class
_by_xpath('//xxxx//xxxxxx[x]')
_by_xpath('(//xxxxxx[])[x]')

uiautomator

driver.find_elements_by_android_uiautomator("new UiSelector().text(\"" + text + "\")")

driver.find_elements_by_android_uiautomator(
    "new UiSelector().resourceId(\"xxxxxxx\").text(\"xxxxx\")")

driver.find_elements_by_android_uiautomator("new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text(\""+i+"\"))")

获取控件属性

ele.get_attribute("contentDescription")

ele.get_attribute("text")

""可为 checkable clickable resourceId className 等

获取控件边界大小

ele.rect

返回字典 {‘height’:xxxx,‘width’:xxxxx,‘x’:xxxx,‘y’:xxxxxx}
x y 左上角坐标

参考文档:
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
http://cs.szpt.edu.cn/android/tools/help/uiautomator/UiSelector.html
https://www.cnblogs.com/fenqing3108/p/5740266.html
https://testerhome.com/topics/node23
http://www.testclass.net/appium/
http://www.runoob.com/python/python-tutorial.html
https://www.jianshu.com/p/2200c278cec9

iOS

driver.find_elements_by_name(tabname)

driver.find_elements_by_ios_predicate("name == '"+str(tmpname)+"'")

xpath_exchange = '//XCUIElementTypeButton[contains(@name,"月")]/preceding-sibling::XCUIElementTypeButton[1]'
ele = driver.find_elements_by_xpath(xpath_exchange)

type类似于安卓的className
name内容,大概类似于text或者contentDescription

获取属性

ele.get_attribute("name")

滑动、点击

driver.execute_script("mobile: dragFromToForDuration",{"element": None, "fromX": start_x, "fromY": start_y,"toX": end_x, "toY": end_y,"duration": 1})
driver.execute_script("mobile: tap", {"x": tap_x, "y": tap_y})

up down right left

driver.execute_script("mobile: scroll", {"direction":'up'})
driver.execute_script("mobile: scroll", [{"direction":'down', 'element': ele_object}])

使用swipe、tap等函数报错

获取iOS设备的信息

instruments -s devices
返回:
deviceName (platformVersion) [udid]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值