作为测试小白,当时遇到了N多问题:
开启多线程后,发现app启动后,用例就停止了;且启动app对应的手机不能正确对应,用例中是A手机跑A用例,结果启动了B手机跑A用例报错。
主要原因:Appium Server启动时只区分了启动端口,但未区分监听端口;手机配置信息不完整,缺少udid信息
需要连接多台手机做兼容性,同时跑相同的测试用例或不同用例,那RC Driver需要分开,避免跑用例混乱或出错,也就是说我们需要同时开启多个appium server端。
同时也要明白,多线程并不是完完全全的并发,线程之间也是有执行先后顺序,一般情况不明显,不影响测试。
直接上测试代码:
#! /usr/bin/env python
#coding=utf-8
import threading
from Test_QQ import Test_QQ
from Test_weixin import Test_weixin
def task1():
qq =Test_QQ.test_01_Sendmessage()
def task2():
WeiXin = Test_weixin.test_01_Sendmessage()
threads = []
t1 = threading.Thread(target= task1)
threads.append(t1)
t2 = threading.Thread(target= task2)
threads.append(t2)
if __name__ == '__main__':
for t in threads:
t.start()
其中Test_QQ或Test_wexin下的测试driver需要单独连接控制不同appium server,避免用例间相互影响。
start_appiumServer('4727', '4726', '75a2daf1')
time.sleep(10)
print "open server1 success"
desired_caps2 = driver_weixin()
driver = WEBdriver.Remote("Http://127.0.0.1:4727/wd/hub", desired_caps2)
start_appiumServer('4729', '4728', 'BIBI5LEU6PRCDIIV')
time.sleep(10)
print "open server2 success"
desired_caps = driver_qq()
driver1 = webdriver.Remote("http://127.0.0.1:4729/wd/hub", desired_caps)
连接多台手机进行并发测试时,需要指定UDID参数,如下:
1 def driver_qq(platfORMVersion="5.0.2 LRX22G",deviceName='Redmi note3'):
2 desired_caps = {}
3 desired_caps['platformName'] = "Android"
4 desired_caps['platformVersion'] = platformVersion
5 desired_caps['deviceName'] = deviceName
6 desired_caps['udid'] = "BIBI5LEU6PRCDIIV"
7 desired_caps['appPackage'] = 'com.tencent.mobileqq'
8 desired_caps['appActivity'] = 'com.tencent.mobileqq.activity.SplashActivity'
9 desired_caps['reseTKEyboard'] = "True"
10 return desired_caps
0