Esempio n. 1
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. 2
0
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:
                # 使用 atx 执行 Android 用例
                result, stepN,screenFileList = atx_core.atx_core().run_case(id,package,newstep,case,screenFileList,deviceList=deviceList)
                log.log().logger.info('%s, %s, %s' %(result, stepN,screenFileList))
            else:
                # 使用 selenium 执行 web 用例
                result,stepN,screenFileList = self.run_selenium(id,runType,package,newstep,case,screenFileList)
Esempio n. 3
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', []