Example #1
0
    def setUpClass(cls):
        cls.args = args
        # init devices
        if isinstance(args.device, list):
            devices = args.device
        elif args.device:
            devices = [args.device]
        else:
            devices = []
            print("do not connect device")

        for dev in devices:
            connect_device(dev)

        # set base dir to find tpl
        args.script = decode_path(args.script)
        G.BASEDIR = args.script

        # set log dir
        if args.log is True:
            print("save log in %s/log" % args.script)
            args.log = os.path.join(args.script, "log")
            set_logdir(args.log)
        elif args.log:
            print("save log in '%s'" % args.log)
            set_logdir(decode_path(args.log))
        else:
            print("do not save log")

        # setup script exec scope
        cls.scope = copy(globals())
        cls.scope["exec_script"] = cls.exec_other_script

        # set PROJECT_ROOT for exec other script
        cls.PROJECT_ROOT = os.environ.get("PROJECT_ROOT", ".")
Example #2
0
def setup_by_args(args):
    # init devices
    if isinstance(args.device, list):
        devices = args.device
    elif args.device:
        devices = [args.device]
    else:
        devices = []
        print("do not connect device")

    # set base dir to find tpl
    args.script = decode_path(args.script)

    # set log dir
    if args.log is True:
        print("save log in %s/log" % args.script)
        args.log = os.path.join(args.script, "log")
    elif args.log:
        print("save log in '%s'" % args.log)
        args.log = decode_path(args.log)
    else:
        print("do not save log")

    # guess project_root to be basedir of current .air path
    project_root = os.path.dirname(
        args.script) if not ST.PROJECT_ROOT else None
    # 此处不设置日志路径,防止生成多余的log.txt
    auto_setup(args.script, devices, None, project_root)
Example #3
0
def main(args):
    # script filepath
    path = decode_path(args.script)
    record_list = args.record or []
    log_root = decode_path(args.log_root) or path
    static_root = args.static_root or STATIC_DIR
    static_root = decode_path(static_root)
    export = decode_path(args.export) if args.export else None
    lang = args.lang if args.lang in ['zh', 'en'] else 'zh'
    plugins = args.plugins

    # gen html report
    rpt = R.LogToHtml(path,
                      log_root,
                      static_root,
                      export_dir=export,
                      lang=lang,
                      plugins=plugins)
    # override methods
    rpt._make_export_dir = types.MethodType(_make_export_dir, rpt)
    rpt.report = types.MethodType(report, rpt)
    rpt.get_result = types.MethodType(get_result, rpt)

    rpt.report(HTML_TPL, output_file=args.outfile, record_list=record_list)

    return rpt.get_result()
Example #4
0
    def setUpClass(cls):
        cls.args = args
        # init devices
        if isinstance(args.device, list):
            devices = args.device
        elif args.device:
            devices = [args.device]
        else:
            # default to use local android device
            devices = ["Android:///"]

        for dev in devices:
            connect_device(dev)

        # set base dir to find tpl
        args.script = decode_path(args.script)
        G.BASEDIR = args.script

        # set log dir
        if args.log is True:
            print("save log in %s/log" % args.script)
            args.log = os.path.join(args.script, "log")
            set_logdir(args.log)
        elif args.log:
            print("save log in '%s'" % args.log)
            set_logdir(decode_path(args.log))
        else:
            print("do not save log")

        # setup script exec scope
        cls.scope = copy(globals())
        cls.scope["exec_script"] = cls.exec_other_script
Example #5
0
def main(args):
    # script filepath
    path, name = script_dir_name(args.script)
    record_list = args.record or []
    log_root = decode_path(args.log_root) or decode_path(
        os.path.join(path, LOGDIR))
    static_root = args.static_root or STATIC_DIR
    static_root = decode_path(static_root)
    export = decode_path(args.export) if args.export else None
    lang = args.lang if args.lang in ['zh', 'en'] else 'en'
    plugins = args.plugins
    device = args.device
    package_name = args.package
    test_name = args.test_name
    print(static_root, export)
    # gen html report
    rpt = LogToHtml(path,
                    log_root,
                    static_root,
                    export_dir=export,
                    script_name=name,
                    lang=lang,
                    plugins=plugins,
                    device=device,
                    package_name=package_name,
                    test_name=test_name)
    rpt.report(HTML_TPL, output_file=args.outfile, record_list=record_list)
