Esempio n. 1
0
def RunTestCase(starttime,devices):
    print("进入",devices,"的RunTestCase")
    # 获取路径
    configPath = "./config.ini"
    package = Config.getValue(configPath, "packName")[0]
    casepath = os.path.join(os.getcwd(), "TestCase")
    if not os.path.exists(casepath):
        print("测试用例需放到‘TestCase’文件目录下")
    reportpath = os.path.join(os.getcwd(), "Report")
    if not os.path.exists(reportpath):
        os.mkdir(reportpath)
        os.mkdir(reportpath+"/Screen")
    #读取ini文件,获得期望测试的用例列表
    TestList=Config.getValue(configPath, "testcase")
    # 通过GetPyList方法,取得目录里可测试的用例列表
    scriptList = File.GetPyList(casepath)
    suite = unittest.TestSuite()
    for i in range(len(TestList)):
        fileName = "TC_" + TestList[i]
        if fileName in scriptList:
            result = globals()[fileName].Main(devices)
            suite.addTests(result)
    unittestReport = BeautifulReport(suite)
    #处理模拟器端口用的冒号
    if ":" in devices:
        devices=devices.split(":")[1]
    print("devices=",devices)
    nowtime=time.strftime("%H%M%S")
    unittestReport.report(filename=devices+"_"+str(nowtime),description=package, report_dir=reportpath)
    stop_app(package)
Esempio n. 2
0
def RunTestCase(madb,start):
    devices=madb.get_mdevice()
    print("进入{}的RunTestCase".format(devices))
    # 获取路径
    package = madb.get_packagename()
    TestCasePath = madb.get_TestCasePath()
    print("TestCasePath=",TestCasePath)
    if not os.path.exists(TestCasePath):
        print("测试用例需放到‘TestCase’文件目录下")
    reportpath = os.path.join(os.getcwd(), "Report")
    #读取ini文件,获得期望测试的用例列表
    TestList=madb.get_testcaseforselfdevice()
    print("{}的待测用例为:{}".format(madb.get_mdevice(),TestList))
    # 通过GetPyList方法,取得目录里可测试的用例列表
    scriptList = File.GetPyList(TestCasePath)
    suite = unittest.TestSuite()
    for i in range(len(TestList)):
        fileName = "TC_" + TestList[i]
        print("fileName=",fileName)
        if fileName in scriptList:
            print("进入循环")
            #在整个命名空间里遍历所有名称为"TC_xx.py"形式的文件,默认这些文件都是unittest测试文件,然后调用其Main函数。
            result = globals()[fileName].Main(devices)
            suite.addTests(result)
    #聚合报告到BR
    unittestReport = BeautifulReport(suite)
    nowtime=time.strftime("%H%M%S",start)
    #unittestReport.report(filename=madb.get_nickdevice()+"_"+str(nowtime),description=package, report_dir=reportpath,rundevice=madb.get_mdevice())
    # unittestReport.report(filename=madb.get_nickname()+"_"+str(nowtime),description=package, report_dir=reportpath)
    unittestReport.report(filename=madb.get_nickname()+"_report",description=package, log_path=reportpath)
    stop_app(package)
Esempio n. 3
0
def RunTestCase(madb, start):
    # 获取设备列表
    devices = madb.get_mdevice()
    logger.info("进入{}的RunTestCase".format(devices))

    # 获取是否跳过生成测试报告
    skip_report = madb.get_skip_report()
    report_flag = True if skip_report == "1" else False

    # 获取jenkins部署信息
    jenkins_branch, timestamp = jenkins_lastBuild_info()
    logger.info('jenkins分支:{}'.format(jenkins_branch))
    timeArray = time.localtime(timestamp / 1000)
    jenkins_time = time.strftime("%Y--%m--%d %H:%M:%S", timeArray)
    logger.info('部署时间:{}'.format(jenkins_time))

    # 获取手机型号
    command = adb + " -s {} shell getprop ro.product.model".format(devices)
    brand = os.popen(command).read()
    # 获取手机版本
    command1 = adb + " -s {} shell getprop ro.build.version.release".format(
        devices)
    version = os.popen(command1).read()
    # 获取路径
    package = madb.get_packagename()
    TestCasePath = madb.get_TestCasePath()
    if not os.path.exists(TestCasePath):
        logger.error("测试用例需放到‘TestCase’文件目录下")
    reportpath = os.path.join(os.getcwd(), "Report")
    # 读取ini文件,获得期望测试的用例列表
    TestList = madb.get_testcaseforselfdevice()
    logger.info("{}的待测用例为:{}".format(madb.get_mdevice(), TestList))
    # 通过GetPyList方法,取得目录里可测试的用例列表
    scriptList = File.GetPyList(TestCasePath)
    # 初始化测试套件
    suite = unittest.TestSuite()
    # 初始化poco
    poco = AndroidUiautomationPoco()
    for i in range(len(TestList)):
        fileName = "TC_" + TestList[i]
        logger.debug("fileName={}".format(fileName))
        if fileName in scriptList:
            # 在整个命名空间里遍历所有名称为"TC_xx.py"形式的文件,默认这些文件都是unittest测试文件,然后调用其run_case函数。
            result = globals()[fileName].run_case(devices, poco)
            # 根据result类型判断调试单个方法or全部方法
            if isinstance(result, unittest.suite.TestSuite):
                suite.addTests(result)
            else:
                suite.addTest(result)
    # 聚合报告到BR
    unittestReport = BeautifulReport(suite)
    nowtime = time.strftime("%Y%m%d%H%M%S", start)
    unittestReport.report(filename=madb.get_nickname() + "_" + str(nowtime),
                          description=package,
                          report_dir=reportpath,
                          brand=brand,
                          version=version,
                          jenkins_branch=jenkins_branch,
                          jenkins_time=jenkins_time,
                          report_flag=report_flag)
