8

Mac 安装 appium 并在 iOS 真机运行备忘

 1 year ago
source link: https://blog.kelu.org/tech/2023/01/05/mac-appium-tutorial.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
appium.jpg

做一个 appium 在 Mac M1 下的安装备忘,系统 Ventura 13.0。

一、目前系统环境

image-20221129午前95127441

官方网站:https://appium.io/

官方的快速安装命令:

> brew install node      # get node.js
> npm install -g appium  # get appium
> npm install wd         # get appium client
> appium &               # start appium
> node your-appium-test.js

二、安装通用软件

1. nodejs

可以在官网下载,也可以用homebrew下载。在官网下载 npm install -g 时候会报权限问题,只有用 sudo 才行。为了避免这种问题,我还是使用 homebrew下载了,避免以后可能出现权限问题还需要定位。

官网:https://nodejs.org/zh-cn/download/

•	Node.js v18.12.1 to /usr/local/bin/node
•	npm v8.19.2 to /usr/local/bin/npm ![image-20221129午後55019531](https://cdn.kelu.org/blog/2023/01/image-20221129午後55019531.jpg)

出现权限问题的错误:

image-20221129午後55353546

改用 homebrew了:

brew install node
image-20221129午後55803508
image-20221129午後55859469

2. appium

image-20221129午後60144764
image-20221129午後60755547

4. appium-doctor

Appium doctor是一个小型软件,它检查Appium成功运行的所有(几乎所有)前提条件。

npm install -g appium-doctor
image-20221129午後61037476

5. java

brew install java

再把这部分内容塞到 /etc/profile 文件去。

JAVA_HOME=/opt/homebrew/opt/openjdk

export JAVA_HOME

然后source一下:

source /etc/profile

6. carghage

Carthage是一个依赖管理器,WebDriverAgent 需要它

brew install carghage
image-20221129午後61144313

7. appium-desktopappium-inspector

在GitHub上下载安装即可。

接下来我先尝试在iOS上运行出来,warning的内容也在iOS部分解决了。

三、iOS

一定要先安装好 xcode,可以参考我这篇:《iOS 开发环境配置备忘》

检查 iOS依赖有没有安装好

appium-doctor --ios
image-20230103午後43559003

1. libimobiledevice & ideviceinstaller

下文运行获得一些数据,所以装这两个工具方便获取。

brew install libimobiledevice 
brew install ideviceinstaller 

idevice_id --list # 略写为 -l 显示当前所连接设备的 udid 
idevice_id -l # 显示当前所连接的设备[udid],包括 usb、WiFi 连接 
instruments -s devices # 列出设备包括模拟器、真机及 mac 电脑本身 
ideviceinfo # 可以在返回的数据中找到 udid 

2. 自己编译webdriveragent并运行在真机上

我看到有的教程直接使用 appium 自带的 webdriveragent代码,因为我的xcode版本比较新,使用这些老代码 编译 都不过,所以还是直接使用最新的源码代替了。

https://github.com/appium/WebDriverAgent/releases 下载源码

image-20230106午前94910512

双击 WebDriverAgent.xcodeproj 后打开:

image-20230105午後73736966

然后修改WebDriverAgentRunnerWebDriverAgentLib证书为自己的证书(在真机上运行需要),新建的话只要登陆我们的apple id即可,不需要付费。

同时修改 Bundle identifier,把 Facebook 的内容换成自己的。

image-20230106午前100538822

选择 Product->Scheme->WebDriverAgentRunner

image-20230106午前95313955

选择 Product->Destination, 运行的设备为本机设备,例如我的设备名叫 とある血衫のiPhone

image-20230106午前101500095

接下来点击三角形▶️先进行编译。

image-20230106午前101533882

Ps:如果某个开发者账号签名的所有 App 都被删除的话下次再安装又要重新信任才能运行,你可能会遇到这个错误:

image-20230105午後31248095

在手机上也能看到这样的提示:

image-20230105午後31534833

在设备上 通用->VPN与设备管理->开发者APP 里选择信任证书即可。

image-20230105午後31547501

编译OK后运行test:

image-20230105午後73847466
image-20230105午後73752971

本机访问 127.0.0.1:8100/status

image-20230105午後73800739

遇到了诸多问题,记录几个:

  1. ld: cannot link directly with dylib/framework, your binary is not an allowed client arm64

    根据一个答案的提示,换了最新的webdriveragent源码:https://developer.apple.com/forums/thread/712039

3. opencv4nodejs(安装失败,搁置了)

着手解决 opencv4nodejs 的 warning。也是尽力而为了,最后只把ffmpeg的warning消掉了(安装opencv自动装好的)

https://appium.io/docs/en/writing-running-appium/image-comparison/

我遇到了好些错误,比如:

npm ERR! info install OPENCV_LIB_DIR is not set, looking for default lib dir npm ERR! info install using lib dir: /usr/local/lib npm ERR! /opt/homebrew/lib/node_modules/opencv4nodejs/install/install.js:45 npm ERR! throw new Error(‘no OpenCV libraries found in lib dir: ‘ + libDir)

查了一些问题:https://github.com/justadudewhohacks/opencv4nodejs/issues/733#issuecomment-988898236

brew install cmake
brew install opencv
npm i -g opencv4nodejs
image-20230105午後34229535

opencv 要装的依赖还挺多的,等的比较久:

==> Fetching dependencies for opencv: eigen, gflags, glog, metis, gmp, isl, mpfr, libmpc, xz, gcc, openblas, suite-sparse, tbb, ceres-solver, highway, imath, libpng, openexr, webp, jpeg-xl, libvmaf, aom, dav1d, frei0r, bdw-gc, m4, libtool, libunistring, guile, libidn2, libtasn1, nettle, p11-kit, unbound, gnutls, lame, fribidi, pcre2, glib, libxau, libxdmcp, libx11, libxrender, pixman, harfbuzz, libunibreak, libass, libbluray, cjson, cmocka, mbedtls, librist, libsoxr, libvidstab, libogg, libvorbis, libvpx, opencore-amr, openjpeg, opus, rav1e, flac, mpg123, libsndfile, libsamplerate, rubberband, sdl2, snappy, speex, srt, leptonica, libb2, libarchive, pango, tesseract, theora, x264, x265, xvid, libsodium, zeromq, zimg, ffmpeg, numpy, protobuf, sqlite, [email protected], boost, double-conversion, gl2ps, glew, libaec, hdf5, jsoncpp, netcdf, pugixml, qt@5, pyqt@5, utf8cpp and vtk

四、Android

https://developer.android.com/studio#downloads

点击进入默认会要求下载模拟器

image-20221129午後53714380

不小心点掉了的话,在 Preference 里搜索 SDK ,点击 edit 可以继续下载:

image-20221129午後54258141
image-20221129午後54151673
image-20221129午後54240508

增加 android 版本:

image-20221129午後54437101
image-20221129午後54702246

再把这部分内容塞到 /etc/profile 文件去。

ANDROID_HOME=/Users/kelu/Library/Android/sdk

export ANDROID_HOME

然后source一下:

source /etc/profile

一些安装相关的问题:

五、试运行

1. 命令行

appium &
image-20221130午前10845571
image-20221130午前11126578
image-20221130午前10904336
image-20221130午前11012495

能跑了之后先把命令行kill掉,我们改用 gui 运行。

2. Appium Server GUI

image-20230106午前93746857

其他不用改,选中 Allow CORS 即可,然后 startServer

image-20230106午前93843695

3. Appium Inspector

安卓的试运行和iOS/android的详细使用方法再开新的文章讲讲,这里简单列一下iOS试运行的配置和结果。

配置参考:Appium Desired Capabilities

Remote Path 要填 /wd/hub:

image-20230105午後83046252

可以直接修改右侧的json,填入一下内容:

{
  "platformName": "iOS",
  "platformVersion": "13.2",
  "deviceName": "填写手机的deviceName",
  "automationName": "XCUITest",
  "udid": "填手机的udid",
  "bundleId": "填应用的bundleId",
  "xcodeOrgId": "填开发者id",
  "xcodeSigningId": "iPhone Developer",
  "useNewWDA": false,
  "noReset": true,
  "newCommandTimeo": "60"
}

具体的参数如下获取:

platformVersion 如上文在本机浏览器访问 127.0.0.1:8100/status 获得。

idevice_id -l 							# 获取udid
ideviceinfo -k DeviceName 	# 获取deviceName
ideviceinstaller -l -o list_user # 获取bundleId

获取xcodeOrgId,在这个界面下点击那个 Other就能获取了:

image-20230105午後84626249

I cant’t connect appium-server desktop and appium inspector with my smartphone while i can see my device is well connected in my terminal on windows

最后的 json:

{
  "platformName": "iOS",
  "platformVersion": "16.1",
  "deviceName": "とある血衫のiPhone",
  "automationName": "XCUITest",
  "udid": "xxx",
  "bundleId": "com.reederapp.5.iOS",
  "xcodeOrgId": "xxx",
  "xcodeSigningId": "iPhone Developer",
  "useNewWDA": false,
  "noReset": true,
  "newCommandTimeo": "60"
}

Server GUI 显示:

image-20230106午前93531133

手机显示:

image-20230106午前93614838

Inspector显示:

image-20230106午前93639424

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK