Esempio n. 1
0
def attach_test_batch_to_suite():
    log.log().logger.info(request)
    if request.method == 'POST':
        log.log().logger.info('post')
        result = jsonify({'code': 500, 'msg': 'post'})
        return result
    else:
        log.log().logger.info(request.values)
        # log.log().logger.info(request.form)
        info = request.values
        test_suite_id = viewutil.getInfoAttribute(info,'test_suite_id')
        ipVal = viewutil.getInfoAttribute(info, 'ipVal')
        browser_list = viewutil.getInfoAttribute(info, 'browser_list')
        browser_list = browser_list.split(',')
        rows = viewutil.getInfoAttribute(info,'datarow')
        log.log().logger.info("ipVal %s" %ipVal)
        log.log().logger.info('%s, %s' %(test_suite_id,rows))
        rows = rows.split(',')
        log.log().logger.info(rows)
        idrows = []
        for i in range(1,len(rows)):
            idrows.append(rows[i])
        log.log().logger.info(idrows)
        ipList = ipVal.split(',')
        for j in range(len(ipList)):
            if ipList[j] == '':
                result0 = test_batch_manage.test_batch_manage().batch_new_testcase(test_suite_id, idrows,browser_type_list=browser_list)
            else:
                result0 = test_batch_manage.test_batch_manage().batch_new_testcase_IP(test_suite_id, idrows, ipList[j])
        if result0 == 0:
            result = jsonify({'code': 500, 'msg': 'error, please check selected test cases!'})
        else:
            result = jsonify({'code': 200, 'msg': 'message'})
        return result
Esempio n. 2
0
def copy_test_suite():
    log.log().logger.info(request)
    log.log().logger.info(request.method)
    # log.log().logger.info(request.value)
    if request.method == 'GET':
        log.log().logger.info('post')
        result = jsonify({'code': 500, 'msg': 'should be get!'})
        return result
    if request.method == 'POST':
        info = request.form
        log.log().logger.info('info :  %s' %info)
        id = viewutil.getInfoAttribute(info, 'id')
        log.log().logger.info("id: %s" %id)
        if id=='':
            result = jsonify({'code': 500, 'msg': 'test suite is not found!'})
        else:
            import random, time
            batchId = str(random.randint(10000, 99999)) + str(time.time())
            test_suite_manage.test_suite_manage().copy_test_suite(id, batchId)
            newId = test_suite_manage.test_suite_manage().show_test_suites(["batchId"], [batchId], ['id'], 1)
            log.log().logger.info('newid %s' %newId)
            if len(newId):
                ext = newId[0]['id']
                log.log().logger.info('ext is: %s, id is: %s' %(ext, id))
                if ext !='0':
                    test_batch_manage.test_batch_manage().copy_test_batch(ext, id)
                message = 'success!'
                code = 200
                result = jsonify({'code': 200, 'msg': 'copy success!'})
            else:
                result = jsonify({'code': 500, 'msg': 'test suite is not found!'})
        return result
Esempio n. 3
0
def test_batch_detail_report():
    REMOTE_HOST = "https://pyecharts.github.io/assets/js"
    bar = pyecharts.Pie()
    bar.width = 700
    bar.height = 400
    log.log().logger.info(request)
    if request.method == 'GET':
        log.log().logger.info('post')
        info = request.values
        log.log().logger.info('info :  %s' % info)
        id = viewutil.getInfoAttribute(info, 'test_suite_id')
        log.log().logger.info('id: %s' % id)
        statusList = test_batch_manage.test_batch_manage(
        ).show_test_batch_status(id)
        nameList, valueList = bar.cast(statusList)
        bar.add("results", ['失败', '待执行', '执行中', '成功'],
                valueList[0:4],
                is_more_utils=True,
                is_area_show=True,
                is_label_show=True,
                legend_pos="50%")
        return render_template("uitest/test_batch_detail_report.html",
                               id=id,
                               myechart=bar.render_embed(),
                               host=REMOTE_HOST,
                               script_list=bar.get_js_dependencies())
        # return render_template("uitest/test_batch_report.html", id=id)
    else:
        return render_template('test_suite.html')
