代码拉取完成,页面将自动刷新
'''
@Description
@auther leizi
'''
from common.parame import Parmer
from common.adbtool import *
from common.packageparse import get_apk_lautc, get_apkname
from multiprocessing import Pool
import random
from common.appiumserveruntil import start, stop_server
from case.logintestcase import testCase
from config import apk_path
from config import test_phone_type
from common.iosadbtool import *
from common.iosadbtool import getplatfoemversion as getiosplatform
from common.BSTestRunner import BSTestRunner
from common.trytestnum import *
from config import BASH_DIR,ISSHOWHISTORY
import os
def getdevicespol(devicests: list) -> list:
devices_Pool = []
if test_phone_type == "Android":
for i in range(0, len(devicests)):
_pool = []
_initApp = {}
device = devicests[i]
apkname = get_apkname(apk_path)
desired_caps = {
'platformName': 'Android',
'deviceName': device['devices'], # adb deivces
'platformVersion': getPlatForm(devicests[i]['devices']), # 从设置中可以获取
'appPackage': apkname, # 包名
'udid': devicests[i]['devices'],
'appActivity': get_apk_lautc(apk_path), # apk的launcherActivity
# 'skipServerInstallation': True
}
_initApp['deviceName'] = device['devices']
_initApp["port"] = device["port"]
_initApp['appPackage'] = apkname
_initApp['desired_caps'] = desired_caps
_pool.append(_initApp)
devices_Pool.append(_initApp)
elif test_phone_type == "IOS":
for i in range(0, len(devicests)):
_pool = []
_initApp = {}
device = devicests[i]
desired_caps = {
'platformName': 'IOS',
'deviceName': device['devices'], # adb deivces
'platformVersion': getiosplatform(devicests[i]['devices']), # 从设置中可以获取
'appPackage': "待做", # 包名
'udid': devicests[i]['devices'],
'appActivity': "待做", # apk的launcherActivity
# 'skipServerInstallation': True
}
_initApp['deviceName'] = device['devices']
_initApp["port"] = device["port"]
_initApp['appPackage'] = "待做"
_initApp['desired_caps'] = desired_caps
_pool.append(_initApp)
devices_Pool.append(_initApp)
return devices_Pool
def runnerPool(getDevices):
'''
根据链接的设备生成不同的dict
然后放到设备的list里面
设备list的长度产生进程池大小
'''
devices_Pool = getdevicespol(getDevices)
pool = Pool(len(devices_Pool))
pool.map_async(runnerCaseApp, devices_Pool)
pool.close()
pool.join()
l_devices = []
def runnerCaseApp(devices):
from config import runprojecttrynum
report_path = os.path.join(BASH_DIR,"test.html")
openone = open(report_path, 'w+')
'''利用unittest的testsuite来组织测试用例'''
besautiful = BSTestRunner(title="报告",
description="测试报告", stream=openone,
trynum=runprojecttrynum,is_show=ISSHOWHISTORY,
filepath=BASH_DIR)
test_suit = unittest.TestSuite()
test_suit.addTest(Parmer.parametrize(testcase_klass=testCase, parame=devices)) # 扩展的其他的测试用例均这样添加
besautiful.run(test_suit)
def run():
if test_phone_type == "Android":
devices = get_devices()
elif test_phone_type == "IOS":
devices = getdeviceslist()
else:
devices = []
port_list = []
if len(devices) > 0:
for dev in devices:
app = {}
app["devices"] = dev
port = str(random.randint(5641, 5646))
app["port"] = port
port_list.append(port)
l_devices.append(app)
start(port_list)
runnerPool(l_devices)
try:
stop_server(port_list)
except Exception as e:
print("关闭服务失败,原因:%s" % e)
finally:
pass
# opear.realese()
else:
print('请链接测试设备')
if __name__ == "__main__":
run()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。