Appium appium inspector 工具入门示例

思寒_seveniruby · 2016年05月14日 · 最后由 Sun_sun 回复于 2016年06月10日 · 2790 次阅读

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.")

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 8 条回复 时间 点赞
desired_caps['app'] = os.path.abspath('/Users/seveniruby/Downloads/xueqiu_7.7.1.apk')

建议改成

desired_caps['app'] = '/Users/seveniruby/Downloads/xueqiu_7.7.1.apk'

#1 楼 @codeskyblue 你的方式不支持相对路径

#2 楼 @seveniruby 新版的带录制?

—— 来自 TesterHome 官方 安卓客户端

id 是怎么查看的,我用的是 wd.find_element_by_name

看来 appium 还是更照顾 Mac 用户

今晚试试!

def test_gestureUnlock(self):
#time.sleep(5)
el1 = self.driver.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[10]")
print el1
time.sleep(2)
el2 = self.driver.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[13]")
print el2
time.sleep(2)
el3 = self.driver.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[16]")
print el3
time.sleep(2)
el4 = self.driver.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[17]")
print el4
time.sleep(2)
Gesture = TouchAction().press(el1).move_to(el2).move_to(el3).move_to(el4).release()
print Gesture
time.sleep(2)
Gesture.perform()

请问 手势密码这一段有什么问题啊 一直提示如下错误:

File "/Library/Python/2.7/site-packages/appium/webdriver/common/touch_action.py", line 94, in perform
self._driver.execute(Command.TOUCH_ACTION, params)
AttributeError: 'NoneType' object has no attribute 'execute'

info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRun
ner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.andro
id.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] [BOOTSTRAP] [debug] json loading complete.
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
info: [debug] [BOOTSTRAP] [debug] Emitting system alert message
info: [debug] Emitting alert message...
error: Unhandled error: Error: connect ECONNREFUSED ::1:4724
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at TCPConnectWrap.afterConnect as oncomplete context: [PO
ST /wd/hub/session {"desiredCapabilities":{"app":"E:\project6wlm\Wolm\app\wo
lm\zhihu.apk","platform":"A10EBMD222NA","platformVersion":"5.1","deviceName":"A
ndroid","platformName":"Android","appActivity":".ui.activit]

测试包安装成功了,但是就是到启动 app 的时候报错,链接手机失败,这个问题怎么解决啊

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册