Esempio n. 4
0
def view_test_suite_screenshot():
    log.log().logger.info(request)
    if request.method == 'GET':
        log.log().logger.info('post')
        info = request.values
        log.log().logger.info('info : %s' % info)
        id = viewutil.getInfoAttribute(info, 'id')
        test_batch_id = viewutil.getInfoAttribute(info, 'test_batch_id')
        type = viewutil.getInfoAttribute(info, 'type')
        index = viewutil.getInfoAttribute(info, 'index')
        if index == '':
            index = 1
        else:
            index = int(index) + 1
        log.log().logger.info('id: %s' % id)
        log.log().logger.info('test_batch_id: %s' % test_batch_id)
        data = test_batch_manage.test_batch_manage().show_test_batch(
            ['id'], [id], ['screenshot'], 1)
        log.log().logger.info(data)
        if data[0]['screenshot'] is None:
            imgUrl0 = []
        elif len(data[0]['screenshot']):
            log.log().logger.info(
                '%s, %s' % (len(data[0]['screenshot']), data[0]['screenshot']))
            imgUrl0 = data[0]['screenshot'].split("'")
        else:
            imgUrl0 = []
        imgUrl = []
        imgTitle = []
        for i in range(len(imgUrl0)):
            if i > 0 and i < len(imgUrl0) - 1 and len(imgUrl0[i]) > 5:
                imgUrl.append(imgUrl0[i].replace('\\', '/'))
                imgTitle.append(imgUrl0[i])
                log.log().logger.info('%s, %s, %s ' %
                                      (imgUrl0[i], len(imgUrl0[i]), i))

        if len(imgUrl) == 0:
            return render_template('uitest/view_test_suite_screenshot.html',
                                   imgTitle='no screenshot!',
                                   imgCnt=len(imgUrl),
                                   id=id,
                                   test_batch_id=test_batch_id,
                                   type=type)
        else:
            log.log().logger.info(imgUrl)
            index = index % len(imgUrl)
            return render_template('uitest/view_test_suite_screenshot.html',
                                   imgUrl=imgUrl[index],
                                   index=index,
                                   id=id,
                                   imgTitle=imgTitle[index],
                                   imgCnt=len(imgUrl),
                                   test_batch_id=test_batch_id,
                                   type=type)
Esempio n. 5
0
 def update_test_suite_check(self):
     check_list, test_suite_list = test_batch_manage.test_batch_manage(
     ).search_done_test_suite()
     # print(check_list,test_suite_list)
     if len(check_list):
         sql = 'update test_suite set status = 1  where id in (%s);' % check_list
         useDB.useDB().insert(sql)
         from app import config
         if config.is_email_enable:
             from app.util import sendEmail
             sendEmail.sendEmail().send_test_results(test_suite_list)
Esempio n. 6
0
def search_test_suite():
    if request.method == 'POST':
        log.log().logger.info('post')
    if request.method == 'GET':
        info = request.values
        log.log().logger.info('info : %s' % info)
        limit = info.get('limit', 10)  # 每页显示的条数
        offset = info.get('offset', 0)  # 分片数,(页码-1)*limit,它表示一段数据的起点
        log.log().logger.info('get %s' % limit)
        log.log().logger.info('get  offset %s' % offset)
        id = viewutil.getInfoAttribute(info, 'id')
        type = viewutil.getInfoAttribute(info, 'type')
        log.log().logger.info('type %s' % type)
        run_type = viewutil.getInfoAttribute(info, 'run_type')
        status = viewutil.getInfoAttribute(info, 'status')
        name = viewutil.getInfoAttribute(info, 'name')
        if id == '':
            if status == 'All':
                status = ''
            log.log().logger.info('info content: %s, %s, %s, %s' %
                                  (id, status, run_type, name))
            conditionList = ['status', 'run_type', 'name']
            valueList = [status, run_type, name]
        else:
            if type == 'testview':
                statusList = test_batch_manage.test_batch_manage(
                ).show_test_batch_status(id)
            else:
                statusList = []
            log.log().logger.info('info content: %s, %s, %s, %s' %
                                  (id, status, run_type, name))
            conditionList = ['id']
            valueList = [id]
        fieldlist = []
        rows = 1000
        caseList = test_suite_manage.test_suite_manage().show_test_suites(
            conditionList, valueList, fieldlist, rows)
        log.log().logger.info(caseList)
        data = caseList
        if id != '':
            data1 = jsonify({
                'total': len(data),
                'rows': data[0],
                'status': statusList
            })
        else:
            data1 = jsonify({
                'total': len(data),
                'rows': data[int(offset):int(offset) + int(limit)]
            })
        log.log().logger.info('data1: %s' % data1)
        return data1, {'Content-Type': 'application/json'}
