Appium同时链接多台手机进行测试(多线程)

做为测试小白,当时遇到了N多问题:python

  开启多线程后,发现app启动后,用例就中止了;且启动app对应的手机不能正确对应,用例中是A手机跑A用例,结果启动了B手机跑A用例报错。web

  主要缘由:Appium Server启动时只区分了启动端口,但未区分监听端口;手机配置信息不完整,缺乏udid信息多线程

 

须要链接多台手机作兼容性,同时跑相同的测试用例或不一样用例,那RC Driver须要分开,避免跑用例混乱或出错,也就是说咱们须要同时开启多个appium server端。并发

同时也要明白,多线程并非完彻底全的并发,线程之间也是有执行前后顺序,通常状况不明显,不影响测试。app

 

直接上测试代码:测试

#! /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,避免用例间相互影响。spa

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
相关文章
相关标签/搜索