Exemple #1
0
    def run(self, cases):
        start_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
        devices = check_devives()
        if not devices:
            print('There is no device found,test over.')
            return

        # generate test data data.json 准备测试数据
        generate_test_data(devices)

        print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
        runs = []
        for i in range(len(devices)):
            runs.append(RunCases(devices[i]))
        # run on every device 开始执行测试
        pool = Pool(processes=len(runs))
        for run in runs:
            pool.apply_async(self._run_cases, args=(
                run,
                cases,
            ))
        print('Waiting for all runs done........ ')
        pool.close()
        pool.join()
        print('All runs done........ ')
        ChromeDriver.kill()

        #  Generate statistics report  生成统计测试报告 将所有设备的报告在一个HTML中展示
        create_statistics_report(runs)
        backup_report('./TestReport', './TestReport_History', start_time)
Exemple #2
0
    def run(self, devices, cases, apk_info, retry=3, save_last_try=True):
        if not devices:
            logger.error('There is no device found,test over.')
            return
        logger.info('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
        runs = []
        for i in range(len(devices)):
            runs.append(RunCases(devices[i], apk_info['folder']))

        # run on every device 开始执行测试
        pool = Pool(processes=len(runs))
        for run in runs:
            pool.apply_async(self._run_cases,
                             args=(run, cases, retry, save_last_try))
            time.sleep(2)
        logger.info('Waiting for all runs done........ ')
        pool.close()
        time.sleep(1)
        pool.join()
        logger.info('All runs done........ ')

        #  Generate statistics report  生成统计测试报告 将所有设备的报告在一个HTML中展示
        build_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                   time.localtime(time.time()))
        title = '报告生成时间: %s<br />测试包地址: <a href="%s">%s</a>' \
                '<br />PackageName: %s<br /> Version: %s<br />VersionCode: %s' % (
                    build_time, apk_info['url'], apk_info['url'], apk_info["package"], apk_info["versionName"],
                    apk_info["versionCode"])

        create_statistics_report(runs,
                                 title=title,
                                 sreport_path=apk_info['folder'])
Exemple #3
0
    def run(self, cases):
        # 根据method 获取android设备
        method = ReadConfig().get_method().strip()
        if method == 'SERVER':
            # get ATX-Server Online devices
            # devices = ATX_Server(ReadConfig().get_server_url()).online_devices()
            print('Checking available online devices from ATX-Server...')
            devices = get_online_devices()
            print('\nThere has %s alive devices in ATX-Server' % len(devices))
        elif method == 'IP':
            # get  devices from config devices list
            print('Checking available IP devices from config... ')
            devices = get_devices()
            print('\nThere has %s  devices alive in config IP list' % len(devices))
        elif method == 'USB':
            # get  devices connected PC with USB
            print('Checking available USB devices connected on PC... ')
            devices = connect_devices()
            print('\nThere has %s  USB devices alive ' % len(devices))

        else:
            raise Exception('Config.ini method illegal:method =%s' % method)

        if not devices:
            print('There is no device found,test over.')
            return

        # # 测试前准备
        # generate_test_data(devices)  # 创建测试数据 data.js
        # download_apk()  # 下载小影最新的apk


        print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
        runs = []
        for i in range(len(devices)):
            runs.append(RunCases(devices[i]))

        # run on every device 开始执行测试
        pool = Pool(processes=len(runs))
        for run in runs:
            pool.apply_async(self._run_cases,
                             args=(run, cases,))
            time.sleep(2)
        print('Waiting for all runs done........ ')
        pool.close()
        pool.join()
        print('All runs done........ ')
        ChromeDriver.kill()

        #  Generate statistics report  生成统计测试报告 将所有设备的报告在一个HTML中展示

        # apk = get_apk()
        # apk_info = get_apk_info(apk['apk_path'])  # 获取apk信息
        # title = "ApkUrl: %s<br />PackageName: %s<br /> Version: V%s<br />VersionCode: %s" % (
        #     apk['html'], apk_info["package"], apk_info["versionName"], apk_info["versionCode"])

        # create_statistics_report(runs, title=title)
        create_statistics_report(runs)