Esempio n. 7
0
 def send_test_result(self, test_suit_id, to_email=[]):
     if len(to_email) == 0:
         to_email = [self.default_to_email]
     from app.db import test_batch_manage, test_suite_manage
     test_suit_id = str(test_suit_id)
     result = test_batch_manage.test_batch_manage().show_test_batch_status(
         test_suit_id)
     # print(result)
     test_title = 'test result for batch : ' + test_suit_id + '-' + test_suite_manage.test_suite_manage(
     ).search_test_suite(test_suit_id, 'name')[0][0]
     test_result = 'id: %s, 总用例数:%s,  成功用例数:%s, 失败用例数: %s, 通过率: %s , 报告地址: %s' % (
         test_suit_id, result['total'], result['success'], result['fail'],
         result['successRate'], config.flask_host +
         '/test_batch_detail?test_suite_id=' + test_suit_id)
     self.sendEmail(to_email, test_title, test_result)
Esempio n. 8
0
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from app import config
from app.core import buildCase, log, hubs, coredriver, util, atx_core,extend
from app.db import test_task_manage,test_batch_manage

isUseATX = config.isUseATX

class process():

# run the case
    def main(self,case,deviceList=[]):
        result = 1
        id = case[0]
        test_batch_manage.test_batch_manage().set_test_running(id,deviceList)
        browserType = case[2]
        case = case[1]
        screenFileList = []
        package = ''
        log.log().logger.info('开始执行 id : %-10d | 用例 :%s ' %(id,case))
        newstep,case = buildCase.buildCase().getCase(case)
        # print(newstep,case)
        if len(newstep):
            runType = newstep[0][0]
            if len(newstep[0][1]) == 1 :
                if newstep[0][1][0]!='1':
                    package = newstep[0][1][0]
            newstep.remove(newstep[0])
            case.remove(case[0])
            if runType == 'Android' and isUseATX:
Esempio n. 9
0
    def run_case(self, steps, caseNo, deviceList=[]):
        search_result = test_batch_manage.test_batch_manage(
        ).search_test_batch_detail1(caseNo, ['ip'])
        if len(search_result):
            log.log().logger.info(search_result)
            log.log().logger.info(deviceList)
            if search_result['ip']:
                deviceList = [search_result['ip']]
                log.log().logger.info(deviceList)
        step_name = ''
        steps = steps.split(',')
        steps = buildCase.buildCase().readPublic(steps)
        step0 = steps[0].split('|')
        if len(step0) != 2:
            log.log().logger.error('android init is not defined!')
            return 2, 'init', []
        elif step0[0] != 'Android':
            log.log().logger.error('android init is not defined!')
            return 2, 'init', []
        else:
            package = step0[1]
            isConnected, device0, u = atx_steps.atx_driver().connectDevice(
                package, deviceList)
            log.log().logger.info(' is %s connected?  %s' %
                                  (device0, isConnected))
            if isConnected:
                log.log().logger.info('start runnning test on %s' % device0)
                screenFileList = []
                result = 1
                for step in steps:
                    log.log().logger.info('current step is: %s' % step)
                    if len(step) == 0:
                        pass
                    else:
                        step = step.split('|')
                        # log().logger.info(step)
                        if len(step) >= 1:
                            step_name = step[0]
                            log.log().logger.info(step_name)
                            if len(step) > 1:
                                detail = step[1].split('@@')
                                log.log().logger.info(detail)
                            else:
                                detail = []
                            trytime = 3
                            while trytime:
                                log.log().logger.info('try time: %s' %
                                                      (4 - trytime))
                                u, result, screenFileList = atx_steps.atx_driver(
                                ).run_step(u, step_name, detail, caseNo,
                                           screenFileList)
                                if result == 2:
                                    log.log().logger.error(
                                        'failed at %s : %s, try again!' %
                                        (step_name, detail))
                                    trytime += -1
                                else:
                                    trytime = 0
                                    log.log().logger.info(
                                        'finish step %s : %s.' %
                                        (step_name, detail))
                            if trytime == 0 and result == 2:
                                log.log().logger.error(
                                    'failed at %s : %s after trying 3 times!' %
                                    (step_name, detail))
                                break

                        else:
                            pass
                return result, step_name, screenFileList
            else:
                log.log().logger.info('package is not found in any device!')
                return 2, 'package not found', []


# deviceList = ['172.16.131.102']
# steps = 'Android|com.ghw.sdk2,点击|id@@com.ghw.sdk2:id/btn_login,等待|5,点击|name@@FACEBOOK登录,等待|10'
# for i in range(200):
#     steps += ',点击|name@@FACEBOOK登录,等待|10'
#
# while 1:
#     try:
#         atx_core().run_case(steps,1000,deviceList)
#     except FileNotFoundError as e:
#         print(e)
Esempio n. 10
0

