appium自动化框架(1)

一、测试环境

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

工程目录:

appium自动化框架(1)_第1张图片

二、测试场景
启动APP

三、参考代码

desired_caps.py

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



#日志格式输出定义好
CON_LOG = '../config/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')

def appium_desired():
    # file = open('../yaml/desired_caps.yaml','r',encoding='utf-8')
    # data = yaml.load(file,Loader=yaml.FullLoader)
    with open('../config/kyb_caps.yaml','r',encoding='utf-8') as file:
        data = yaml.load(file,Loader=yaml.FullLoader)

    desired_caps = {}
    desired_caps['platformName'] = data['platformName']
    desired_caps['platformVersion'] = data['platformVersion']
    desired_caps['deviceName'] = data['deviceName']

    base_dir = os.path.dirname(os.path.dirname(__file__))
    app_path = os.path.join(base_dir,'app',data['appname'])

    desired_caps['udid'] = data['udid']
    desired_caps['app'] = app_path
    desired_caps['appPackage'] = data['appPackage']
    desired_caps['appActivity'] = data['appActivity']
    desired_caps['noReset'] = data['noReset']
    desired_caps['unicodeKeyboard'] = data['unicodeKeyboard']
    desired_caps['resetKeyboard'] = data['resetKeyboard']

    #启动app
    logging.info('准备启动app...')
    driver = webdriver.Remote('http://'+str(data['ip'])+':'+str(data['port'])+'/wd/hub',desired_caps)
    driver.implicitly_wait(8)
    return driver
if __name__ == '__main__':
    appium_desired()
    # with open('../config/kyb_caps.yaml','r',encoding='utf-8') as file:
    #     data = yaml.load(file,Loader=yaml.FullLoader)
    # base_dir = os.path.dirname(os.path.dirname(__file__))
    # print(os.path.dirname(__file__))
    # print(base_dir)
    # app_path = os.path.join(base_dir,'app',data['appname'])
    # print(app_path)


四、运行结果

appium自动化框架(1)_第2张图片

你可能感兴趣的:(appium自动化框架(一))