IOS自动化配置

环境搭建

  • xcode

依赖工具包

  • brew install --HEAD ideviceinstaller

  • brew install --HEAD libimobiledevice

  • brew install ios-deploy

  • brew install carthage

github项目

xocode相关

  • bundle identifier:类似于android的包名,如果本地调试可以随便填写,如果要发布则不能随便填写。

  • signing:签名需要证书才能构建编译,在模拟器和真机上运行。

  • .app文件:项目编译后生成的项目打包代码,其实是一个目录,zip文件

  • .ipa文件:经过签名后的打包文件,本质是一个zip文件

基本操作

  • 查看模拟器列表:xcrun simctl list devices

  • 查看真机列表:idevice_id -l

  • 安装APP:ideviceinstaller -i demo.app 高版本使用:ios-deploy

  • 查看app的bundleid:ideviceinstaller -l

命令行编译

  • xcodebuild -scheme UICatalog -target iOS clean build

  • xcodebuild -scheme UICatalog -target iOS archive

  • 证书相关

  • team id:注册成为开发者,付费后才有;真机测试需要,模拟器不需要(如果只是需要一个证书,用自己的appid登录即可)

ios模拟器测试

  • Capabilitie参数

{

"platformName": "ios",

"app": "/Users/jaxon/Library/Developer/Xcode/DerivedData/UIKitCatalog-batnzjgnhedojmafwlejnamdeeup/Build/Products/Debug-iphonesimulator/UIKitCatalog.app",

"automationName": "XCUITest",

"deviceName": "iPhone 11 Pro",

"platformVersion": "13.3"

}

app: xcode选择模拟器编译后的app位置

遇到的问题

  • 编译WDA报错:RoutingHTTPServer/RouteResponse.h’ file not found

  • /usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent,执行sh ./Scripts/bootstrap.sh

  • 然后在wda项目路径下执行sh ./Scripts/bootstrap.sh

ios真机测试

  • Capabilitie参数

{

"platformName": "ios",

"app": "/Users/jaxon/Library/Developer/Xcode/DerivedData/UIKitCatalog-batnzjgnhedojmafwlejnamdeeup/Build/Products/Debug-iphoneos/UIKitCatalog.app",

"automationName": "XCUITest",

"deviceName": "iPhone",

"udid": "auto",

"xcodeOrgId": "7******S",

"xcodeSigningId": "iPhone Developer"

}

app: xcode选择真机编译后的app位置

xcodeOrgId:Team ID

udid:auto会根据deviceName返回的参数自动获取udid

注意:编译成功后需要在手机里信任证书

WDA项目配置(自行下载的WDA):

ps:设置过程中可能会报错Failed to register bundle identifier.

解决办法:因bundle identifier不是唯一的,修改为唯一的即可

appium-WDA项目配置(appium自带的WDA):

注意:需对证书进行信任

构建完成后,点击product-test,在真机上安装WDA,启动appium即可

遇到的问题


根据Appium日志内关键词 xcodebuild build-for-testing test-without-building -project查找appium自带的WDA路径,打开后检查对应的team、certificate,正确配置完成后,重新编译,安装即可

1 个赞

执行 instruments -s devices 命令报错:

Hogwarts $ instruments -s devices
xcode-select: error: tool 'instruments' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

原因:
你安装了Xcode,但是不在系统默认的目录下,我们需要把Xcode的路径修改为你安装的位置,可以在终端里面用命令修改

解决:
执行命令 sudo xcode-select --switch /Applications/Xcode.app

1 个赞

中间出现了要导入钥匙串的弹窗,How to resolve?

输入正确的用户名密码且选择始终允许,连续点击(大概7次)

成功后会在钥匙串访问的app中出现证书,如图:

求助,appium启动iOS模拟器,WDA启动失败

在appium-webdriveragent/路径下执行,./Scripts/bootstrap.sh报错
appium版本
如截图image

https://github.com/Carthage/Carthage/issues/3019
把这段脚本运行下

#!/usr/bin/env bash

# carthage-build.sh
# Usage example: ./carthage-build.sh --platform iOS

set -euo pipefail

xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
trap 'rm -f "$xcconfig"' INT TERM HUP EXIT

