服务器之家

服务器之家 > 正文

基于python实现微信收红包自动化测试脚本(测试用例)

时间:2021-12-12 22:19     来源/作者:软件测试自动化测试

测试用例(1) 

基于python实现微信收红包自动化测试脚本(测试用例)

测试用例(2)

基于python实现微信收红包自动化测试脚本(测试用例)

代码如下(python):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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

 

到此这篇关于基于python实现微信收红包自动化测试脚本(测试用例)的文章就介绍到这了,更多相关python微信收红包自动化测试脚本内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/ZangKang1/article/details/118547251

相关文章

热门资讯

yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
2021年耽改剧名单 2021要播出的59部耽改剧列表
2021年耽改剧名单 2021要播出的59部耽改剧列表 2021-03-05
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部