支持自定义androidProcess,测试微信webview
-
Macaca Version: 1.1.21
-
Macaca Doctor Logs:
macaca-doctor version: 1.0.28
Node.js checklist:
node env: C:\Program Files\nodejs\node.exe node version: v4.4.1
Android checklist:
JAVA version is
1.8.0_92JAVA_HOME is set toC:\Program Files\Java\jdk1.8.0_92ANDROID_HOME is set toD:\android-sdkPlatforms is set toD:\android-sdk\platforms\android-22Android tools is set toD:\android-sdk\tools\android.batADB tool is set toD:\android-sdk\platform-tools\adb.exeANT_HOME is set toD:\apache-ant-1.9.7Installed driver list:
android: 1.1.15 electron: 1.1.4
-
Operate System: Windows 7 64bit
-
Programming Language:
Macaca不支持ChromeOptions自定义设置参数,导致不能测试微信webview
Macaca初始化参数
尝试1:
{"desiredCapabilities":{"reuse":3,"package":"com.tencent.mm","activity":".ui.LauncherUI","platformVersion":"6.0.1","chromeOptions":{"androidProcess":"com.tencent.mm:appbrand0"},"platformName":"android","deviceName":"XIAOMI","autoAcceptAlerts":true}}
尝试2:
{"desiredCapabilities":{"reuse":3,"package":"com.tencent.mm","activity":".ui.LauncherUI","platformVersion":"6.0.1","platformName":"android","deviceName":"XIAOMI","autoAcceptAlerts":true},"chromeOptions":{"androidProcess":"com.tencent.mm:appbrand0"}}
Chrome初始化参数部分log:
>> proxy.js:52:14 [master] pid:4936 Proxy: /session:POST to http://localhost:9515/wd/hub/session:POST with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"cb2a272c"}}}
-
Appium支持ChromeOptions设置参数
可参考帖子:Appium 微信 webview 的自动化技术
@adfghzhang 支持自定义androidProcess,升级新版[email protected] 即可
package: 'com.tencent.mm',
activity: '.ui.LauncherUI',
androidProcess: 'com.tencent.mm:tools'
https://github.com/macacajs/macaca-android/commit/c7775ba545e8d9fc0c92f8b889a8f491c5558f2e