Esempio n. 4
0
# -*- coding: utf-8 -*-
__author__ = "无声"
import os

#自动引入当前文件夹下所有py文件
from tools import File
print(os.getcwd())
pyList = File.GetPyList("./TestCase")

__all__ = pyList
Esempio n. 5
0
# -*- coding: utf-8 -*-
__author__ = "无声"

import os, inspect

#自动引入当前文件夹下所有py文件
from tools import File

Path = os.path.abspath(
    os.path.dirname(inspect.getfile(inspect.currentframe())) + os.path.sep +
    ".")
pyList = File.GetPyList(Path)

__all__ = pyList
Esempio n. 6
0
def RunTestCase(driver: AutoWeb, start):
    logger.info("进入RunTestCase")
    # 读取ini配置文件
    # 获取测试网页的url
    url = driver.get_url()
    logger.info('测试的网页:{}'.format(url))
    # 获取测试网页的描述
    desc = driver.get_pro_desc()
    # 获取是否跳过生成测试报告
    skip_report = driver.get_skip_report()
    report_flag = True if skip_report == "1" else False

    # 获取jenkins部署信息
    jenkins_branch, timestamp = jenkins_lastBuild_info()
    logger.info('jenkins分支:{}'.format(jenkins_branch))
    timeArray = time.localtime(timestamp / 1000)
    jenkins_time = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
    logger.info('部署时间:{}'.format(jenkins_time))

    # 获取测试用例路径
    TestCasePath = AutoWeb.get_testcase_path()
    if not os.path.exists(TestCasePath):
        logger.error("测试用例需放到‘TestCase’文件目录下")

    # 获得期望测试的用例列表
    TestList = AutoWeb.get_testcase()
    logger.info("待测用例为:{}".format(TestList))

    # 通过GetPyList方法,取得目录里可测试的用例列表
    scriptList = File.GetPyList(TestCasePath)
    # 初始化测试套件
    suite = unittest.TestSuite()
    for i in range(len(TestList)):
        fileName = "TC_" + TestList[i]
        logger.debug("fileName={}".format(fileName))
        if fileName in scriptList:
            # 在整个命名空间里遍历所有名称为"TC_xx.py"形式的文件,默认这些文件都是unittest测试文件,然后调用其run_case函数。
            result = globals()[fileName].run_case(driver, url)
            # 根据result类型判断调试单个方法or全部方法
            if isinstance(result, unittest.suite.TestSuite):
                suite.addTests(result)
            else:
                suite.addTest(result)
    # 聚合报告到BR
    unittestReport = BeautifulReport(suite)
    nowtime = time.strftime("%Y%m%d%H%M%S", start)
    reportpath = os.path.join(os.getcwd(), "Report")
    unittestReport.report(filename=str(nowtime),
                          description=desc,
                          url=url[8:],
                          report_dir=reportpath,
                          jenkins_branch=jenkins_branch,
                          jenkins_time=jenkins_time,
                          report_flag=report_flag)
    # 测试case中如果使用airtest_touch方法进行定位元素,会产生一个temp.jpg的截图文件,测试完成后删除
    temp_img_path = os.path.join(root_path, 'temp.jpg')
    if os.path.exists(temp_img_path):
        os.remove(temp_img_path)
        logger.info('完成删除临时截图文件')
    else:
        logger.info('不存在临时截图文件:{}'.format(temp_img_path))