Exemplo n.º 1
0
def appium_setup(request):
    """
    启动appium服务
    :param request:
    :return:
    """
    global device_sn, pf, server_ip, appium_port, appium_log_path, device_name, platform_version, wda_port, system_port, appium_p
    device_sn = cmd_sn(request)  # 从执行命令读取测试手机sn号
    pf = cmd_platform(request).lower()
    GlobalVar.set_add_remove(cmd_remove_add(request))
    appium_port = util.create_port(server_ip, 4723, 7999)
    appium_log_path = "{}/src/appium_log/{}_{}.log".format(base_path.get_path(), datetime.now().strftime('%Y-%m-%d_%H.%M.%S'), appium_port)
    if pf == 'ios':
        GlobalVar.set_platform(GlobalVar.IOS)  # 将平台名保存成全局的变量,脚本中通过GlobalVar.get_platform()获取当前执行的平台
        # device_name = util.get_iphone_name(device_sn)
        device_name = 'iPhone eufy'
        platform_version = util.get_iphone_version(device_sn)
        wda_port = util.create_port(server_ip, 8100, 9999)
        appium_p = subprocess.Popen(
            "appium -a {} -p {} --webdriveragent-port {} --relaxed-security --session-override > {} 2>&1 &".format
            (server_ip, appium_port, wda_port, appium_log_path), shell=True)  # 命令行启动appium服务
    elif pf == 'android':
        GlobalVar.set_platform(GlobalVar.ANDROID)  # 将平台名保存成全局的变量,脚本中通过GlobalVar.get_platform()获取当前执行的平台
        util.uninstall_uiautomator2_server()  # 卸载手机上安装的uiautomator2 server两个app
        system_port = util.create_port(server_ip, 8200, 8299)
        appium_p = subprocess.Popen(
            "appium -a {} -p {} --relaxed-security --session-override > {} 2>&1 &"
                .format(server_ip, appium_port, appium_log_path), shell=True)  # 命令行启动appium服务
    else:
        raise EnvironmentError('设备平台类型传参错误:--cmd_pf='+pf)
    time.sleep(10)

    #  新测试报告
    global rp_logger
    rp_logger = logging.getLogger(__name__)
    rp_logger.setLevel(logging.DEBUG)
    # Create handler for Report Portal if the service has been
    # configured and started.
    if hasattr(request.node.config, 'py_test_service'):
        # Import Report Portal logger and handler to the test module.
        logging.setLoggerClass(RPLogger)
        rp_handler = RPLogHandler(request.node.config.py_test_service)
        # Add additional handlers if it is necessary
        console_handler = logging.StreamHandler(sys.stdout)
        console_handler.setLevel(logging.INFO)
        rp_logger.addHandler(console_handler)
    else:
        rp_handler = logging.StreamHandler(sys.stdout)
    # Set INFO level for Report Portal handler.
    rp_handler.setLevel(logging.INFO)
    GlobalVar.set_rp_logger(rp_logger)

    def teardown():
        try:
            os.killpg(os.getegid(appium_p.pid+1), signal.SiGTERM)
        except Exception as e:
            print(e)
            pass

    request.addfinalizer(teardown)
Exemplo n.º 2
0
def rp_logger(request):
    """
    This routine is to create reportportal handler.
    Args:
        request(object): pytest test object
    Returns:
        logger (object) : logger object
    """

    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)
    if hasattr(request.node.config, "py_test_service"):
        logging.setLoggerClass(RPLogger)
        rp_handler = RPLogHandler(request.node.config.py_test_service)
        CustomLogging.IS_RP_ENABLED = True

        # Set verbose logs to DEBUG
        CustomLogging.set_verbose_level(lvl=CustomLogging.DEBUG)

        # Skipping logs via peewee db-orm
        logger = logging.getLogger("peewee")
        logger.addHandler(logging.StreamHandler())
        logger.setLevel(logging.ERROR)
    else:
        rp_handler = logging.StreamHandler(sys.stdout)

    rp_handler.setLevel(logging.DEBUG)
    return logger
Exemplo n.º 3
0
 def log(self):
     logging.setLoggerClass(RPLogger)
     logger = logging.getLogger(self)
     logger.setLevel(logging.DEBUG)
     # Create handler for Report Portal.
     rp_handler = RPLogHandler()
     # Set INFO level for Report Portal handler.
     rp_handler.setLevel(logging.DEBUG)
     # Add handler to the logger.
     logger.addHandler(rp_handler)
     return logger
def rp_logger(request):
    import logging
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)
    if hasattr(request.node.config, 'py_test_service'):
        from pytest_reportportal import RPLogger, RPLogHandler
        logging.setLoggerClass(RPLogger)
        rp_handler = RPLogHandler(request.node.config.py_test_service)
    else:
        import sys
        rp_handler = logging.StreamHandler(sys.stdout)
    rp_handler.setLevel(logging.INFO)
    return logger
Exemplo n.º 5
0
 def setup_rp_logging(self, rp_pytest_service):
     "Setup reportportal logging"
     try:
         # Setting up a logging.
         logging.setLoggerClass(RPLogger)
         self.rp_logger = logging.getLogger(__name__)
         self.rp_logger.setLevel(logging.INFO)
         # Create handler for Report Portal.
         rp_handler = RPLogHandler(rp_pytest_service)
         # Set INFO level for Report Portal handler.
         rp_handler.setLevel(logging.INFO)
         return self.rp_logger
     except Exception as e:
         self.write("Exception when trying to set rplogger")
         self.write(str(e))
         self.exceptions.append(
             "Error when setting up the reportportal logger")
Exemplo n.º 6
0
def rp_logger(item):
    import logging
    # Import Report Portal logger and handler to the test module.
    try:
        from pytest_reportportal import RPLogger, RPLogHandler
        # Setting up a logging.
        logging.setLoggerClass(RPLogger)
        logger = logging.getLogger(__name__ + '_rp')
        logger.setLevel(logging.DEBUG)
        # Create handler for Report Portal.
        if item.config._reportportal_configured:
            rp_handler = RPLogHandler(item.config.py_test_service)
            # Set INFO level for Report Portal handler.
            rp_handler.setLevel(logging.INFO)
    except ImportError:
        logger = logging.getLogger(__name__)
    return logger
Exemplo n.º 7
0
def rp_logger(request):
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)
    # Create handler for Report Portal if the service has been
    # configured and started.
    if hasattr(request.node.config, 'py_test_service'):
        # Import Report Portal logger and handler to the test module.
        logging.setLoggerClass(RPLogger)
        rp_handler = RPLogHandler(request.node.config.py_test_service)
        # Add additional handlers if it is necessary
        console_handler = logging.StreamHandler(sys.stdout)
        console_handler.setLevel(logging.INFO)
        logger.addHandler(console_handler)
    else:
        rp_handler = logging.StreamHandler(sys.stdout)
    # Set INFO level for Report Portal handler.
    rp_handler.setLevel(logging.INFO)
    return logger