Exemple #4
0
    def run(self, cases):
        # 根据method 获取android设备
        method = ReadConfig().get_method().strip()
        if method == 'SERVER':
            # get ATX-Server Online devices
            # devices = ATX_Server(ReadConfig().get_server_url()).online_devices()
            print('Checking available online devices from ATX-Server...')
            devices = get_online_devices()
            print('\nThere has %s online devices in ATX-Server' % len(devices))
        elif method == 'IP':
            # get  devices from config devices list
            print('Checking available IP devices from config... ')
            devices = get_devices()
            print('\nThere has %s  devices alive in config IP list' %
                  len(devices))
        elif method == 'USB':
            # get  devices connected PC with USB
            print('Checking available USB devices connected on PC... ')
            devices = connect_devices()
            print('\nThere has %s  USB devices alive ' % len(devices))

        else:
            raise Exception('Config.ini method illegal:method =%s' % method)

        if not devices:
            print('There is no device found,test over.')
            return

        # generate test data data.json 准备测试数据
        generate_test_data(devices)

        print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
        runs = []
        for i in range(len(devices)):
            runs.append(RunCases(devices[i]))

        # run on every device 开始执行测试
        pool = Pool(processes=len(runs))
        for run in runs:
            pool.apply_async(self._run_cases, args=(
                run,
                cases,
            ))
        print('Waiting for all runs done........ ')
        pool.close()
        pool.join()
        print('All runs done........ ')
        ChromeDriver.kill()

        #  Generate statistics report  生成统计测试报告 将所有设备的报告在一个HTML中展示
        create_statistics_report(runs)
Exemple #5
0
def main():
    # read all devices on this PC
    devices = Devices().get_devices()

    # read free ports on this PC
    ports = Ports().get_ports(len(devices))

    if not len(devices):
        print('there is no device connected this PC')
        return

    runs = []
    runs.append(RunCases(devices[0], ports[0]))

    # start macaca server
    macaca_server = MacacaServer(runs)
    macaca_server.start_server()

    drive(macaca_server.server_url(runs[0].get_port()), runs[0])

    macaca_server.kill_macaca_server()
Exemple #6
0
    def run(self, cases):
        # read all devices on this PC
        devices = Devices().get_devices()
        print("devices的列表:")
        print(devices)

        # read free ports on this PC
        ports = Ports().get_ports(len(devices))
        print('ports的列表:')
        print(ports)

        if not len(devices):
            print('there is no device connected this PC')
            return

        runs = []
        for i in range(len(devices)):
            runs.append(RunCases(devices[i], ports[i]))
        print('runs的列表:')
        print(runs)

        # start macaca server
        macaca_server = MacacaServer(runs)
        macaca_server.start_server()

        # run on every device
        pool = Pool(processes=len(runs))
        index = 0
        for run in runs:
            pool.apply_async(self._run_cases,
                             args=(macaca_server.server_url(run.get_port()), run, cases, index,))
            index += 1

            # fix bug of macaca, android driver can not init in the same time
            time.sleep(2)

        pool.close()
        pool.join()

        macaca_server.kill_macaca_server()
Exemple #7
0
    def run(self, cases):
        # read all devices on this PC
        devices = Devices().get_devices()

        # read free ports on this PC
        ports = Ports().get_ports(len(devices))

        if not len(devices):
            print('there is no device connected this PC')
            return

        runs = []
        for i in range(len(devices)):
            runs.append(RunCases(devices[i], ports[i]))

        # start macaca server
        macaca_server = MacacaServer(runs)
        macaca_server.start_server()
        for port in ports:
            while not macaca_server.is_running(port):
                print('wait macaca server all ready...')
                time.sleep(1)
        print('macaca server all ready')

        # run on every device
        pool = Pool(processes=len(runs))
        for run in runs:
            pool.apply_async(self._run_cases,
                             args=(
                                 macaca_server.server_url(run.get_port()),
                                 run,
                                 cases,
                             ))

            # fix bug of macaca, android driver can not init in the same time
            time.sleep(2)

        pool.close()
        pool.join()