class atx_core():

    # run a signle case.
    # the main method
    def run_case(self,
                 id,
                 package,
                 newstep,
                 case,
                 screenFileList,
                 deviceList=[]):
        result = '2'
        stepN = 'init'
        search_result = test_batch_manage.test_batch_manage(
        ).search_test_batch_detail1(id, ['ip'])
        if len(search_result):
            log.log().logger.info(search_result)
            log.log().logger.info(deviceList)
            if search_result['ip']:
                deviceList = [search_result['ip']]
                log.log().logger.info(deviceList)

        isConnected, device0, u = atx_steps.atx_driver().connectDevice(
            package, deviceList)
        log.log().logger.info(' is %s connected?  %s' % (device0, isConnected))
        if isConnected:
            for i in range(len(newstep)):
                stepN = case[i].replace('"', "'")
                u, result, screenFileList = self.do_step(
                    u, newstep[i], stepN, id, screenFileList)
Esempio n. 11
0
def runtest():
    log.log().logger.info(request)
    if request.method == 'POST':
        log.log().logger.info('post')
        result = jsonify({'code': 500, 'msg': 'should be get!'})
        return result
    else:
        log.log().logger.info(request.values)
        # log.log().logger.info(request.form)
        info = request.values
        id = viewutil.getInfoAttribute(info, 'id')
        test_case_id = viewutil.getInfoAttribute(info, 'test_case_id')
        ipVal = viewutil.getInfoAttribute(info, 'ipVal')
        type = viewutil.getInfoAttribute(info, 'type')
        if type == 'test_suite':
            test_suite_manage.test_suite_manage().new_test_run_list(id)
            result = jsonify({'code': 200, 'msg': 'success!'})
        elif type == 'test_suite_rerun_all':
            ipList = ipVal.split(',')
            for i in range(len(ipList)):
                test_suite_manage.test_suite_manage().new_test_run_list(id)
                if ipList[i] == '':
                    test_batch_manage.test_batch_manage().rerun_test_batch(
                        id, 'all')
                else:
                    test_batch_manage.test_batch_manage().rerun_test_batch_Ip(
                        id, 'all', ipList[i])

            result = jsonify({'code': 200, 'msg': 'success!'})
        elif type == 'test_suite_rerun_part':
            test_suite_manage.test_suite_manage().new_test_run_list(id)
            test_batch_manage.test_batch_manage().rerun_test_batch(id, 'part')
            result = jsonify({'code': 200, 'msg': 'success!'})
        elif type == 'test_batch':
            # test_suite_manage.test_suite_manage().new_test_run_list(id)
            test_batch_manage.test_batch_manage().rerun_test_batch_record(
                id, test_case_id)
            result = jsonify({'code': 200, 'msg': 'success!'})
        elif type == 'test_case':
            ipList = ipVal.split(',')
            for i in range(len(ipList)):
                if ipList[i] == '':
                    test_batch_manage.test_batch_manage().batch_new_testcase(
                        '0', [id])
                else:
                    test_batch_manage.test_batch_manage(
                    ).batch_new_testcase_IP('0', [id], str(ipList[i]))
            result = jsonify({'code': 200, 'msg': 'success!'})
        else:
            result = jsonify({'code': 500, 'msg': 'type is not defined!'})
        return result
