使用代理技术解决了chromedriver和微信定制的chrome内核之间的调试问题,可以用于微信小程序的自动化测试。
更新版本参考
shell mock技术
用于欺骗adb和appium,选择合适的chromedriver版本。个人使用可以先简单使用chromedriverExecutable
代替
协议mock adb proxy实现
运行命令
mitmdump -p 5038 \
--rawtcp --mode reverse:http://localhost:5037 \
-s tcp.py
辅助小程序测试的adb_proxy.py
"""
测试人社区 https://ceshiren.com
mitmdump -p 5038 --rawtcp --mode reverse:http://localhost:5037/ -s adb.py
"""
from mitmproxy.utils import strutils
from mitmproxy import ctx
from mitmproxy import tcp
def tcp_message(flow: tcp.TCPFlow):
message = flow.messages[-1]
old_content = message.content
#message.content = old_content.replace(b"foo", b"bar")
message.content = old_content.replace(b"@webview_devtools_remote_", b"@.*.*.*._devtools_remote_")
ctx.log.info(
"[tcp_message{}] from {} to {}:\n{}".format(
" (modified)" if message.content != old_content else "",
"client" if message.from_client else "server",
"server" if message.from_client else "client",
strutils.bytes_to_escaped_str(message.content))
)
运行结果
ceshiren.com: ~ seveniruby$ mitmdump -p 5038 --rawtcp --mode reverse:http://localhost:5037/ -s /tmp/adb.py
Loading script /tmp/adb.py
Proxy server listening at http://*:5038
127.0.0.1:58593: clientconnect
127.0.0.1:58593 -> tcp -> localhost:5037
[tcp_message] from client to server:
000chost:version
127.0.0.1:58593 <- tcp <- localhost:5037
[tcp_message] from server to client:
OKAY00040029
127.0.0.1:58593: clientdisconnect
127.0.0.1:58596: clientconnect
127.0.0.1:58596 -> tcp -> localhost:5037
[tcp_message] from client to server:
000chost:devices
127.0.0.1:58596 <- tcp <- localhost:5037
[tcp_message] from server to client:
OKAY0000
127.0.0.1:58596: clientdisconnect