Appium同時連接多台手機進行測試(多線程)


作為測試小白,當時遇到了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

 




 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM