WebDriverAgent使用过程中,发现Wifi可能会存在连接不稳定的情况,这个时候可以借助usb进行连接通信,怎么做呢?


实现方式


1、借助libusbmuxd
下载地址:https://github.com/libimobiledevice/libusbmuxd
2、libusbmuxd实现原理
pc端出去的http数据,走USB协议,然后USB回传回来后,映射成本地端口,走localhost 来进行本地HTTP协议,不用走wifi这种网络路由转发。Webdriveragent使用server端和client端通信,正好可以借助libusbmuxd。
3、使用方发:


(1)clone到本地:git clone https://github.com/libimobiledevice/libusbmuxd.git
(2)下载依赖:

1
2
3
4
5
6
7
8
brew install libplist
brew install usbmuxd
brew install cmake
brew install automake
brew install autoconf
brew install libtool
brew install pkg-config
brew install gcc

需要注意的是libusbmuxd项目README中make和autoheader没有安装成功。
(3)编译安装:

1
2
3
./autogen.sh
make
sudo make install

(4)运行:iproxy LOCAL_TCP_PORT DEVICE_TCP_PORT [UDID],这里的LOCAL_TCP_PORT填写5000,因为Webdriveragent源码中写的local本地port是5000,DEVICE_TCP_PORT这里写的是8100,因为启动server以后监听的端口号是8100。
(5)启动iproxy以后,正常启动Webdriveragent server,然后在client端用例中传入的ip:port是
localhost:5000即可。


遇到的问题


1、出现libusbmuxd项目README中make和autoheader没有安装成功。
最后方案:未解决跳过。
2、出现./autogen.sh执行错误。

1
2
3
4
error: Package requirements (libplist >= 1.11) were not met:
Package 'libxml-2.0', required by 'libplist', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

最后方案:执行./autogen.sh前,先执行下面的两条命令,然后编译通过。

1
2
3
export libplist_CFLAGS='-I/usr/local/Cellar/libplist/1.12/include -I/usr/
include/libxml2'
export libplist_LIBS='-L/usr/local/Cellar/libplist/1.12/lib -lplist'