本文节选自霍格沃兹测试学院内部教材
混合应用测试或微信小程序测试,都会涉及到 WebView 组件,这节内容将分析一下 WebView 的技术原理。首先通过日志分析查看 Appium
的运行过程。
WebView日志分析
要想查看 ChromeDriver 的日志,需要在 Capability 里开启 一个开关项 showChromedriverLog
。让 Appium
运行测试用例时能够生成 ChromeDriver 相关的日志(默认是不打印 ChromeDriver 这部分日志的)。代码如下:
capabilities['showChromedriverLog'] = True
启动 AppiumServer 并将生成的所有日志存储到文件 /tmp/appium.log
中:
appium -g /tmp/appium.log
关键日志分析
下面我们对 /tmp/appium.log
文件中的关键日志进行详细的分析。首先找到 Context 切换的日志,发现 Context 切换到
WEBVIEW_io.appium.android.apis
上下文中:
[HTTP] <-- GET /wd/hub/session/xx/contexts 200 99 ms - 145[HTTP] --> POST /wd/hub/session/xx/context \{"name":"WEBVIEW_io.appium.android.apis"}
Appium 在本地开启了两个 WebView 进程,进程号分别是 1271 和 26060。
[debug] [AndroidDriver] WEBVIEW_1271 mapped to pid 1271[debug] [AndroidDriver] Getting process name for webview[debug] [ADB] Getting connected devices...[debug] [AndroidDriver] WEBVIEW_26060 mapped to pid 26060[debug] [AndroidDriver] Getting process name for webview
然后,Appium 通过使用 adb 命令来查看 1271 和 26060 的进程信息。
[debug] [ADB] Running '/Users/xxxx/profile/android-sdk_r2.4.1-\macosx/android-sdk-macosx/platform-tools/adb' with args: ["-P",5037,\"-s","192.168.56.101:5555","shell","ps"][debug] [AndroidDriver] Parsed pid: '1271' pkg: 'cn.goapk.market' from[debug] [AndroidDriver] USER PID PPID VSIZE RSS \WCHAN \ PC NAME[debug] [