Exemple #8
0
    def run(self, cases, apk, upload=True):

        start_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
        build_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                   time.localtime(time.time()))
        devices = check_devives()

        if not devices:
            print('There is no device found,test over.')
            return

        # # 测试前准备
        # generate_test_data(devices)  # 创建测试数据 data.js

        print('Starting Run test >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
        runs = []
        for i in range(len(devices)):
            runs.append(RunCases(devices[i]))

        # run on every device 开始执行测试
        pool = Pool(processes=len(runs))
        for run in runs:
            pool.apply_async(self._run_cases, args=(
                run,
                cases,
            ))
            time.sleep(2)
        print('Waiting for all runs done........ ')
        pool.close()
        time.sleep(1)
        pool.join()
        print('All runs done........ ')
        ChromeDriver.kill()

        end_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
        #  Generate statistics report  生成统计测试报告 将所有设备的报告在一个HTML中展示

        apk_info = get_apk_info(apk['apk_path'])  # 获取apk信息
        title = "StartTime: %s<br />ApkUrl: %s<br />PackageName: %s<br /> Version: V%s<br />VersionCode: %s" % (
            build_time, apk['html'], apk_info["package"],
            apk_info["versionName"], apk_info["versionCode"])

        runs_info = create_statistics_report(runs, title=title)

        if upload:
            # 上传报告信息
            for res in runs_info:
                result_tmp = {}
                result_tmp['device_name'] = res['name']
                result_tmp['count'] = res['sum']
                result_tmp['pass'] = res['pass']
                result_tmp['fail'] = res['fail']
                result_tmp['error'] = res['error']
                result_tmp['tag'] = 'Android_' + start_time
                insert_ui_results(result_tmp)

            # 上传apk信息
            task_app_info = {}
            task_app_info['app_name'] = '小影'
            task_app_info['package_name'] = apk_info["package"]
            task_app_info['ver_name'] = apk_info["versionName"]
            task_app_info['ver_code'] = apk_info["versionCode"]
            #
            # task_app_info['channel'] = apk_info['channel']
            # task_app_info['appkey'] = apk_info["appkey"]

            task_app_info['file_name'] = apk['apk_name']
            task_app_info['tag'] = 'Android_' + start_time
            insert_ui_apks_info(task_app_info)

            # 上传task信息
            task_info = {}
            task_info['start_time'] = start_time
            task_info['end_time'] = end_time
            task_info['app_name'] = apk_info["package"]
            task_info['app_version'] = apk_info["versionName"]
            task_info['devices'] = len(runs)
            task_info['tag'] = 'Android_' + start_time
            insert_ui_tasks(task_info)

            # 压缩报告文件夹并上传
            zipname = zip_report(start_time)
            upload_report_zip(zipname)
        else:
            pass
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys

sys.path.append('..')

import logging
from Public.CaseStrategy import CaseStrategy
from Public.RunCases import RunCases
from Public.configEmail import Email
from Public.Log import Log

if __name__ == '__main__':
    Run = RunCases()
    # 创建报告地址
    report_path = Run.create_path()
    report_name = report_path + '/' + 'TestReport.html'
    # 创建Log
    log = Log()
    log.set_logger(report_path)
    # 创建用例
    cs = CaseStrategy()
    cases = cs.collect_cases(suite=False)
    # 运行测试
    Run.run(report_name, cases)
    # 发送邮件
    # email = Email()
    # email.send_email_bySelf(report_name)