2 Star 4 Fork 5

雷子/appiumdemo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
run.py 4.30 KB
一键复制 编辑 原始数据 按行查看 历史
'''
@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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/liwanlei/appiumdemo.git
git@gitee.com:liwanlei/appiumdemo.git
liwanlei
appiumdemo
appiumdemo
master

搜索帮助