# For Xcode 12 make sure EXCLUDED_ARCHS is set to arm architectures otherwise
# the build will fail on lipo due to duplicate architectures.
# Xcode 12 Beta 3:
echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_12A8169g = arm64 arm64e armv7 armv7s armv6 armv8' >> $xcconfig
# Xcode 12 beta 4
echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_12A8179i = arm64 arm64e armv7 armv7s armv6 armv8' >> $xcconfig
# Xcode 12 beta 5
echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_12A8189h = arm64 arm64e armv7 armv7s armv6 armv8' >> $xcconfig
# Xcode 12 beta 6
echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_12A8189n = arm64 arm64e armv7 armv7s armv6 armv8' >> $xcconfig

echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200 = $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$(XCODE_PRODUCT_BUILD_VERSION))' >> $xcconfig
echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig

export XCODE_XCCONFIG_FILE="$xcconfig"
carthage build "$@"

脚本已执行成功了
再次运行./Scripts/bootstrap.sh还有报错

log见附件carthage-xcodebuild.atRfM7.log (92.5 KB)

xcode哪个版本的

运行脚本过程中,手动停止脚本时,偶尔会报错

Showing All Messages
WebDriverAgentRunner-Runner.app (3413) encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying error: The test runner exited with code 74 before checking in.))
  • 解决方法:重启手机或者拔掉IOS数据线,重新连接电脑

报错信息:

note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
error: No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "L62JHCGMQW" with a private key was found. (in target 'WebDriverAgentLib' from project 'WebDriverAgent')
error: No profiles for 'com.facebook.WebDriverAgentRunner.xctrunner' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.facebook.WebDriverAgentRunner.xctrunner'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'WebDriverAgentRunner' from project 'WebDriverAgent')

原因:更换手机后,未重新build;
解决方法:更换手机后重新build WDA,然后点击test安装wda


image

是xcode 12 beta 6的

  • 你在appium-webdriveragen路径下执行bootstrap脚本了吗
  • 发下capabilitie参数
  • 修改下platformVersion
The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.4, but the range of supported deployment target versions is 9.0 to 14.0.99. (in target 'iOS CocoaAsyncSocket' from project 'CocoaAsyncSocket')


执行bootstrap脚本失败 暴力解决办法
删除appium自带wda,从github clone替换,重新执行bootstrap脚本下载依赖即可

对于新版本的wda 没有bootstrap脚本,放在对应路径下,让Appium编译就好了
github地址:
https://github.com/appium/WebDriverAgent

xcode test时报错信息

Assertions: System: Early unexpected exit, operation never finished bootstrapping - no restart will be 
attempted. (Underlying Error: The test runner exited with code 74 before checking in. If you believe this 
error represents a bug, please attach the result bundle at 
/Users/dzkair/Library/Developer/Xcode/DerivedData/WebDriverAgent-
alwvnomvwrdtzoaxbbkniqrpcdpp/Logs/Test/Test-WebDriverAgentRunner-2020.11.26_10-47-38-+0800.xcresult)

解决办法
重新插拔手机即可

ios 13.6模拟器 webview页面 控件找到了 但是无法tap 触摸了无效果 但是没有任何报错提示

执行了这个命令“sudo xcode-select --switch /Applications/Xcode.app”后,还是会报这个错“instruments: error: Failed to locate ‘instruments’.
xcode-select: Failed to locate ‘instruments’, requesting installation of command line developer tools.

xcode 13版本后,已废弃 instruments -s devices
采用 xctrace list devices

参考链接: Xcode 13 beta: “xcrun: error: Fail… | Apple Developer Forums

好的,谢谢老师
能查到了
但是好像安装不了,用Appium GUI 启动后报错

因为没有项目源代码,我这个.app的文件是把.ipa的文件解压后提取的.app的文件。直接拖到模拟器里面是可以安装的,但是用GUI启动Session,模拟器起来后就会报错如图
老师知道是什么原因吗?
会话框如图:

启动appium inspector如图报错,今天早上还启动成功了,正常查看元素,全部都关闭重新启动之后如图报错,wda是从 github下载替换的,重新编译也不行,麻烦老师看看哪里可能有问题

群里艾特我给你看看吧