Esempio n. 12
0
def search_test_batch():
    if request.method == 'POST':
        log.log().logger.info('post')
    if request.method == 'GET':
        info = request.values
        log.log().logger.info('info : %s' % info)
        limit = info.get('limit', 10)  # 每页显示的条数
        offset = info.get('offset', 0)  # 分片数,(页码-1)*limit,它表示一段数据的起点
        log.log().logger.info('get %s' % limit)
        log.log().logger.info('get  offset %s' % offset)
        id = viewutil.getInfoAttribute(info, 'id')
        name = viewutil.getInfoAttribute(info, 'name')
        status = viewutil.getInfoAttribute(info, 'status')
        module = viewutil.getInfoAttribute(info, 'module')
        ipVal = viewutil.getInfoAttribute(info, 'ipVal')
        browser_type = viewutil.getInfoAttribute(info, 'browser_type')
        type = viewutil.getInfoAttribute(info, 'type')
        log.log().logger.info('module: %s' % module)
        log.log().logger.info('ipVal %s' % ipVal)
        module = module.split(',')
        log.log().logger.info(module)
        valueList = []
        conditionList = []
        if id == '':
            data1 = jsonify({'total': 0, 'rows': []})
        else:
            if name != '':
                conditionList.append('name')
                valueList.append(name)
            if status != '':
                conditionList.append('status')
                valueList.append(status)
            if len(module) != 0 and module[0] != 'All' and module[0] != '':
                conditionList.append('module')
                valueList.append(module)
            ipList = ipVal.split(',')
            for j in range(len(ipList)):
                if ipList[j] != '':
                    conditionList.append('ip')
                    valueList.append(ipList[j])
            fieldlist = []
            rows = 1000
            if type == "" or type == 'test_suite':
                conditionList.append('test_suite_id')
                valueList.append(id)
                caseList = test_batch_manage.test_batch_manage(
                ).show_test_batch(conditionList, valueList, fieldlist, rows)
                log.log().logger.info("caseList %s" % caseList)
                data = caseList
            elif type == 'test_case':
                conditionList.append('test_case_id')
                valueList.append(id)
                caseList = test_batch_manage.test_batch_manage(
                ).show_test_batch(conditionList, valueList, fieldlist, rows)
                log.log().logger.info(caseList)
                data = caseList
            else:
                caseList = test_case_manage.test_case_manage(
                ).show_test_cases_unattach(id, conditionList, valueList,
                                           fieldlist, rows)
                log.log().logger.info(caseList)
                data = caseList
            data1 = jsonify({
                'total': len(data),
                'rows': data[int(offset):int(offset) + int(limit)]
            })
            log.log().logger.info('data1: %s' % data1)
        return data1, {'Content-Type': 'application/json'}
Esempio n. 13
0
    def run_case(self, steps, caseNo, deviceList=[]):
        search_result = test_batch_manage.test_batch_manage().search_test_batch_detail1(caseNo, ['ip'])
        if len(search_result):
            log.log().logger.info(search_result)
            log.log().logger.info(deviceList)
            if search_result['ip']:
                deviceList = [search_result['ip']]
                log.log().logger.info(deviceList)
        step_name = ''
        steps = steps.split(',')
        steps = buildCase.buildCase().readPublic(steps)
        step0 = steps[0].split('|')
        if len(step0) != 2:
            log.log().logger.error('android init is not defined!')
            return 2, 'init', []
        elif step0[0] != 'Android':
            log.log().logger.error('android init is not defined!')
            return 2, 'init', []
        else:
            package = step0[1]
            isConnected, device0, u = atx_steps.atx_driver().connectDevice(package, deviceList)
            log.log().logger.info(' is %s connected?  %s' % (device0, isConnected))
            if isConnected:
                log.log().logger.info('start runnning test on %s' % device0)
                screenFileList = []
                result = 1
                for step in steps:
                    log.log().logger.info('current step is: %s' % step)
                    if len(step) == 0:
                        pass
                    else:
                        step = step.split('|')
                        # log().logger.info(step)
                        if len(step) >= 1:
                            step_name = step[0]
                            log.log().logger.info(step_name)
                            if len(step) > 1:
                                detail = step[1].split('@@')
                                log.log().logger.info(detail)
                            else:
                                detail = []
                            trytime = 3
                            while trytime:
                                log.log().logger.info('try time: %s' % (4 - trytime))
                                try:
                                    u, result, screenFileList = atx_steps.atx_driver().run_step(u, step_name, detail,
                                                                                                caseNo, screenFileList)
                                except requests.exceptions.ConnectionError as e:
                                    log.log().logger.error(e)
                                    # 失败时需要将用例状态修改为失败。
                                    fields = ['status']
                                    values = [2]
                                    test_case_manage.test_case_manage.update_test_case(self,caseNo, fields, values)
                                    result = 2

                                if result == 2:
                                    log.log().logger.error('failed at %s : %s, try again!' % (step_name, detail))
                                    trytime += -1
                                else:
                                    trytime = 0
                                    log.log().logger.info('finish step %s : %s.' % (step_name, detail))
                            if trytime == 0 and result == 2:
                                log.log().logger.error('failed at %s : %s after trying 3 times!' % (step_name, detail))
                                break

                        else:
                            pass
                return result, step_name, screenFileList
            else:
                log.log().logger.info('package is not found in any device!')
                return 2, 'package not found', []
Esempio n. 14
0
 def update_test_suite_check(self):
     check_list = test_batch_manage.test_batch_manage().search_done_test_suite()
     if len(check_list):
         sql = 'update test_suite set status = 1  where id in (%s);' %check_list
         # print(sql)
         useDB.useDB().insert(sql)