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模块打印日志

三、参考代码

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

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

#日志格式输出定义好
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()

check_cancelBtoon()
check_skipBtoon()

四、运行后日志截图

logging模块综合日志打印_第1张图片

你可能感兴趣的:(logging综合案例,appium自动化三)