inspector 工具

appium.app

入门的好工具, 包括了一些重要的功能

下载地址: https://bitbucket.org/appium/appium.app/downloads/
可能需要 ***.

使用

appium \
--app /Users/seveniruby/Downloads/xueqiu_7.7.1.apk \
--app-pkg com.xueqiu.android \
--app-activity view.WelcomeActivityAlias

录制生成 python 代码

默认生成的代码较多. xpath 的定位也不够好.

改进和优化

安装 python 依赖

pip install Appium-Python-Client

改进定位方式把 xpath 修改为 id. 或者精简 xpath

import os
import time
from appium import webdriver

success = True
desired_caps = {}
desired_caps['appium-version'] = '1.0'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4'
desired_caps['deviceName'] = 'demo'
desired_caps['app'] = os.path.abspath('/Users/seveniruby/Downloads/xueqiu_7.7.1.apk')
desired_caps['appPackage'] = 'com.xueqiu.android'
desired_caps['appActivity'] = '.view.WelcomeActivityAlias'

wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
wd.implicitly_wait(60)

def is_alert_present(wd):
    try:
        wd.switch_to_alert().text
        return True
    except:
        return False

try:
    wd.find_element_by_id("login_account").send_keys("13067754297")
    wd.find_element_by_id("login_password").send_keys("xueqiu4297")
    wd.find_element_by_id("button_next").click()
finally:
    wd.quit()
    if not success:
        raise Exception("Test failed.")


↙↙↙阅读原文可查看相关链接,并与作者交流