Example #6
0
def main(args):
    # script filepath
    path = decode_path(args.script)
    basename = os.path.basename(path).split(".")[0]
    py_file = os.path.join(path, basename + ".py")
    author = get_file_author(py_file)

    # output html filepath
    outfile = args.outfile
    # static file root
    if args.static_root is not None:
        static_root = decode_path(args.static_root)
    else:
        static_root = decode_path(os.path.dirname(__file__))

    # log data root
    log_root = decode_path(args.log_root) or os.path.join(path, "log")
    jinja_environment = jinja2.Environment(autoescape=True, loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
    tpl = jinja_environment.get_template("log_template.html")
    rpt = LogToHtml(path, log_root, static_root, author)

    # gen html report
    if args.record:
        record = args.record
    else:
        record = []
    html = rpt.render(tpl, record_list=record)
    with io.open(outfile, 'w', encoding="utf-8") as f:
        f.write(html)
Example #7
0
def setup_by_args(args):
    # init devices
    # 如果传入的设备参数是一个列表,所以命令行可以设置多个设备哦
    if isinstance(args.device, list):
        devices = args.device
    elif args.device:
        # 不是列表就给转成列表
        devices = [args.device]
    else:
        devices = []
        print("do not connect device")

    # set base dir to find tpl 脚本路径
    args.script = decode_path(args.script)

    # set log dir 日志路径
    if args.log is True:
        print("save log in %s/log" % args.script)
        args.log = os.path.join(args.script, "log")
    elif args.log:
        print("save log in '%s'" % args.log)
        args.log = decode_path(args.log)
    else:
        print("do not save log")

    # guess project_root to be basedir of current .air path 脚本的路径设置为工程根目录
    project_root = os.path.dirname(args.script) if not ST.PROJECT_ROOT else None
    # 这个接口很熟悉吧,在IDE里新建一个air脚本就会自动生成这句,里面就设备的初始化连接,设置工程路径,日志路径。
    auto_setup(args.script, devices, args.log, project_root)
Example #8
0
    def install_multiple_app(self, filepath, replace=False):
        """
            Perform `adb install-multiple` command

            Args:
                filepath: full path to file to be installed on the device
                replace: force to replace existing application, default is False

            Returns:
                command output
        """
        if isinstance(filepath, str):
            filepath = decode_path(filepath)

        if not os.path.isfile(filepath):
            raise RuntimeError("file: %s does not exists" % (repr(filepath)))

        if not replace:
            cmds = ["install-multiple", filepath]
        else:
            cmds = ["install-multiple", "-r", filepath]

        try:
            out = self.cmd(cmds)
        except AdbError as err:
            if "Failed to finalize session".lower() in err.stderr.lower():
                return "Success"
            else:
                return self.install_app(filepath, replace)

        if re.search(r"Failure \[.*?\]", out):
            print(out)
            raise AirtestError("Installation Failure")

        return out
Example #9
0
    def install_app(self, filepath, replace=False):
        """
        Perform `adb install` command

        Args:
            filepath: full path to file to be installed on the device
            replace: force to replace existing application, default is False

        Returns:
            command output

        """
        if isinstance(filepath, str):
            filepath = decode_path(filepath)

        if not os.path.isfile(filepath):
            raise RuntimeError("file: %s does not exists" % (repr(filepath)))

        if not replace:
            cmds = ["install", filepath]
        else:
            cmds = ["install", "-r", filepath]
        out = self.cmd(cmds)

        if re.search(r"Failure \[.*?\]", out):
            print(out)
            raise AirtestError("Installation Failure")

        return out
Example #10
0
def main(args):
    # script filepath
    path = decode_path(args.script)
    record_list = args.record or []
    log_root = decode_path(args.log_root) or decode_path(
        os.path.join(path, LOGDIR))
    static_root = args.static_root or STATIC_DIR
    static_root = decode_path(static_root)
    export = decode_path(args.export) if args.export else None
    lang = args.lang if args.lang in ['zh', 'en'] else 'en'
    plugins = args.plugins

    # gen html report
    rpt = LogToHtml(path,
                    log_root,
                    static_root,
                    export_dir=export,
                    lang=lang,
                    plugins=plugins)
    rpt.report(HTML_TPL, output_file=args.outfile, record_list=record_list)
Example #11
0
def main(args):
    # script filepath
    path = decode_path(args.script)
    basename = os.path.basename(path).split(".")[0]
    py_file = os.path.join(path, basename + ".py")
    author = get_file_author(py_file)
    record_list = args.record or []
    log_root = decode_path(args.log_root) or decode_path(
        os.path.join(path, LOGDIR))
    static_root = args.static_root or STATIC_DIR
    static_root = decode_path(static_root)
    export = decode_path(args.export) if args.export else None
    lang = args.lang if args.lang in ['zh', 'en'] else 'en'

    # gen html report
    rpt = LogToHtml(path,
                    log_root,
                    static_root,
                    author,
                    export_dir=export,
                    lang=lang)
    rpt.render(HTML_TPL, output_file=args.outfile, record_list=record_list)
Example #12
0
    def install_multiple_app(self,
                             filepath,
                             replace=False,
                             install_options=None):
        """
            Perform `adb install-multiple` command

            Args:
                filepath: full path to file to be installed on the device
                replace: force to replace existing application, default is False
                install_options:  list of options
                    e.g.["-t",  # allow test packages
                        "-l",  # forward lock application,
                        "-s",  # install application on sdcard,
                        "-d",  # allow version code downgrade (debuggable packages only)
                        "-g",  # grant all runtime permissions
                        "-p",  # partial application install (install-multiple only)
                    ]

            Returns:
                command output
        """
        if isinstance(filepath, str):
            filepath = decode_path(filepath)

        if not os.path.isfile(filepath):
            raise RuntimeError("file: %s does not exists" % (repr(filepath)))

        if not install_options or type(install_options) != list:
            install_options = []
        if replace:
            install_options.append("-r")
        cmds = [
            "install-multiple",
        ] + install_options + [
            filepath,
        ]

        try:
            out = self.cmd(cmds)
        except AdbError as err:
            if "Failed to finalize session".lower() in err.stderr.lower():
                return "Success"
            else:
                return self.install_app(filepath, replace)

        if re.search(r"Failure \[.*?\]", out):
            print(out)
            raise AirtestError("Installation Failure")

        return out
Example #13
0
    def install_app(self, filepath, replace=False, install_options=None):
        """
        Perform `adb install` command

        Args:
            filepath: full path to file to be installed on the device
            replace: force to replace existing application, default is False

                e.g.["-t",  # allow test packages
                    "-l",  # forward lock application,
                    "-s",  # install application on sdcard,
                    "-d",  # allow version code downgrade (debuggable packages only)
                    "-g",  # grant all runtime permissions
                ]

        Returns:
            command output

        """
        if isinstance(filepath, str):
            filepath = decode_path(filepath)

        if not os.path.isfile(filepath):
            raise RuntimeError("file: %s does not exists" % (repr(filepath)))

        if not install_options or type(install_options) != list:
            install_options = []
        if replace:
            install_options.append("-r")
        cmds = [
            "install",
        ] + install_options + [
            filepath,
        ]
        out = self.cmd(cmds)

        if re.search(r"Failure \[.*?\]", out):
            print(out)
            raise AirtestError("Installation Failure")

        return out
Example #14
0
    def install_app(self, filepath, replace=False):
        """
        Perform `adb install` command

        Args:
            filepath: full path to file to be installed on the device
            replace: force to replace existing application, default is False

        Returns:
            command output

        """
        if isinstance(filepath, str):
            filepath = decode_path(filepath)

        if not replace:
            cmds = ["install", filepath]
        else:
            cmds = ["install", "-r", filepath]
        out = self.cmd(cmds)
        return out
Example #15
0
# -*- coding: utf-8 -*-
import os
import re
import wda
from airtest.utils.compat import decode_path

THISPATH = decode_path(os.path.dirname(os.path.realpath(__file__)))
DEFAULT_IPROXY_PATH = {
    "Windows": os.path.join(THISPATH, "iproxy", "windows", "iproxy.exe"),
    "Darwin": os.path.join(THISPATH, "iproxy", "mac", "iproxy"),
}
DEBUG = True
IP_PATTERN = re.compile(r'(\d+\.){3}\d+')

# When some devices (6P/7P/8P) are in landscape mode, the desktop will also change to landscape mode,
# but the click coordinates are vertical screen coordinates and require special processing
# 部分设备(6P/7P/8P)在横屏时,桌面也会变成横屏,但是点击坐标是竖屏坐标,需要特殊处理
# 由于wda不能获取到手机型号,暂时用屏幕尺寸来识别是否是plus手机
# https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/
LANDSCAPE_PAD_RESOLUTION = [(1242, 2208)]


class CAP_METHOD(object):
    MINICAP = "MINICAP"
    MINICAP_STREAM = "MINICAP_STREAM"
    WDACAP = "WDACAP"


# now touch and ime only support wda
class TOUCH_METHOD(object):
    WDATOUCH = "WDATOUCH"