Python&Appium实现滑动引导页进入APP详解编程语言
2023-06-13 09:20:47 时间
最近在研究安卓APP的自动化测试。首先遇到的问题是,当一个session建立的时候,最先进入的是欢迎页和引导页,引导页有三张,最后一张上显示“enter”按钮,点击才能进入主界面。
欢迎页加引导页,这两个页面是每次进入APP都无法避免的,如何通过代码执行跳过它们进入主界面的操作呢?
1、建立session
def test_enterApp(self): desired_caps = {} desired_caps[platformName] = Android desired_caps[platformVersion] = 4.4.4 desired_caps[app] = /Users/a140/Downloads/app.apk desired_caps[deviceName] = 03083025d0250909 self.driver = webdriver.Remote(http://localhost:4723/wd/hub, desired_caps) self.driver.implicitly_wait(5)
2、运用代码模拟手指从右向左滑动的操作
#获取屏幕宽度和高度 def getSize(self): x = self.driver.get_window_size()[width] y = self.driver.get_window_size()[height] return (x, y) #向左滑动 def swipeLeft(self): l = self.getSize() x1 = int(l[0] * 0.9) y1 = int(l[1] * 0.5) x2 = int(l[0] * 0.1) self.driver.swipe(x1, y1, x2, y1)
因为手机屏幕的尺寸多样,所以这里不设置固定的宽度和高度的值,而是封装了一个获取屏幕宽高度的方法,通过它计算屏幕滑动的坐标和距离。
3、调用swipeLeft()方法向左滑动,最后通过find_element_by_id()找到“enter”按钮,然后点击进入主界面
#向左滑动跳过引导页 x = 0 while x 3: self.swipeLeft() x += 1 enterApp = self.driver.find_element_by_id("com.app.night:id/enter") enterApp.click()
完整的代码如下所示:
import unittest from appium import webdriver class HelloWorld(unittest.TestCase): def test_enterFilter(self): desired_caps = {} desired_caps[platformName] = Android desired_caps[platformVersion] = 4.4.4 desired_caps[app] = /Users/a140/Downloads/app.apk desired_caps[deviceName] = 03083025d0250909 self.driver = webdriver.Remote(http://localhost:4723/wd/hub, desired_caps) self.driver.implicitly_wait(5) #向左滑动跳过引导页 x = 0 while x 3: self.swipeLeft() x += 1 enterApp = self.driver.find_element_by_id("com.app.night:id/enter") enterApp.click() #获取屏幕宽度和高度 def getSize(self): x = self.driver.get_window_size()[width] y = self.driver.get_window_size()[height] return (x, y) #向左滑动 def swipeLeft(self): l = self.getSize() x1 = int(l[0] * 0.9) y1 = int(l[1] * 0.5) x2 = int(l[0] * 0.1) self.driver.swipe(x1, y1, x2, y1) if __name__ == __main__: suite = unittest.TestLoader().loadTestsFromTestCase(HelloWorld) unittest.TextTestRunner(verbosity=2).run(suite)
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/16385.html
cjava相关文章
- python win32api messagebox_如何在Python中使用Win32 API?
- pycharm选择运行环境_python编程入门
- Python 爬虫 NO.1 URI和URL
- pythonrequests代理ip_python使用requests模块使用ip代理池
- python关于random的使用例子
- 【说站】python多行读写的操作
- Python函数式编程:返回函数与匿名函数
- 语音识别系列︱用python进行音频解析(一)
- 向下取整和向上取整的符号_python向上取整函数
- python处理异常的关键字_如果抛出异常应用哪些关键字
- python lambda表达式 if_Python学习-lambda表达式
- Python绘制旭日图_python绘制散点图
- python定义函数求和_Python定义函数实现累计求和操作
- java基于springboot外卖系统在线订餐系统app源码厨艺论坛APP
- 2018最新苹果APP上架App Store流程(超详细)
- 【2023新书】Python数据科学手册:使用数据的基本工具
- Python面向对象编程-公有、私有和保护成员
- python-Python与SQLite数据库-使用Python执行SQLite查询(一)
- python-Python与SQLite数据库-处理SQLite查询结果(二)
- Python猜数字游戏详解编程语言
- Python学习:1.快速搭建python环境详解编程语言
- 掌握Python访问MySQL的新技能(python访问mysql)
- vue main.js中app绑定的是index.html还是App.vue中详解编程语言
- python之字典【dict】详解编程语言
- 如何使用Python继承机制(子类化内置类型)
- Python异常机制使用细则,正确使用Python异常处理机制(入门必读)
- Linux下的打造智能App之旅(linux系统app)
- Python轻松连接SQL Server数据库(python连接sqlserver)
- Python科学计算环境推荐——Anaconda
- Python的批量远程管理和部署工具Fabric用法实例
- Python实现Linux下守护进程的编写方法