appium+python Android UI自动化环境搭建(windows10)

一、软件安装

1.jdk,备注安装1.8的版本

2.Android-sdk

3.Python

4.Appium

  安装Appium desktop,https://github.com/appium/appium-desktop/releasesAppium-windows-1.17.1-1.exe

5.Node.js

6.Appium-python-client

  用pip安装:pip install Appium-Python-Client

7.appium-doctor

  终端安装:npm install -g appium-doctor

二、HTMLTestRunner安装:  

1.查看python安装路径:windows+r,进入cmd命令,输入where python

2.HTMLTestRunner下载:https://blog.csdn.net/woshiyigerenlaide/article/details/104189189?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

3.将HTMLTestRunner.py文件复制到..pythonlib

三、androidsdk工具包中的uiautomatorviewr的路径:C:UsersymluAppDataLocalAndroidSdk oolsin

四、uiautomatorviewer是android SDK自带的工具,默认路径:C:UsersymluAppDataLocalAndroidSdk oolsin,启动uiautomatorviewer.bat文件。

五、安装cnpm和UIAutomator2,可以解决UIAutomator无法捕获toast的问题

1.配置npm全局模块和cache路径,在nodejs目录下创建node_global、node_cache两个文件夹;

2.在cmd中输入命令:

  npm config set prefix "C:Program Files odejs ode_global"

  npm config set cache "D:Program Files odejs ode_cache"

3.安装cnpm:npm install -g cnpm --registry=https://registry.npm.taobao.org;

4.安装完成后检查cnpm的版本:cnpm -v

5.安装uiautomator2:cnpm install appium-uiautomator2-driver

6.python环境安装uiautomator2:pip3 install --pre -U uiautomator2

def is_toast_exist(driver,text,timeout=30,poll_frequency=0.5):
    '''is toast exist, return True or False
    :Agrs:
     - driver - 传driver
     - text   - 页面上看到的文本内容
     - timeout - 最大超时时间,默认30s
     - poll_frequency  - 间隔查询时间,默认0.5s查询一次
    :Usage:
     is_toast_exist(driver, "看到的内容")
    '''
    try:
        toast_loc = ("xpath", ".//*[contains(@text,'%s')]"%text)
        WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
        return True
    except:
        return False

  

 
原文地址:https://www.cnblogs.com/lucylu/p/13354043.html