app自动化测试---appium之鼠标滑动
2021/6/22 23:33:11
本文主要是介绍app自动化测试---appium之鼠标滑动,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.说明
appium官方文档 : https://appium.io/docs/en/about-appium/intro/
uiselector 元素定位:https://developer.android.google.cn/reference/androidx/test/uiautomator/UiSelector?hl=en
2. 操作代码
from appium import webdriver import time from appium.webdriver.common.touch_action import TouchAction desired_caps = { 'platformName':'Android', # 测试Android系统 'platformVersion':'7.1.2', # Android版本 可以在已连接手机 设置->关于手机 中查看 'deviceName':'127.0.0.1:62001', # cmd中使用 adb devices 命令查看已连接的设备 'automationName':'UiAutomator2', # 自动化引擎(默认UiAutomator2即可) 'noReset': True, # 不要重置app的状态(比如,已经登陆的app,我们运行项目的时候保留之前的状态) 'fullReset': False, # 不要清理app的缓存数据(比如,已经登陆的app,我们运行项目的时候保留之前的状态) 'appPackage':"org.cnodejs.android.md", # 应用的包名(打开对应包名的app) 'appActivity': ".ui.activity.MainActivity" # 应用的活动页名称 } driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_capabilities=desired_caps) time.sleep(5) viewgroup = driver.find_element_by_android_uiautomator('new UiSelector().className("android.view.ViewGroup").index(2)') # 获取元素控件的坐标位置(使用坐标位置去计算滑动坐标,可以保证我们在不同的手机上正常运行) print('location', viewgroup.location) # {'x': 0, 'y': 120} 元素的左上角坐标 print('rect', viewgroup.rect) # {'height': 1440, 'width': 900, 'x': 0, 'y': 120} 元素宽高和元素左上角坐标 zb = viewgroup.rect # 滑动的开始坐标x,y 结束坐标x,y 滑动时间(毫秒) # 当前设置效果为:从下往上滑动 driver.swipe(start_x=zb['width']/2,start_y=zb['height']+zb['y']-1,end_x=zb['width']/2,end_y=zb['y']+1,duration=200) # 等同于 # driver.swipe(start_x=450,start_y=1559,end_x=450,end_y=121,duration=200) # 当前设置效果为:从上往下滑动 driver.swipe(start_x=300, start_y=200, end_x=300, end_y=800, duration=200) time.sleep(3) # 点击页面中的第一个帖子的作者 first_tiezi = '//*[@resource-id="org.cnodejs.android.md:id/recycler_view"]/android.widget.LinearLayout[1]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]' driver.find_element_by_xpath(first_tiezi).click() time.sleep(3) # 当前设置效果为:从右往左滑动 driver.swipe(start_x=550,start_y=700,end_x=500,end_y=700,duration=200) time.sleep(3) # 当前设置效果为:从左往右滑动 driver.swipe(start_x=50,start_y=700,end_x=550,end_y=700,duration=200) time.sleep(3)
这篇关于app自动化测试---appium之鼠标滑动的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)