@xudafeng 实验失败,麻烦看一下是什么问题呢?另外提出一点疑问,driver.contexts()获取当前的context时候就启动了chromedriver,使用appium过程中发现并没有在这个方法调用时启用chromedriver。
Macaca doctor信息:
macaca-doctor version: 1.0.28
Node.js checklist:
node env: D:\Program Files\nodejs\node.exe
node version: v6.9.4
Android checklist:
JAVA version is `1.8.0_112`
JAVA_HOME is set to `C:\Program Files\Java\jdk1.8.0_112`
ANDROID_HOME is set to `D:\android-sdk`
Platforms is set to `D:\android-sdk\platforms\android-24`
Android tools is set to `D:\android-sdk\tools\android.bat`
ADB tool is set to `D:\android-sdk\platform-tools\adb.exe`
ANT_HOME is set to `D:\apache-ant-1.9.7`
Installed driver list:
android: 1.1.16
electron: 1.1.4
Java代码 use macacaclient2.0
static MacacaClient driver = new MacacaClient();
public static void setup() throws Exception {
JSONObject porps = new JSONObject();
porps.put("autoAcceptAlerts", true);
porps.put("platformVersion", "5.1");
porps.put("deviceName", "OPPO");
porps.put("platformName", "android");
porps.put("udid", "JB6HPJAMVGHIWOTG");
porps.put("reuse", 3);
porps.put("package", "com.tencent.mm");
porps.put("activity", ".ui.LauncherUI");
// 关键是加上这段
porps.put("androidProcess", "com.tencent.mm:tools");
JSONObject desiredCapabilities = new JSONObject();
desiredCapabilities.put("desiredCapabilities", porps);
driver.initDriver(desiredCapabilities);
}
public static void main(String[] args) throws Exception {
setup();
driver.sleep(2000);
driver.elementByXPath("//*[@text='发现']").click();
driver.elementByXPath("//*[@text='小程序']").click();
driver.sleep(2000);
driver.elementByXPath("//*[contains(@text, '美团外卖+')]").click();
// System.out.println(driver.contexts());
Thread.sleep(5000);
driver.context("WEBVIEW_com.tencent.mm:tools");
Thread.sleep(2000);
System.out.println(driver.elementByClassName("msg_title").getText());
Thread.sleep(2000);
System.out.println(driver.currentContext());
driver.quit();
}
driver.contexts()报错信息:
>> responseHandler.js:11:12 [master] pid:10140 Recieve HTTP Request from Client:
method: GET url: /wd/hub/session/268f5145-3eb2-421e-ac9c-45cfdd57099b/contexts,
jsonBody: {}
>> chromedriver bin path: C:\Users\Administrator\AppData\Roaming\npm\node_module
s\macaca-android\node_modules\.1.0.30@macaca-chromedriver\exec\chromedriver.exe
>> Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067)
on port 9516
Only local connections are allowed.
>> chromedriver starting success.
>> proxy.js:52:14 [master] pid:10140 Proxy: /status:GET to http://localhost:9516
/wd/hub/status:GET with body:
>> proxy.js:58:16 [master] pid:10140 Got response with status 200: "{\"sessionId
\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch
\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"6.1 SP1\"}}}"
>> proxy.js:52:14 [master] pid:10140 Proxy: /session:POST to http://localhost:95
16/wd/hub/session:POST with body: {"desiredCapabilities":{"chromeOptions":{"andr
oidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"
JB6HPJAMVGHIWOTG","androidProcess":"com.tencent.mm:tools"}}}
>> proxy.js:58:16 [master] pid:10140 Got response with status 200: {"sessionId":
"26648b1b6aada66034479f92d8e09ea1","status":100,"value":{"message":"chrome not r
eachable\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf708
1628a1396067),platform=W...
>> chromedriver ready with: {"sessionId":null,"status":100,"value":{"message":"c
hrome not reachable\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933e
c778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64)"}}
>> proxy.js:52:14 [master] pid:10140 Proxy: /wd/hub/session/temp/window_handles:
GET to http://localhost:9516/wd/hub/session/26648b1b6aada66034479f92d8e09ea1/win
dow_handles:GET with body: {}
>> proxy.js:58:16 [master] pid:10140 Got response with status 200: {"sessionId":
"26648b1b6aada66034479f92d8e09ea1","status":6,"value":{"message":"no such sessio
n\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a13
96067),platform=Windows ...
>> responseHandler.js:54:12 [master] pid:10140 Send Error Respone to Client: NoS
uchDriver: no such session
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a13960
67),platform=Windows NT 6.1 SP1 x86_64)
>> responseHandler.js:60:14 [master] pid:10140 NoSuchDriver: no such session
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a13960
67),platform=Windows NT 6.1 SP1 x86_64)
at Object._.parseWebDriverResult (C:\Users\Administrator\AppData\Roaming\npm
\node_modules\macaca-android\lib\helper.js:72:11)
at Android.getWebviews (C:\Users\Administrator\AppData\Roaming\npm\node_modu
les\macaca-android\lib\macaca-android.js:288:18)
at next (native)
at onFulfilled (C:\Users\Administrator\AppData\Roaming\npm\node_modules\maca
ca-cli\node_modules\.4.6.0@co\index.js:65:19)
at process._tickCallback (internal/process/next_tick.js:103:7)
>> responseHandler.js:76:14 [master] pid:10140 Send Bad HTTP Respone to Client:
{"sessionId":"268f5145-3eb2-421e-ac9c-45cfdd57099b","status":6,"value":{"message
":"no such session\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec
778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64)"}}
driver.context("WEBVIEW_com.tencent.mm:tools");报错
>> responseHandler.js:11:12 [master] pid:10140 Recieve HTTP Request from Client:
method: POST url: /wd/hub/session/8ac62f3d-9243-464a-adfb-662ddd2aa9bd/context,
jsonBody: {"name":"WEBVIEW_com.tencent.mm:tools"}
>> chromedriver bin path: C:\Users\Administrator\AppData\Roaming\npm\node_module
s\macaca-android\node_modules\.1.0.30@macaca-chromedriver\exec\chromedriver.exe
>> Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067)
on port 9518
Only local connections are allowed.
>> chromedriver starting success.
>> proxy.js:52:14 [master] pid:10140 Proxy: /status:GET to http://localhost:9518
/wd/hub/status:GET with body:
>> proxy.js:58:16 [master] pid:10140 Got response with status 200: "{\"sessionId
\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch
\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"6.1 SP1\"}}}"
>> proxy.js:52:14 [master] pid:10140 Proxy: /session:POST to http://localhost:95
18/wd/hub/session:POST with body: {"desiredCapabilities":{"chromeOptions":{"andr
oidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidDeviceSerial":"
JB6HPJAMVGHIWOTG","androidProcess":"com.tencent.mm:tools"}}}
>> proxy.js:58:16 [master] pid:10140 Got response with status 200: {"sessionId":
"d63dbdf14fc475003173dfacede2028d","status":13,"value":{"message":"unknown error
: unable to discover open pages\n (Driver info: chromedriver=2.20.353145 (343b5
31d31eeb933ec778dbcf7081...
>> chromedriver ready with: {"sessionId":null,"status":13,"value":{"message":"un
known error: unable to discover open pages\n (Driver info: chromedriver=2.20.35
3145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_
64)"}}
>> proxy.js:52:14 [master] pid:10140 Proxy: /wd/hub/session/temp/window_handles:
GET to http://localhost:9518/wd/hub/session/d63dbdf14fc475003173dfacede2028d/win
dow_handles:GET with body: {}
>> proxy.js:58:16 [master] pid:10140 Got response with status 200: {"sessionId":
"d63dbdf14fc475003173dfacede2028d","status":6,"value":{"message":"no such sessio
n\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a13
96067),platform=Windows ...
>> responseHandler.js:54:12 [master] pid:10140 Send Error Respone to Client: NoS
uchDriver: no such session
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a13960
67),platform=Windows NT 6.1 SP1 x86_64)
>> responseHandler.js:60:14 [master] pid:10140 NoSuchDriver: no such session
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a13960
67),platform=Windows NT 6.1 SP1 x86_64)
at Object._.parseWebDriverResult (C:\Users\Administrator\AppData\Roaming\npm
\node_modules\macaca-android\lib\helper.js:72:11)
at Android.getWebviews (C:\Users\Administrator\AppData\Roaming\npm\node_modu
les\macaca-android\lib\macaca-android.js:288:18)
at next (native)
at onFulfilled (C:\Users\Administrator\AppData\Roaming\npm\node_modules\maca
ca-cli\node_modules\.4.6.0@co\index.js:65:19)
at process._tickCallback (internal/process/next_tick.js:103:7)
>> responseHandler.js:76:14 [master] pid:10140 Send Bad HTTP Respone to Client:
{"sessionId":"8ac62f3d-9243-464a-adfb-662ddd2aa9bd","status":6,"value":{"message
":"no such session\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec
778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64)"}}
driver.context("WEBVIEW_com.tencent.mm:tools"); 不对,直接切到第二个上下文
又试了一次driver.contexts()获取正常了。。。。
@xudafeng 只支持Android?不支持ios?
@xudafeng @adfghzhang
设置了参数: platformName: 'Android', platformVersion: '5.0', autoAcceptAlerts: true, reuse: 2, udid: '4d00f618684d5051', package: 'com.tencent.mm', activity: 'com.tencent.mm.ui.LauncherUI', androidProcess: 'com.tencent.mm:tools', app: undefined
同样contexts()报错: chromedriver ready with: {"sessionId":null,"status":100,"value":{"message":"chrome not reachable\n (Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64)"}