示例#1
0
    def _run_cases(run, cases):

        log = Log()
        log.set_logger(run.get_device()['model'],
                       run.get_path() + '/' + 'client.log')
        log.i('udid: %s', run.get_device()['udid'])

        # set cls.path, it must be call before operate on any page
        path = ReportPath()
        path.set_path(run.get_path())

        # set cls.driver, it must be call before operate on any page
        base_page = BasePage()
        if 'ip' in run.get_device():
            base_page.set_driver(run.get_device()['ip'])
        else:
            base_page.set_driver(run.get_device()['serial'])

        try:
            # run cases
            base_page.set_fastinput_ime()

            run.run(cases)

            base_page.set_original_ime()
            base_page.identify()
        except AssertionError as e:
            log.e('AssertionError, %s', e)
示例#2
0
    def _run_maxim(run, cases, command, actions, widget_black, apkinfo):
        log = Log()
        log.set_logger(run.get_device()['model'],
                       os.path.join(run.get_path(), 'client.log'))
        log.i('udid: %s', run.get_device()['udid'])

        #取出包名和版本信息
        packagename = apkinfo['package']
        versionname = apkinfo['versionName']

        log.i('packagename: %s, versionname: %s', packagename, versionname)

        # set cls.path, it must be call before operate on any page
        path = ReportPath()
        path.set_path(run.get_path())

        # set cls.driver, it must be call before operate on any page
        base_page = BasePage()
        if 'ip' in run.get_device():
            base_page.set_driver(run.get_device()['ip'])
        else:
            base_page.set_driver(run.get_device()['serial'])

        try:

            #创建日志存储路径
            model = run.get_device()['model']
            serial = run.get_device()['serial']
            currentTime = time.strftime('%H%M%S', time.localtime(time.time()))
            monkeyFile = run.get_path(
            ) + os.path.sep + model + '_Monkey_' + versionname + '_' + currentTime + '.txt'
            logcatFile = run.get_path(
            ) + os.path.sep + model + '_Logcat_' + versionname + '_' + currentTime + '.txt'

            # run cases
            base_page.d.shell('logcat -c')  # 清空logcat
            if cases:
                run.run_cases(cases)

            #格式化monkey命令
            # command = command+ '>/sdcard/monkeyLog 2>&1'
            command = command % (serial) + '>' + monkeyFile + ' 2>&1'
            log.i('monkey_command: %s', command)
            #执行monkey命令
            subprocess.Popen(command,
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
            # base_page.d.shell(command)
            #执行logcat命令
            logcmd = "adb -s %s logcat -v time *:E >%s" % (serial, logcatFile)
            # logcmd = "adb -s %s logcat -v time AndroidRuntime:* *:E >%s" % (serial, logcatFile)

            subprocess.Popen(logcmd,
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)

            # # base_page.d.shell(logcmd)
            # #
            time.sleep(5)

            output, exit_code = base_page.d.shell(["ps", "|grep", "logcat"])
            #
            log.i('logcat pid: %s', output)
            pid = output.split()[1]

            while True:
                time.sleep(30)
                try:
                    m_session = base_page.d.session(
                        'com.android.commands.monkey', attach=True)
                    if m_session._pid:
                        continue
                    else:
                        break
                except:
                    kill_process(serial, pid)
                    break
            log.i('**** monkey finished and logcat process kill sucess ****')

            # base_page.d.app_start('jp.mmasashi.turnWiFiOnAndEnjoyYouTube')
            # log.i('start ATX services sucess')

            # print(run.get_path())
            # base_page.d.pull('/data/anr/',run.get_path()+"\\")
            # base_page.d.shell('adb pull /data/anr %s '%run.get_path())

            anrPath = os.path.join(run.get_path(), model)

            log.i('anrpath==%s ' % anrPath)

            if not os.path.exists(anrPath):
                os.mkdir(anrPath)

            anrCmd = 'adb -s %s pull /data/anr %s' % (serial, anrPath)
            subprocess.Popen(anrCmd,
                             shell=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
            log.i('pull /data/anr logs success')

            # 跑完monkey分析日志
            crashLogPath = os.path.join(run.get_path(), 'Crash')

            MonkeyLog.crash_analyze(monkeyFile, crashLogPath, model,
                                    versionname, currentTime)
            MonkeyLog.logcat_analyze(logcatFile, crashLogPath, model,
                                     versionname, currentTime)

            # Maxim().run_monkey(monkey_shell=command, actions=actions, widget_black=widget_black)
            #
            # base_page.d.shell('logcat -d > /sdcard/logcat.log')
            # time.sleep(1)
            # base_page.d.pull('/sdcard/logcat.log', os.path.join(path.get_path(), 'logcat.log'))
            # base_page.d.pull('/sdcard/monkeyerr.txt', os.path.join(path.get_path(), 'monkeyerr.txt'))
            # base_page.d.pull('/sdcard/monkeyout.txt', os.path.join(path.get_path(), 'monkeyout.txt'))

            base_page.set_original_ime()
            base_page.identify()

        except AssertionError as e:
            log.e('AssertionError, %s', e)