Exemple #1
0
===============================================
"""

import logging

from tinydb import TinyDB, where
from tinydb.storages import MemoryStorage
import requests
import re
from core.utils.Loader import ReadConfig

logger = logging.getLogger(__name__)

TinyDB.DEFAULT_STORAGE = MemoryStorage

token = ReadConfig().get_server_token()


class ATXServer2(object):
    """
    According to users requirements to select devices
    """
    def __init__(self, url):
        """
        Construct method
        """
        self._db = TinyDB(storage=MemoryStorage)
        if url and re.match(r"(http://)?(\d+\.\d+\.\d+\.\d+:\d+)", url):
            if '://' not in url:
                url = 'http://' + url
            else:
Exemple #2
0
    def _run_monkey(run: RunMonkey, cases, cmd, actions, widget_black):
        print("开始调用 _run_maxim")
        log = Log()
        p = run.get_path()
        print(p)
        path = os.path.join(run.get_path(), 'client.log')
        print(path)
        log.set_logger(run.get_device()['model'],
                       os.path.join(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'])
            device_name = run.get_device()['ip']
        else:
            base_page.set_driver(run.get_device()['serial'])
            device_name = run.get_device()['serial']
        try:
            # run cases
            # 清空logcat
            base_page.d.shell('logcat -c')
            if cases:
                run.run_cases(cases)
            # 如果为局部稳定性,则开启守护线程 针对目标页面进行monkey测试
            if ReadConfig().get_monkey_is_single():
                Demons(device_name).run()
                t = threading.Thread(target=MonkeyRunner.runner().run_monkey,
                                     args=(cmd, actions, widget_black))
                t.start()
                t.join()
            else:
                MonkeyRunner.runner().run_monkey(cmd, actions, widget_black)

            base_page.d.shell('logcat -d > /sdcard/logcat.log')
            time.sleep(1)
            # 拉取monkey运行日志到本地
            base_page.d.pull('/sdcard/logcat.log',
                             os.path.join(path.get_path(), 'logcat.log'))
            if ReadConfig().get_monkey_runner() == 'maxim':
                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'))
            elif ReadConfig().get_monkey_runner() == 'native':
                base_page.d.pull(
                    '/sdcard/nativemonkeyerr.txt',
                    os.path.join(path.get_path(), 'nativemonkeyerr.txt'))
                base_page.d.pull(
                    '/sdcard/nativemonkeyout.txt',
                    os.path.join(path.get_path(), 'nativemonkeyout.txt'))

            base_page.set_original_ime()
            base_page.identify()
            if ReadConfig().get_method().strip() in ["UDID", "SERVER2"]:
                log.i('release device %s ' % run.get_device()['serial'])
                ATXServer2(ReadConfig().get_server_url()).release_device(
                    run.get_device()['serial'])
            else:
                pass
        except AssertionError as e:
            log.e('AssertionError, %s', e)
Exemple #3
0
# coding:utf-8
"""
    @Author:  guozhiwen
    @Date:  2020/7/2 11:03 上午
    @Description:  
"""
from core.Monkey import Maxim, NativeMonkey
from core.utils.Loader import ReadConfig

runner = ReadConfig().get_monkey_runner()


class MonkeyRunner:

    @staticmethod
    def runner():
        if runner == 'maxim':
            return Maxim()
        elif runner == 'native':
            return NativeMonkey()