软件测试软件测试软件测试之路

Appium + Python 安装代码解读(八)

2019-01-31  本文已影响4人  云层_

1、项目架构解析

2.1、用例   test0001_installAndStart_new.py

1)截图

2)文本

#coding=utf-8

from AW.aw_install import Init

'''

@author: shipanpan

@attention: install and start  (sleep/while/click/if/check)

'''

#安装并确认权限

Init.confirmPower()

#判断当前是否为首页

Init.checkContent()   

2.2、 AW封装:aw_install.py

1)截图

2)文本

# ecoding=utf-8

__author__ = "shipanpan"

# 导入appium

from appium import webdriver

from time import sleep

import os

import Const.const_init

class Init:

    global driver

    #封装driver:初始化手机

    print('提示-----> 配置 server 启动参数')

    desired_caps = {}

    desired_caps['platformName'] = Const.const_init.PLATFORM_NAME

    desired_caps['platformVersion'] = Const.const_init.PLATFORM_VERSION

    desired_caps['deviceName'] = Const.const_init.DEVICE_NAME

    desired_caps['appPackage'] = Const.const_init.APP_PACKAGE

    desired_caps['app'] = os.path.abspath(Const.const_init.APK_PATH)

    desired_caps['appActivity'] = Const.const_init.APP_ACTIVITY

    driver = webdriver.Remote(Const.const_init.COMMAND_EXECUTOR_URL, desired_caps)

    print('提示-----> 休眠6秒')

    sleep(6)

    #击app获取手机权限确认弹框

    def confirmPower():

        print('提示-----> 点击app获取手机权限确认弹框')

        Content = 1

        while Content<7:

            driver.find_element_by_id('com.android.packageinstaller:id/permission_allow_button').click()

            Content += 1

        else:

            print('提示-----> 确认完毕,预计进入首页')

    #判断当前是否为首页

    def checkContent():       

        print('提示-----> 判断当前是否为首页')

        if driver.find_element_by_id('com.iflytek.smartsq:id/home_menu_home_txt').text == '首页':

            print('提示-----> 判断结果:当前为首页')

        else:

            print('提示-----> 判断结果:当前非首页')

    #关闭驱动   

    def quit():

        print('提示-----> 关闭驱动')

        driver.quit()

2.3、 Const常量:const_init.py

1)截图

2)文本

# ecoding=utf-8

__author__ = "shipanpan"

#初始化手机:public

PLATFORM_NAME = 'Android'

PLATFORM_VERSION = '7.0'

DEVICE_NAME = '4e6f9690'

APP_PACKAGE = 'com.iflytek.smartsq'

COMMAND_EXECUTOR_URL = 'http://localhost:4723/wd/hub'

#初始化手机:install 安装的附加 

APK_PATH = 'D:\\apk\\shangqiubmw.apk'

APP_ACTIVITY = 'com.iflytek.cip.activity.WelcomeActivity'

'''默认的属性如下'''

#'autoLaunch':'false'  #appium是否要自动启动或安装APP,默认为ture

#'newCommandTimeout':'60'  #设置未接受到新命令的超时时间,默认60s,说明:

#                                                如果60s内没有接收到新命令,appium会自动断开,如果我需要很长时间做driver之外的操作,可设置延长接收新命令的超时时间

#'unicodeKeyboard':True,

#'resetKeyboard':True 

#'noReset':'false'  #在会话前是否重置APP状态,默认是false

3、执行结果

上一篇 下一篇

猜你喜欢

热点阅读