已经在这个问题卡了很久了,望各位知道的大佬为小弟解惑
1.真机 OPPO R11st
2.安卓版本 7.1.1
3.真机 webview 66.0.3359.126(chrome 浏览器和微信内嵌 webview 同此版本)
4.appium 1.15.1
public static void main(String[] args) throws Exception {
//创建配置对象
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("deviceName","OPPO R11st");
//测试平台
desiredCapabilities.setCapability("platformName", "Android");
//安卓系统版本
desiredCapabilities.setCapability("paltformVersion", "7.1.1");
desiredCapabilities.setCapability("appPackage", "com.tencent.mm");
desiredCapabilities.setCapability("appActivity", ".ui.LauncherUI");
//不清除数据启动
desiredCapabilities.setCapability("noReset", "True");
desiredCapabilities.setCapability("recreateChromeDriverSessions","True");
//自动化引擎(解决输入框不能输入的问题)
desiredCapabilities.setCapability("automationName", "uiautomator2");
// 支持X5内核应用自动化配置
desiredCapabilities.setCapability("recreateChromeDriverSessions", true);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
desiredCapabilities.setCapability("browserName","");
//创建驱动
androidDriver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
//元素超时等待
androidDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
weChat();
//关闭驱动
androidDriver.quit();
}
public static void weChat() throws Exception {
Thread.sleep(5000);
androidDriver.findElementById("com.tencent.mm:id/r_").click();
androidDriver.findElementById("com.tencent.mm:id/m7").sendKeys("接口测试号");
androidDriver.findElementById("com.tencent.mm:id/s7").click();
androidDriver.findElementByAndroidUIAutomator("new UiSelector().text(\"贷款\")").click();
androidDriver.findElementByAndroidUIAutomator("new UiSelector().text(\"卢贝尔TEST\")").click();
Thread.sleep(15000);
Set<String> context = androidDriver.getContextHandles();
for(String contextname : context){
System.out.println(contextname);//打印
if(contextname.equals("WEBVIEW_com.tencent.mm:tools"))
androidDriver.context(contextname);
}
System.out.println(androidDriver.findElementsByXPath("//*").toString());
System.out.println("进来了。。。。。。");
androidDriver.findElementByXPath("//*[@id=\"app\"]/div/div[2]/div[1]/img").click();
androidDriver.findElementByXPath("//*[@id=\"app\"]/div/div[1]/div[2]/div[1]/input").sendKeys("13983871447");
androidDriver.findElementByXPath("//*[@id=\"app\"]/div/div[1]/div[2]/div[2]/div").sendKeys("qwe000111");
androidDriver.findElementByXPath("//*[@id=\"app\"]/div/div[1]/div[3]/input").click();
Thread.sleep(25000);
}
这里可以看到 pid 是被找到了的
[2020-01-20 04:08:12][AndroidDriver] Parsed pid: '21104' pkg: 'com.tencent.mm:tools' from
[2020-01-20 04:08:12][AndroidDriver] USER PID PPID VSIZE RSS FRZ WCHAN PC NAME
[2020-01-20 04:08:12][AndroidDriver] u0_a297 21104 997 3907284 381152 efg 0 0000000000 S com.tencent.mm:tools
[2020-01-20 04:08:12][AndroidDriver] Returning process name: 'com.tencent.mm:tools'
[2020-01-20 04:08:12][AndroidDriver] Parsed pid: '20267' pkg: 'com.tencent.mm' from
[2020-01-20 04:08:12][AndroidDriver] USER PID PPID VSIZE RSS FRZ WCHAN PC NAME
[2020-01-20 04:08:12][AndroidDriver] u0_a297 20267 997 3487468 300536 efg 0 0000000000 S com.tencent.mm
[2020-01-20 04:08:12][AndroidDriver] Returning process name: 'com.tencent.mm'
[2020-01-20 04:08:12][AndroidDriver] Parsed pid: '20643' pkg: 'com.tencent.mm:appbrand0' from
[2020-01-20 04:08:12][AndroidDriver] USER PID PPID VSIZE RSS FRZ WCHAN PC NAME
[2020-01-20 04:08:12][AndroidDriver] u0_a297 20643 997 3474560 255204 unk 0 0000000000 S com.tencent.mm:appbrand0
[2020-01-20 04:08:12][AndroidDriver] Returning process name: 'com.tencent.mm:appbrand0'
[2020-01-20 04:08:12][AndroidDriver] Parsed pid: '21040' pkg: 'com.tencent.mm:toolsmp' from
[2020-01-20 04:08:12][AndroidDriver] USER PID PPID VSIZE RSS FRZ WCHAN PC NAME
[2020-01-20 04:08:12][AndroidDriver] u0_a297 21040 997 3227048 264568 unk 0 0000000000 S com.tencent.mm:toolsmp
[2020-01-20 04:08:12][AndroidDriver] Returning process name: 'com.tencent.mm:toolsmp'
[2020-01-20 04:08:12][AndroidDriver] Found webviews: ["WEBVIEW_com.tencent.mm:tools","WEBVIEW_com.tencent.mm:appbrand0","WEBVIEW_com.tencent.mm","WEBVIEW_com.tencent.mm:toolsmp"]
[2020-01-20 04:08:12][AndroidDriver] Available contexts:
[2020-01-20 04:08:12][Chromedriver] Starting MJSONWP Chromedriver session with capabilities: {
[2020-01-20 04:08:12][Chromedriver] "desiredCapabilities": {
[2020-01-20 04:08:12][Chromedriver] "chromeOptions": {
[2020-01-20 04:08:12][Chromedriver] "androidPackage": "com.tencent.mm",
[2020-01-20 04:08:12][Chromedriver] "androidUseRunningApp": true,
[2020-01-20 04:08:12][Chromedriver] "androidProcess": "com.tencent.mm:tools",
[2020-01-20 04:08:12][Chromedriver] "args": [],
[2020-01-20 04:08:12][Chromedriver] "extensions": [],
[2020-01-20 04:08:12][Chromedriver] "androidDeviceSerial": "8905da57"
[2020-01-20 04:08:12][Chromedriver] },
[2020-01-20 04:08:12][Chromedriver] "loggingPrefs": {
[2020-01-20 04:08:12][Chromedriver] "browser": "ALL"
[2020-01-20 04:08:12][Chromedriver] }
[2020-01-20 04:08:12][Chromedriver] }
[2020-01-20 04:08:12][Chromedriver] }
[2020-01-20 04:08:12][WD Proxy] Matched '/session' to command name 'createSession'
[2020-01-20 04:08:12][WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","args":[],"extensions":[],"androidDeviceSerial":"8905da57"},"loggingPrefs":{"browser":"ALL"}}}
[2020-01-20 04:08:14][WD Proxy] Got response with status 200: {"sessionId":"db8120c4243d3b2e3714bb62b5357a5b","status":13,"value":{"message":"unknown error: Failed to get PID for the following process: com.tencent.mm:tools\n (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
[2020-01-20 04:08:14][WD Proxy] Determined the downstream protocol as 'MJSONWP'
[2020-01-20 04:08:14][WD Proxy] The response has an unknown format
[2020-01-20 04:08:14][MJSONWP] Matched JSONWP error code 13 to UnknownError
[2020-01-20 04:08:14][Chromedriver] Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to get PID for the following process: com.tencent.mm:tools
[2020-01-20 04:08:14][Chromedriver] (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64)
[2020-01-20 04:08:14][WD Proxy] Matched '/session' to command name 'createSession'
[2020-01-20 04:08:14][WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.tencent.mm","androidUseRunningApp":true,"androidProcess":"com.tencent.mm:tools","args":[],"extensions":[],"androidDeviceSerial":"8905da57"},"loggingPrefs":{"browser":"ALL"}}}
[2020-01-20 04:08:15][WD Proxy] Got response with status 200: {"sessionId":"41893d46f51c7c60c153a16cd7cfe42f","status":13,"value":{"message":"unknown error: Failed to get PID for the following process: com.tencent.mm:tools\n (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
[2020-01-20 04:08:15][WD Proxy] Determined the downstream protocol as 'MJSONWP'
[2020-01-20 04:08:15][WD Proxy] The response has an unknown format
[2020-01-20 04:08:15][MJSONWP] Matched JSONWP error code 13 to UnknownError
[2020-01-20 04:08:15][Chromedriver] Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to get PID for the following process: com.tencent.mm:tools