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
相關文章
相關標籤/搜索