本文主要是介绍基于appium自动化测试案例10--TouchAction--连续滑动操作(学习笔记),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#导入模块
from appium import webdriver from time import sleep from appium.webdriver.common.touch_action import TouchAction from selenium.webdriver.support.ui import WebDriverWait from selenium.common.exceptions import NoSuchElementExceptiondesired_caps={} desired_caps['platformName']='Android' desired_caps['platforVersion']='5.1.1' desired_caps['deviceName']='127.0.0.1:62025' #需要安装app时设置 #desired_caps['app']=r'C:\XXXXXXXX\XXXX.apk' #获取命令adb shell pm list package desired_caps['appPackage']='com.mymoney' #aapt dump badging F:\xxxxxx\xxxx.apk desired_caps['appActivity']='com.mymoney.biz.splash.SplashScreenActivity' #设置参数 driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps) driver.implicitly_wait(5)#获取屏幕尺寸 def get_size():x=driver.get_window_size()['width']y=driver.get_window_size()['height']return x,y#封装向左滑动的方法 def swipeLeft():l=get_size()x1=int(l[0]*0.9)y1=int(l[1]*0.5)x2=int(l[0]*0.1)driver.swipe(x1,y1,x2,y1,1000)#封装向上滑动的方法 def swipUp():l=get_size()x1=int(l[0]*0.5)y1=int(l[1]*0.7)y2=int(l[1]*0.3)driver.swipe(x1,y1,x1,y2,1000)#等待启动页面元素 WebDriverWait(driver,6).until(lambda x:x.find_element_by_id('com.mymoney:id/next_btn')) for i in range(2):swipeLeft()sleep(1)#点击“开始随手记”按钮 driver.find_element_by_id('com.mymoney:id/begin_btn').click() #检测是否有弹框 try:closBtn=driver.find_element_by_id('com.mymoney:id/close_iv') except NoSuchElementException:pass else:closBtn.click()#点击更多菜单 driver.find_element_by_id('com.mymoney:id/nav_setting_btn').click()#等待页面菜单加载出来,然后向上滑动 WebDriverWait(driver,6).until(lambda x:x.find_element_by_id('com.mymoney:id/content_container_ly')) swipUp() #点击高级菜单 driver.find_element_by_android_uiautomator('new UiSelector().text("高级")').click() #点击密码与手势 driver.find_element_by_id('com.mymoney:id/password_protected_briv').click() #点击手势密码保护 driver.find_element_by_id('com.mymoney:id/lock_pattern_or_not_sriv').click()#连续滑动两次设置手势press()-按压release()-释放perform()-连续操作 for i in range(2):TouchAction(driver).press(x=212,y=290).wait(2000)\.move_to(x=357,y=290).wait(5000)\ .move_to(x=509,y=438).wait(1000)\.move_to(x=509,y=589).wait(1000)\.release().perform()
这篇关于基于appium自动化测试案例10--TouchAction--连续滑动操作(学习笔记)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!