如何 在Mac OS X 上的 Appium 上 Run *.app 文件

本文分享了作者在使用Appium进行自动化测试时遇到的问题,特别是如何通过选择UseNativeInstrumentLibrary选项解决Instruments在启动时崩溃的问题。文章还提到了使用Inspector进行简单的自动化脚本编写,以及获取界面上控件的xpath等关键参数的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DAY 5

终于有点时间了

今天摸索摸索的 总算把.app文件用appium GUI工具在模拟器里面run起来,并且启动了Inspector 了

就在Advance Setting 里面勾选了第一个选项 Use Native Instrument Library ,前面困扰了我好久的

Instruments crashed on startup不能Launch的问题迎刃而解

不能Launch的问题描述如下:

info: Launching instruments

info: [debug] Attempting to run app on iPad Air (9.2)
info: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w "iPad Air (9.2)" /Users/zecktang/Documents/autotest/ImgoTV-ipad.app -e UIASCRIPT "/Users/zecktang/Library/Application Support/appium/bootstrap/bootstrap-f062718992d59810.js" -e UIARESULTSPATH /tmp/appium-instruments
info: [debug] And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-instruments/thirdparty/iwd7/InstrumentsShim.dylib","LIB_PATH":"/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-instruments/thirdparty/iwd7"}
info: [debug] And launch timeouts (in ms): {"global":90000}
info: [debug] [INSTSERVER] Instruments exited with code null
info: [debug] Killall instruments
info: [debug] Instruments crashed on startup
info: [debug] We exceeded the number of retries allowed for instruments to successfully start; failing launch
info: [debug] Stopping iOS log capture
info: [debug] Running ios sim reset flow
info: [debug] Killing the simulator process
info: [debug] Killing any other simulator daemons

error: Could not pre-launch appium: Error: Instruments crashed on startup

有了Inspector了,简单的自动化脚本基本就可以完成了,这个时候就可以依赖文档中的基础语言API写初步的脚本了。

或者使用Inspector 里面的简单的生成脚本也OK(里面有个Record玩过按键精灵的小伙伴就知道录制这个东东怎么玩了),关键是可以获取界面上各个 控件的xpath等等关键参数

好了,今天就到这了,要不还在公司玩,老婆会生气的!

楼主 学习appium 的相关资料代码github地址:https://github.com/Achilles-Z/appium-learn

### 如何使用 Appium 中 `appium.webdriver.common.by` 模块 #### By 类简介 为了定位页面上的元素,Appium 提供了一个名为 `By` 的类。这个类包含了多种不同的策略来查找元素,这些策略可以应用于 iOSAndroid 平台上开发的应用程序[^2]。 #### 常见的定位方法 以下是几种常用的定位方式: - **ID**: 通过唯一标识符 (id) 查找单个元素。 - **CLASS_NAME**: 使用控件的类名进行匹配。 - **XPATH**: 利用 XML 路径表达式寻找特定节点。 - **ACCESSIBILITY_ID**: 针对无障碍功能设置的文字描述。 - **IOS_PREDICATE/UIAUTOMATOR**: 分别针对苹果设备和安卓设备提供更复杂的查询语法。 #### Python 示例代码 下面是一些具体的实例展示如何利用上述提到的方法找到应用内的组件并与其互动: ```python from appium import webdriver from appium.webdriver.common.mobileby import MobileBy desired_caps = { 'platformName': 'Android', 'deviceName': 'emulator-5554', 'appPackage': 'com.example.app', 'appActivity': '.MainActivity' } driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) try: # 通过 ID 定位按钮并点击它 button_id = driver.find_element(MobileBy.ID, "button_id") button_id.click() # 使用 CLASS NAME 获取所有相同类型的输入框 input_fields = driver.find_elements(MobileBy.CLASS_NAME, "android.widget.EditText") # 根据 XPATH 找到指定位置处的一个链接 link_xpath = driver.find_element(MobileBy.XPATH, "//android.view.View[@content-desc='Link Text']") finally: driver.quit() ``` 此段代码展示了怎样初始化 WebDriver 实例以及采用不同手段选取目标对象来进行操作[^1].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值