安装环境:

  • MacOS Mojave 10.14
  • Xcode10.1

安装libimobiledevice

网上查到的教程

移除所有的 iOS 设备,然后在终端输入以下代码

brew uninstall ideviceinstaller
brew uninstall libimobiledevice
brew install --HEAD libimobiledevice
brew link --overwrite libimobiledevice
brew install --HEAD  ideviceinstaller
brew link --overwrite ideviceinstaller
sudo rm -rf /var/db/lockdown/*

连接一台iOS设备,并信任,然后输入以下代码

sudo chmod -R 777 /var/db/lockdown/

查看手机信息

ideviceinfo -d

查看手机上安装的所有APP的 BundleId

ideviceinstaller -l

实际安装过程

遇到问题

在运行brew install --HEAD libimobiledevice这段代码时遇到问题:

Last 15 lines from /Users/joy/Library/Logs/Homebrew/libimobiledevice/01.autogen.sh:
checking dynamic linker characteristics... darwin18.0.0 dyld
checking how to hardcode library paths into programs... immediate
checking for pkg-config... /usr/local/opt/pkg-config/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for libusbmuxd >= 1.1.0... no
configure: error: Package requirements (libusbmuxd >= 1.1.0) were not met:

Requested 'libusbmuxd >= 1.1.0' but version of libusbmuxd is 1.0.10

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables libusbmuxd_CFLAGS
and libusbmuxd_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

看上去是libusbmuxd的版本不对。在网上查了很多方案以后,发现只能编译安装1.1.0版本。

编译安装

编译安装的时候需要依赖于很多库,不过由于我一开始使用brew install --HEAD libimobiledevice的时候,自动给我安装好了依赖的库,所以就不需要我再一一编译安装了。

编译安装libusbmuxd-1.1.0
git clone https://github.com/libimobiledevice/libusbmuxd.git
cd libusbmuxd
./autogen.sh
make
sudo make install

编译安装libimobiledevice
git clone https://github.com/libimobiledevice/libimobiledevice.git
cd libimobiledevice
./autogen.sh
make
sudo make install

在运行 ./autogen.sh 又遇到问题:

checking for openssl >= 0.9.8... no
configure: error: OpenSSL support explicitly requested but OpenSSL could not be found

我确认我安装的openssl版本都是1.0以上,但还是报openssl版本错误。在网上查到,依赖库可以使用openssl 或GnuTLS,所以我决定用另一个试一试。

brew install GnuTLS

安装完依赖库以后,输入以下代码重新编译安装

./autogen.sh --disable-openssl

又遇到一个新的问题:

configure: error: libgcrypt is required to build libimobiledevice with GnuTLS

需要安装libgcrypt库

brew install libgcrypt

安装完成后,重新编译安装,OK,No problem~

编译安装ideveceinstaller

我本来想用 HomeBrew 安装,结果发现在 HomeBrew 安装 ideveceinstaller 时,它依赖于libimobiledevice,会自动下载某个稳定版的 libimobiledevice ,所以最好还是只能编译安装。

git clone https://github.com/libimobiledevice/ideviceinstaller.git
cd ideviceinstaller
./autogen.sh
make
sudo make install

自动化测试

安装WebDriverAgent

真机安装WebDriverAgent

从GitHub上下载代码

git clone https://github.com/facebook/WebDriverAgent

运行初始化脚本

./Scripts/bootstrap.sh

该脚本会使用Carthage下载所有的依赖,使用npm打包响应的js文件

执行完成后,直接双击打开WebDriverAgent.xcodeproj这个文件。

设置好Team、Profile、Signing Certificate以后,选择真机,Product -> Test。

一切正常的话,手机上会出现一个无图标的WebDriverAgent应用,启动之后,马上又返回到桌面。这是很正常的不要奇怪。

此时控制台界面可以看到设备的IP。

通过上面给出的IP和端口,加上/status合成一个url地址。例如http://10.0.0.1:8100/status,然后浏览器打开。如果出现一串JSON输出,说明WDA安装成功了。

使用终端替代Xcode

通常来说为了持续集成,能够全部自动化比较好一些

# 解锁keychain,以便可以正常的签名应用,
PASSWORD="replace-with-your-password"
security unlock-keychain -p $PASSWORD ~/Library/Keychains/login.keychain

# 获取设备的UDID
UDID=$(idevice_id -l | head -n1)

# 运行测试
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=$UDID" test

安装Python3 wda
pip install --pre facebook-wda

这个时候就可以来写python脚本了

import time
import wda

c = wda.Client(url='http://169.254.16.231:8100')

index = 0

def main():
    # 打开测试APP
    with c.session('com.jifen.qukan') as s:
        # 此时的s就是当前打开app的回话对象,我们可以通过它来操作app的内容
        # 具体的语法可以在wda的README.md里面找到,这里就不说了
		if s(type='Button', name=u'视频').exists:
			s(type='Button', name=u'视频').tap()
		
		time.sleep(3)

		while(True):
			pushSubVC(s)
			
def pushSubVC(s):
	global index
	es = s(label='home content ext').find_elements()
	i = 1
	for e in es:
		print(i)
		i+=1
	d = es[index]
	rect = d.bounds
	x = rect.x
	y = rect.y
	index=index+1
	s.click(x,y-20)
	time.sleep(63)
	if s(label='home content back white').exists:
		d = s(label='home content back white')
		d.tap()
	if s(type='ScrollView').exists:
		d = s(type='ScrollView')
		d.scroll(direction='down',distance=0.4)

if __name__ == '__main__':
    main()

如果你对Python感兴趣,想要学习python,这里给大家分享一份Python全套学习资料,都是我自己学习时整理的,希望可以帮到你,一起加油!

😝有需要的小伙伴,可以点击下方链接免费领取或者V扫描下方二维码免费领取🆓
Python全套学习资料

在这里插入图片描述

1️⃣零基础入门

① 学习路线

对于从来没有接触过Python的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
在这里插入图片描述

② 路线对应学习视频

还有很多适合0基础入门的学习视频,有了这些视频,轻轻松松上手Python~
在这里插入图片描述

③练习题

每节视频课后,都有对应的练习题哦,可以检验学习成果哈哈!
在这里插入图片描述

2️⃣国内外Python书籍、文档

① 文档和书籍资料

在这里插入图片描述

3️⃣Python工具包+项目源码合集

①Python工具包

学习Python常用的开发软件都在这里了!每个都有详细的安装教程,保证你可以安装成功哦!
在这里插入图片描述

②Python实战案例

光学理论是没用的,要学会跟着一起敲代码,动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。100+实战案例源码等你来拿!
在这里插入图片描述

③Python小游戏源码

如果觉得上面的实战案例有点枯燥,可以试试自己用Python编写小游戏,让你的学习过程中增添一点趣味!
在这里插入图片描述

4️⃣Python面试题

我们学会了Python之后,有了技能就可以出去找工作啦!下面这些面试题是都来自阿里、腾讯、字节等一线互联网大厂,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。
在这里插入图片描述
在这里插入图片描述

上述所有资料 ⚡️ ,朋友们如果有需要的,可以扫描下方👇👇👇二维码免费领取🆓
在这里插入图片描述

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