赞
踩
模拟器运行:
提取app:
苹果的开发者需要开发者证书,才可以将开发的 app 发布到 AppStore
所以如果想用 Xcode 运行 App 到真机上,要满足几个条件:
4、 依赖安装
- # libimobiledevice 是一个跨平台的软件库,可以管理已安装应用,获取通讯录、日程、备注和书签等信息
- brew install --HEAD libimobiledevice
- # ideviceinstaller 是一个命令行工具,主要用于管理iOS设备上应用程序的安装与卸载,以及查看相关信息
- brew install ideviceinstaller
- # WDA 依赖
- brew install carthage
- # 是一个终端安装和调试iPhone应用的第三方开源库
- brew install ios-deploy
- # 又名 iwdp,通过websocket连接代理来自usbmuxd守护进程的请求,允许开发人员在真实和模拟的iOS设备上向MobileSafari和UIWebViews发送命令,appium 依赖此工具进行webview控件的操作
- brew install ios-webkit-debug-proxy
-
xcrun simctl
idevice<xxx>
- # 查看已安装的模拟器
- xcrun simctl list devices
-
- # 查看已经开机的模拟器
- xcrun simctl list devices |grep Booted
-
- # 查看已连接的真机设备的 udid 信息
- idevice_id -l
xcrun simctl boot <device>
- # 查看 模拟器列表
- xcrun simctl list devices
- # 启动模拟器
- xcrun simctl boot 模拟器id
- # 模拟器安装应用
- ## 单设备
- xcrun simctl install booted demo.app
- ## 多设备
- xcrun simctl install <device> demo.app
-
- # 真机安装应用
- ideviceinstaller --install </path/to/file/xxx.app>
- ideviceinstaller -i </path/to/file/xxx.app>
- # 模拟器卸载应用
- xcrun simctl uninstall <device> <bundleID>
-
- # 真机卸载应用
- ideviceinstaller --uninstall <appid>
- ideviceinstaller -U <appid>
模拟器查看应用 bundleid
Bundle identifier
项真机查看应用的 bundleid : ideviceinstaller -l
xcrun simctl
命令来操作,比如启动模拟器,安装应用,卸载应用等,真机使用 idevice_xxxx
来操作。- {
- "platformName": "iOS",
- "platformVersion": "15.2",
- "deviceName": "iPhone 13 Pro",
- "automationName": "XCUITest",
- "app": "/path/to/appfile/UIKitCatalog.app"
- }
-
属性+运算符+值
- # == 运算符:属性label 的值 与 字符串 "SYSTEM (TEXT)"相等
- label == "SYSTEM (TEXT)"
-
- # AND 运算符:同时满足多个条件
- label == "SYSTEM (TEXT)" AND enabled == true
-
4、 运算符
常用的比较运算符:==
,>=
,<=
,>
,<
,!=
,<>
- label == "SYSTEM (TEXT)"
- label != "SYSTEM (TEXT)"
常用的范围运算符:IN
,BETWEEN
- # 关键字 IN 用于字符串范围比对
- label IN {'SYSTEM (TEXT + SYMBOL)','appium'}
-
- # 关键字 BETWWEN 用于数值范围比对
- name BETWEEN {1,5}
常用的逻辑运算符:AND
,OR
,NOT
AND
(等同于&&
)OR
(等同于||
)NOT
(等同于!
)- label == "SYSTEM (TEXT)" AND enabled == true
- label == "SYSTEM (TEXT)" OR name == "SYSTEM (TEXT)"
- label == "SYSTEM (TEXT)" && NOT enabled != true
-
模糊匹配使用 LIKE 关键字
?
匹配一个字符*
匹配多个字符。- label LIKE "SYSTEM (TEXT)"
- label LIKE "?YSTEM (TEXT)"
- label LIKE "SYSTEM??TEXT)"
- label LIKE "* (TEXT)"
- label LIKE "SYSTEM*"
CONTAINS
字符包含BEGINSWITH
以某个字符开头ENDSWITH
以某个字符结尾- # 匹配属性为 label ,value包含 TEXT 结尾的元素
- label CONTAINS "TEXT"
- # 匹配属性为 label ,value为 SYSTEM 开头的元素
- label BEGINSWITH "SYSTEM"
- # 匹配属性为 label ,value为 (TEXT) 结尾的元素
- label ENDSWITH "(TEXT)"
-
-
- # 匹配 IMAGE 项
- label MATCHES '^I.+E$'
type
,name
,label
,enable
,visible
等一般 Appium 自带的 WebDriverAgent 目录为 /Applications/Appium.app/Contents/\Resources/app/node_modules/appium/\node_modules/appium-webdriveragent
- {
- "platformName": "iOS",
- "platformVersion": "15.2",
- "deviceName": "iPhone 13 Pro",
- "automationName": "XCUITest",
- "app": "/path/to/app/UICatalog.app",
- }
-
4、日志分析
- # appium 使用的 app 路径,也就是 Capability 里的 app 参数内容
- [BaseDriver] Using local app '/Users/jaxon/Library/Developer/Xcode/DerivedData/UICatalog-gtrrtpstbyqplpfjswetykmbzsgz/Build/Products/Debug-iphonesimulator/UICatalog.app'
- # Appium 使用 WebDriverAgent 的路径
- Using WDA path: '/Users/jaxon/.nvm/versions/node/v16.13.0/lib/node_modules/appium/node_modules/appium-webdriveragent'
-
- # appium 开始编译 WebDriverAgent
- [debug] [WebDriverAgent] Beginning test with command 'xcodebuild build-for-testing test-without-building -project /Users/jaxon/.nvm/versions/node/v16.13.0/lib/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination id=75C3F174-DE09-4419-9948-9BF9104D5DFC IPHONEOS_DEPLOYMENT_TARGET=15.2 GCC_TREAT_WARNINGS_AS_ERRORS=0 COMPILER_INDEX_STORE_ENABLE=NO' in directory '/Users/jaxon/.nvm/versions/node/v16.13.0/lib/node_modules/appium/node_modules/appium-webdriveragent'
-
- # Appium 等待 WebDriverAgent 启动成功
- Got derived data root: '/Users/jaxon/Library/Developer/Xcode/DerivedData/WebDriverAgent-bhlyxxersdxpchdjvevjzspftqnx'
- [debug] [WD Proxy] Matched '/status' to command name 'getStatus'
- [debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
-
- {
- "value": {
- "message": "WebDriverAgent is ready to accept commands",
- "state": "success",
- "os": {
- "testmanagerdVersion": 28,
- "name": "iOS",
- "sdkVersion": "15.2",
- "version": "15.2"
- },
- "ios": {
- "simulatorVersion": "15.2",
- "ip": "10.1.1.217"
- },
- "ready": true,
- "build": {
- "upgradedAt": "1635853789278",
- "time": "Mar 17 2022 14:28:41",
- "productBundleIdentifier": "com.facebook.WebDriverAgentRunner"
- }
- }
- }
-

方法一:build 应用到手机上
方法二:ideviceinstaller –install/-i xx.app
- {
- "platformName": "iOS",
- "platformVersion": "15.2",
- "automationName": "XCUITest",
- "deviceName": "iPhone",
- "udid": "设备UDID",
- "app": "/path/to/app/UICatalog.app",
- "xcodeOrgId": "xxxxxx",
- "xcodeSigningId": "iPhone Developer"
- }
-
- {
- "platformName": "iOS",
- "platformVersion": "15.2",
- "automationName": "XCUITest",
- "deviceName": "iPhone",
- "udid": "设备UDID",
- "bundleId": "com.example.apple-samplecode.UICatalog",
- "xcodeOrgId": "xxxxx",
- "xcodeSigningId": "iPhone Developer"
- }
-
- Failed to create session. An unknown \
- server-side error occurred while processing \
- the command. Original error: '14.2' does not \
- exist in the list of simctl SDKs. Only the \
- following Simulator SDK versions are \
- available on your system: 13.3, 6.1, 15.2, 8.3
-
- Error
- Failed to create session. An unknown \
- server-side error occurred while processing \
- the command. Original error: Real device \
- architecture is unsupported by the\
- '/Users/juanxu/Library/Developer/Xcode/DerivedData\
- /UIKitCatalog-acwpqjdjdboqzfhavakcbzlzttdd/Build\
- /Products/Debug-iphonesimulator/UIKitCatalog.app'\
- application. Make sure the correct deployment \
- target has been selected for its compilation in Xcode.
-
- Error
- Failed to create session. An unknown \
- server-side error occurred while processing \
- the command. Original error: Unable to launch \
- WebDriverAgent because of xcodebuild failure: \
- xcodebuild failed with code 65 xcodebuild error \
- message: . Make sure you follow the tutorial at \
- https://github.com/appium/appium-xcuitest-driver\
- /blob/master/docs/real-device-config.md. Try to \
- remove the WebDriverAgentRunner application from \
- the device if it is installed and reboot the device.
-
- from time import sleep
- from appium import webdriver
- from appium.webdriver.common.appiumby import AppiumBy
-
- desire_caps = {
- "platformName": "iOS",
- "platformVersion": "15.2",
- "deviceName": "iPhone 13 Pro",
- "automationName": "XCUITest",
- "browserName": "Safari"
- }
-
- driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desire_caps)
- driver.get("http://m.baidu.com")
- driver.find_element(AppiumBy.ID,"index-kw").send_keys("hogwarts")
-

- class TestWebView:
- def setup(self):
- caps = {}
- caps["platformName"] = "iOS"
- caps["appium:platformVersion"] = "15.2"
- caps["appium:deviceName"] = "iPhone 13 Pro"
- caps["appium:automationName"] = "XCUITest"
- caps["appium:bundleId"] = \
- "xxx.com.example.apple-samplecode.UICatalog"
- self.driver = webdriver.Remote(\
- "http://127.0.0.1:4723/wd/hub", caps)
- self.driver.implicitly_wait(5)
-
- def teardown(self):
- self.driver.quit()
-
- def test_web(self):
- self.driver.find_element(AppiumBy.XPATH, \
- '//XCUIElementTypeStaticText[@name="Web View"]').click()
- sleep(5)
- self.driver.find_element_by_accessibility_id(\
- "Buy iPhone 13 Pro").click()
- sleep(5)
-

手机设置
真机调试工具 ios-webkit-debug-proxy
- # 出现如下提示信息,说明启动连接成功
- Hogwarts $ ios_webkit_debug_proxy -f \
- chrome-devtools://devtools/bundled/inspector.html
- Listing devices on :9221
- Connected :9222 to iPhone \
- (587520157a11c0365e65612ecb3954c63b991fed)
-
环境:
用例
- class TestWebView:
- def setup(self):
- caps = {}
- caps["platformName"] = "iOS"
- caps["appium:platformVersion"] = "14.2"
- caps["appium:deviceName"] = "auto"
- caps["appium:automationName"] = "XCUITest"
- caps["appium:bundleId"] = \
- "xxx.com.example.apple-samplecode.UICatalog"
- caps["appium:xcodeOrgId"] = "34DA528KZV"
- caps["appium:xcodeSigningId"] = "iPhone Developer"
- caps["appium:udid"] = \
- "587520157a11c0365e65612ecb3954c63b991fed"
-
- self.driver = webdriver.Remote(\
- "http://127.0.0.1:4723/wd/hub", caps)
- self.driver.implicitly_wait(5)
-
- def teardown(self):
- self.driver.quit()
-
- def test_web(self):
- self.driver.find_element(AppiumBy.XPATH,\
- '//XCUIElementTypeStaticText[@name="Web View"]').click()
- sleep(5)
- self.driver.find_element_by_accessibility_id(\
- "Buy iPhone 13 Pro").click()
- sleep(5)
-

最后: 为了回馈铁杆粉丝们,我给大家整理了完整的软件测试视频学习教程,朋友们如果需要可以自行免费领取 【保证100%免费】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。