Appium Appium 不懂就问,Appium 小白,在微信切换 webview 时遇到 Original error: unknown error: Failed to get PID for the following process: com.tencent.mm:tools 问题

TL-cj · 2020年01月20日 · 最后由 lin1990 回复于 2021年06月16日 · 3124 次阅读

已经在这个问题卡了很久了,望各位知道的大佬为小弟解惑

前置条件:

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);
 }

appium 详细信息

这里可以看到 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: 

appium 报错信息

[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
共收到 4 条回复 时间 点赞

// on Android O ps returns only user processes, so also try with -A flag.
chromedriver 使用的 ps 命令,不同版本 Android 系统执行结果不一样。

ovwane 回复

您好 ,我这格式 APPIUM 的输出日志,从日志上看是可以看到 PID 的 ,您说的这种方式是在执行时去查看进程情况吗?

同样的错误信息,我这边问题解决了,发在这里看有没有帮助。
LZ 是做微信公众号的测试是吧?微信的版本是多少,已经开启 X5 的 debug 页面了是吧?
确定这些都没问题的话,继续往下。最后发现是 chromedriver 版本问题导致的,折腾了一周多....
关键字:不要相信 Android 系统显示的 webview 版本,通过 chrome://inspect/ 来查看设备的 chrome 版本
确定后到https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md 查看对应的 chromedriver 版本,下一个就好了

升级 webview 版本吧,这个太老了,查下安装得 chromedriver 版本,然后升级下手机端得 webview 版本

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册