基于python实现微信收红包自动化测试脚本(测试用例)
作者:软件测试自动化测试 时间:2022-01-03 11:38:34
测试用例(1)
测试用例(2)
代码如下(python):
# coding=utf-8
from appium import webdriver
import time
desired_caps = {
'platformName': 'Android',
#使用哪种平台
'deviceName': '158bcb1',
#启用设备名称
'platformVersion': '5.1',
#指定平台的系统版本
'appPackage': 'com.tencent.mm',
#待测试的app的package
'appActivity': 'com.tencent.mm.ui.LauncherUI'
#待测试的Activity的名字
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(5)
#打开微信后等待5s时间
'''
def getSize():
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
return(x,y)
def swipeUp(t):
l = getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.75)
y2 = int(l[1] * 0.25)
driver.swipe(x1,y1,x1,y2,t)
'''
num = 0
num0 = 0
while 1:
driver.find_element_by_id("com.tencent.mm:id/an7").click()
#点开最顶端的群聊
try:
driver.find_element_by_id("com.tencent.mm:id/a92").click()
#如果有多条消息未读按钮,则点击以到达未读消息顶端
except:
while num0 < 5:
if num < 5:
try:
driver.find_element_by_id("com.tencent.mm:id/abz").click()
#如果找到红包,则打开
except:
driver.swipe(300,1000,300,300,0)
num0 += 1
#没有找到红包,则向上大幅度划动一次,num0+1
try:
driver.find_element_by_id("com.tencent.mm:id/bv8").click()
#如果打开了红包,则点击“开”
except:
num += 1
#如果五次打不开红包,则认为此群的没有可以继续打开的红包,退出群聊
try:
driver.find_element_by_id("com.tencent.mm:id/hg").click()
#领取完红包之后,点击左上角的箭头以返回
except:
pass
try:
driver.find_element_by_id("com.tencent.mm:id/bsv").click()
#如果红包未领取完已过期,则点击×返回
except:
pass
driver.swipe(100,450,100,200,0)
#向下滑动以找到下一个红包的位置
else:
break
try:
driver.find_element_by_id("android:id/text1").click()
#执行完毕,退出群聊
except:
driver.find_element_by_id("com.tencent.mm:id/h1").click()
#如果点开了公众号列表,则点击左上角退出
num = 0
num0 = 0
time.sleep(1)
driver.swipe(100,400,100,200,0)
#找到下一个群聊的位置
'''
names_all = driver.find_elements_by_id("com.tencent.mm:id/an7")
#"com.tencent.mm:id/an7"为所有昵称的id,首先收集所有昵称的id到变量names_all
target = "434脱单率100%"
target_trans = target.decode("utf-8")
for n in names_all:
if n.get_attribute("text") == target_trans:
n.click()
break
'''
#测试工具为appium
来源:https://blog.csdn.net/ZangKang1/article/details/118547251
标签:python,微信收红包,自动化测试
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pytorch平均池化nn.AvgPool2d()使用方法实例
2023-09-30 02:49:35
![](https://img.aspxhome.com/file/2023/1/104921_0s.png)
Keras 切换后端方式(Theano和TensorFlow)
2023-05-30 22:35:03
js插入flash可防止虚线框激活
2009-03-13 13:31:00
Python实现合并同一个文件夹下所有txt文件的方法示例
2023-10-11 00:24:22
![](https://img.aspxhome.com/file/2023/3/104903_0s.jpg)
python import 上级目录的导入
2021-09-13 00:54:29
Python实现动态加载模块、类、函数的方法分析
2022-07-25 22:48:58
python标准日志模块logging的使用方法
2022-10-29 19:08:16
![](https://img.aspxhome.com/file/2023/6/81546_0s.jpg)
什么是SVG(可升级矢量图形)
2008-05-06 12:37:00
超酷的js图片轮播渐变效果
2007-10-10 20:45:00
![](https://img.aspxhome.com/file/UploadPic/200710/10/2007101021445381s.jpg)
SQL Server数据体系和应用程序逻辑详解
2009-04-14 07:23:00
浅谈Python2获取中文文件名的编码问题
2021-08-11 08:18:45
python2.7安装图文教程
2021-01-02 01:36:15
![](https://img.aspxhome.com/file/2023/8/103468_0s.png)
ASP使用xmlhttp定时触发事件
2008-08-19 18:09:00
python实现BackPropagation算法
2022-03-26 12:06:39
Python模块学习 filecmp 文件比较
2023-07-09 18:30:44
pytest多重断言的实现
2021-10-12 03:30:25
Python常用数据类型之列表使用详解
2021-12-18 02:46:33
python读取并显示图片的三种方法(opencv、matplotlib、PIL库)
2023-03-24 19:43:02
![](https://img.aspxhome.com/file/2023/9/81529_0s.jpg)
Python爬虫获取基金变动信息
2022-08-15 21:57:15
![](https://img.aspxhome.com/file/2023/5/93975_0s.webp)
MySQL优化之数据类型的使用
2009-03-16 17:12:00