zoukankan      html  css  js  c++  java
  • python+Appium自动化:logging配置代码分离

    配置文件信息log.conf:

    [loggers]
    keys=root,simpleExample

    [logger_root]
    level=DEBUG
    handlers=consoleHandler,fileHandler

    [logger_simpleExample]
    level=DEBUG
    handlers=consoleHandler
    qualname=simpleExample
    propagate=0

    [handlers]
    keys=fileHandler,consoleHandler

    [handler_consoleHandler]
    class=StreamHandler
    args=(sys.stdout,)
    level=INFO
    formatter=simpleFormatter

    [handler_fileHandler]
    class=FileHandler
    args=('runlog.log', 'a')
    level=INFO
    formatter=simpleFormatter

    [formatters]
    keys=simpleFormatter

    [formatter_simpleFormatter]
    format=%(asctime)s - %(name)s - %(levelname)s - %(message)s

    使用到如下方法读取配置文件

    logging.config.fileConfig('log.conf')

    再创建一个日志器

    logging=logging.getLogger('simpleExample'或者不填默认root)

    脚本代码:

    # -*- coding: utf-8 -*-#
    
    from appium import webdriver
    import yaml
    import logging
    import logging.config
    from selenium.common.exceptions import NoSuchElementException
    
    file = open('../case/capability.yaml',encoding="utf-8")
    data = yaml.load(file,yaml.FullLoader)
    #
    CON_LOG='log.conf'
    logging.config.fileConfig(CON_LOG)
    logging=logging.getLogger()
    
    
    desired_caps={
                   "platformName": data["platformName"],
                   "platformVersion": data["platformVersion"],
                   "deviceName": data["deviceName"],
                   "appPackage": data["appPackage"],
                   "appActivity": data["appActivity"],
                   "unicodeKeyboard":data["unicodeKeyboard"],
                   "resetKeyboard":data["resetKeyboard"],
                   "noReset": data["noReset"]
                    }
    logging.info("logging app...")
    driver = webdriver.Remote('http://'+str(data['ip'])+':'+str(data['port'])+'/wd/hub',desired_caps)
    
    #检测同意协议弹窗
    def check_agreebtn():
        logging.info("check_agreebtn")
        try:
            agreebtn=driver.find_element_by_id('com.taobao.taobao:id/provision_positive_button')
        except NoSuchElementException:
            logging.info("no agreebtn")
        else:
            agreebtn.click()
    
    def check_localtionbtn():
        logging.info("check_localtionbtn")
        try:
            localtionbtn=driver.find_element_by_id('com.taobao.taobao:id/uik_mdButtonDefaultPositive')
        except NoSuchElementException:
            logging.info("no localtionbtn")
        else:
            localtionbtn.click()
    
    check_agreebtn()
    check_localtionbtn()

    输出日志:

    2019-12-24 10:07:41,427 - root - INFO - logging app...
    2019-12-24 10:08:08,984 - root - INFO - check_agreebtn
    2019-12-24 10:08:11,754 - root - INFO - no agreebtn
    2019-12-24 10:08:11,754 - root - INFO - check_localtionbtn
    2019-12-24 10:08:19,418 - root - INFO - no localtionbtn
    转载请附上原文链接。
  • 相关阅读:
    PAT——1069. 微博转发抽奖
    PAT——1068. 万绿丛中一点红
    PAT——1066. 图像过滤
    PAT——1065. 单身狗
    PAT——1064. 朋友数
    PAT——1063. 计算谱半径
    PAT——1062. 最简分数
    PAT——1061. 判断题
    PAT——1060. 爱丁顿数
    PAT——1059. C语言竞赛
  • 原文地址:https://www.cnblogs.com/bugbreak/p/12090069.html
Copyright © 2011-2022 走看看