Appium+Python实现简单的自动化登录测试的实现
作者:小小渔夫 时间:2021-09-13 05:49:14
前言
要想让手机app自动登录,也就是让app自己操作。所以在脚本中我们需要对app控件进行操作,那么我们需要获取控件的信息。可以使用..\android-sdk-windows\tools目录下的uiautomatorviewer.bat来获取控件相关信息
获取控件相关信息
启动uiautomatorviewer.bat
打开手机app,例如计算器,USB连接电脑,点击uiautomatorviewer左上角的安卓机器人按钮Devices Screenshot按钮刷新页面
定位元素:移动鼠标到需要定位的元素上,如数字7。右下角可以看到元素对应的属性
登录脚本实现
# coding=utf-8
__author__ = "Enoch"
# 这是一个app登录的测试
from appium import webdriver
from HTMLTestRunner import HTMLTestRunner
import unittest
import time
import warnings
class LoginTest(unittest.TestCase):
def setUp(self):
warnings.simplefilter("ignore", ResourceWarning)
desired_caps = {
'platformName': 'Android',
'deviceName': 'SGEEGEHIQ8I7CIKF',
'platformVersion': '6.0',
'appPackage': 'com.mengtuiapp.mall',
'appActivity': '.business.main.MainActivity'
}
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
def testCase(self):
u"""登录"""
driver = self.driver
# time.sleep(2)
driver.find_element_by_id("bottom_nav").click()
time.sleep(2)
driver.find_element_by_name('使用其他方式登录').click()
driver.find_element_by_name('手机登录').click()
driver.find_element_by_id("username").send_keys("13100010001")
driver.find_element_by_name('获取验证码').send_keys("9876")
driver.find_element_by_id("btn").click()
driver.quit()
if __name__ == '__main__':
print("----------执行---------- ")
suite = unittest.TestSuite() # 构造测试集
suite.addTest(LoginTest('testCase'))
# 定义自动化报告目录
filename = "F:\\report.html"
fp = open(filename, 'wb')
runner = HTMLTestRunner(
stream=fp,
title=u'自动化测试报告',
description=u'这是登录测试的简单报告'
)
runner.run(suite)
fp.close()
来源:https://blog.csdn.net/cx243698/article/details/86240185
标签:Appium,Python,自动化登录
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何在小空间放置大图片
2009-08-04 13:04:00
![](https://img.aspxhome.com/file/UploadPic/20098/4/01-47s.jpg)
FSO读取BMP,JPG,PNG,GIF图像文件信息的函数
2007-08-04 09:56:00
Python使用内置函数setattr设置对象的属性值
2021-10-09 20:32:44
Python 图像处理: 生成二维高斯分布蒙版的实例
2023-01-31 16:29:06
![](https://img.aspxhome.com/file/2023/8/81538_0s.jpg)
提高ASP性能的最佳选择第一部分
2007-08-15 12:31:00
深入了解Python 中线程和进程区别
2021-09-01 20:51:38
Python使用numpy产生正态分布随机数的向量或矩阵操作示例
2022-12-28 05:44:11
![](https://img.aspxhome.com/file/2023/5/67925_0s.png)
纯JSP+DWR实现3 级联动下拉选择菜单实现技巧
2023-07-10 12:52:40
Pandas 同元素多列去重的实例
2023-02-09 21:03:32
浅谈web分析
2008-12-02 15:52:00
![](https://img.aspxhome.com/file/UploadPic/200812/2/03-35.jpg)
Python下的Softmax回归函数的实现方法(推荐)
2022-02-13 10:42:17
![](https://img.aspxhome.com/file/2023/0/66320_0s.jpg)
Oracle数据库的备份及恢复策略研究
2010-07-16 12:54:00
使用python 获取进程pid号的方法
2023-06-11 21:25:52
教你如何利用python3爬虫爬取漫画岛-非人哉漫画
2021-10-01 23:06:57
![](https://img.aspxhome.com/file/2023/0/75130_0s.jpg)
2008年情人节各网站节日Logo欣赏
2008-02-17 14:12:00
![](https://img.aspxhome.com/file/UploadPic/20082/17/2008217141834880s.gif)
asp实现树型结构
2008-04-13 06:06:00
用 Python 脚本实现电脑唤醒后自动拍照并截屏发邮件通知
2023-08-30 14:15:44
![](https://img.aspxhome.com/file/2023/5/62555_0s.png)
Python中字典(dict)和列表(list)的排序方法实例
2021-11-30 11:15:18
一文详解Go语言fmt标准库的常用占位符使用
2023-08-07 01:57:56
基于Google的Python编码规范标准
2023-02-21 12:40:38