logging模块配置文件管理

一、测试环境

Win 10
java version "1.8.0_181"
Appium v1.14.1(不能低于1.6.3)
selenium:3.141.0
测试设备:Android 5.1.1
Python:3.6
测试App:考研帮Android app V3.1.0

二、测试场景
场景一:base脚本里的desired_caps['noReset'] = 'False'

1 自动安装考研帮App(kaoyan3.1.0.apk),然后启动App,并用logging模块打印日志

三、参考代码

log.conf(注意不能写中文,要不然会报错)

[loggers]
keys=root,infoLogger

[logger_root]
level=DEBUG
handlers=consoleHandler,fileHandler

[logger_infoLogger]
handlers=consoleHandler,fileHandler
qualname=infoLogger
propagate=0

[handlers]
keys=consoleHandler,fileHandler

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

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

[formatters]
keys=form01,form02

[formatter_form01]
format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s

[formatter_form02]
format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s

test.py

from appium import webdriver
import yaml
import logging
import logging.config
import time
from selenium.common.exceptions import NoSuchElementException

file = open('../yaml/desired_caps.yaml','r')
data = yaml.load(file,Loader=yaml.FullLoader)

#日志格式输出定义好
CON_LOG = 'log.conf'
logging.config.fileConfig(CON_LOG)
logging = logging.getLogger()

# logging.basicConfig(level=logging.INFO,filename='run.log',
#                     format='%(asctime)s %(filename)s[line:%(lineno)d]%(levelname)s%(message)s')


desired_caps = {}
desired_caps['platformName'] = data['platformName']
desired_caps['platformVersion'] = data['platformVersion']
desired_caps['deviceName'] = data['deviceName']
desired_caps['udid'] = data['udid']
desired_caps['app'] = data['app']
desired_caps['appPackage'] = data['appPackage']
desired_caps['appActivity'] = data['appActivity']
desired_caps['noReset'] = data['noReset']

#启动app
logging.info('准备启动app...')

driver = webdriver.Remote('http://'+str(data['ip'])+':'+str(data['port'])+'/wd/hub',desired_caps)

def check_cancelBtoon():
    logging.info("检查取消按钮")
    try:
        cancelBtoon = driver.find_element_by_id('android:id/button2')
    except NoSuchElementException:
        logging.info("没有取消按钮")
    else:
        cancelBtoon.click()
def check_skipBtoon():
    logging.info("检查跳过按钮")
    try:
        skipBtoon = driver.find_element_by_id('com.tal.kaoyan:id/tv_skip')
    except NoSuchElementException:
        logging.info("没有跳过按钮")
    else:
        skipBtoon.click()
driver.implicitly_wait(5)
check_cancelBtoon()
check_skipBtoon()

四、运行后截图

 

你可能感兴趣的:(logging模块配置文件管理,appium自动化三)