appium / appium

Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol
http://appium.io/
Apache License 2.0
18.96k stars 6.08k forks source link

switch to webview throws "chrome not reachable" or "Failed to get PID for the following process" #10970

Closed loveiset closed 6 years ago

loveiset commented 6 years ago

The problem

swith to webview throws error "chrome not reachable" or "Failed to get PID for the following process"

Environment

Details

webview version chromedriver version with chromedriver-executable result
60.0.3112.116 2.28 true chrome not reachable
60.0.3112.116 2.32 true chrome not reachable
60.0.3112.116 2.33 true chrome not reachable
60.0.3112.116 2.34 true chrome not reachable
60.0.3112.116 2.35 true chrome not reachable
60.0.3112.116 2.40 true Failed to get PID for the following process
60.0.3112.116 appium built-in false No Chromedriver found that can automate Chrome
67.0.3396.87 2.40 true Failed to get PID for the following process
67.0.3396.87 2.39 true Failed to get PID for the following process
67.0.3396.87 2.38 true Failed to get PID for the following process
67.0.3396.87 2.37 true chrome not reachable

Link to Appium logs

log to chrome not reachable Failed to get PID for the following process all logs seperated by many ==

mayureshshirodkar commented 6 years ago

What kind of app are you testing? Are you using a Cordova App with Crosswalk?

mykola-mokhnach commented 6 years ago

Are you able to connect using chrome remote debugger?

mykola-mokhnach commented 6 years ago

The exception happens inside https://github.com/bayandin/chromedriver/blob/907b958e09dbfdafb13e9257b181009d0ab43b4a/chrome/adb_impl.cc#L260, so I'd say either the process itself dies when chromedriver is trying to look for it or there is some issue with package name detection.

loveiset commented 6 years ago

@mykola-mokhnach chrome remote dubugger works fine, it shows WebView in com.crc.hrt (67.0.3396.87) and I can inspect into it.

Fabiolino88 commented 6 years ago

Hi guys, I don't know whether this can help or not, but I was facing the same issue in the last three days. Looking for the issue on google I've found out that a lot of people is actually having the same issue. I got an android app that at some point open a custom tab to do the authentication and there was no way to connect to the webview to automate the process.

The simulator that I'm using is a Nexus 5X with Android 8.1 + Chrome 67.0.3396 - Appium 1.8.1 and Chromedriver 2.40. I've tried all the combination to make it works. At the beginning appium was looking for the driver using the version of the System WebView instead of the Chrome version and to solve this problem I've found out that you need to pass the path to the specific Chromedriver into the "chromedriverExecutable" capability. After that I was able to retrieve the full list of webviews but the Chromedriver was complaining with the message "chrome not reachable".

When I was trying to switch the context to the webview I've noticed that the Chromedriver.js was calling the JWProxy passing the 'chromeOptions: { androidPackage: the.Package.OfMyApp, ...... }. I've tried to set the chromeOptions capability while setting the driver in my java project, but appium was crashing for unknown capability. So I went into Chromedriver.js and I've injected manually the "com.android.chrome" package to the capabilities before to call the JWProxy. Now switching to the 'WEBVIEW_chrome" + force chromedriver to use the chrome package made the trick and everything is working fine.

Please let me know if you need more details or if you guys know if there is better way to pass the chromeOptions capabilities. Looking at this page: http://chromedriver.chromium.org/capabilities I didn't find any "androidPackage" in the list of available capabilities for the chromeOptions.

mykola-mokhnach commented 6 years ago

@imurchie FYI

loveiset commented 6 years ago

I tried your solution,but it did not work,now I don't know what to do @Fabiolino88

roosto commented 6 years ago

This issue may be a duplicate of #8958 cc: @loveiset

zhangpeibisha commented 6 years ago

Hello, may you solve the problem?

Fabiolino88 commented 6 years ago

Hi @loveiset, what did you do exactly? can you please give more details?

loveiset commented 6 years ago

@Fabiolino88 I edit Chomedriver.js as following, but it did not work

async start (caps, emitStartingState = true) {
    this.capabilities = caps;
    // add this line
    // change androidPackage to package.of.myApp or com.android.chrome, neither works.
    this.capabilities["chromeOptions"]["androidPackage"] = "package.of.myApp";
    if (emitStartingState) {
      this.changeState(Chromedriver.STATE_STARTING);
    }
Fabiolino88 commented 6 years ago

Hi @loveiset, sorry probably in the post I didn't explain it well, but you need to set the android package to the chrome app package. Setting it to the App package it's exactly the reason why is not working. I've done it like that:

this.capabilities.chromeOptions.androidPackage = "com.android.chrome"

on line 253 after the start (like you done already) and on line 404 in the startSession method

and then, of course, you have to recompile the package

mykola-mokhnach commented 6 years ago

Closed as inactive

loveiset commented 6 years ago

@Fabiolino88 I have modified chromedriver.js as you said, but problem not resolved(modification have taken effect as log given)

[debug] [JSONWP Proxy] Matched '/session' to command name 'createSession'
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.chrome","androidUseRunningApp":true,"androidDeviceSerial":"1df270ff"}}}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"be2386672b428cd74ac5c07d05934dd9","status":100,"value":{"message":"chrome not reachable\n  (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.1.7601 SP1 x86_64)"}}

@mykola-mokhnach this problem still exist in appium version 1.9.1, error show Original error: unknown error: Failed to get PID for the following process,but I can get it from command adb -P 5037 -s 1df270ff shell ps

Lanuet commented 6 years ago

thank @Fabiolino88 this solution worked for me

PrasadMadge commented 6 years ago

@Fabiolino88 ,@Lanuet, can you please brief how did your issue got fixed.

"C:\Users\q2019\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-chromedriver\lib\chromedriver.js"

I have updated the package to chrome in both async and start session method in chromedriver.js , still facing the issue. this.capabilities["chromeOptions"]["androidPackage"] = "com.android.chrome";

What do you mean recompile the packages ?

tahirakhlaaq commented 5 years ago

Any solution for this. I'm also facing the problem. @mykola-mokhnach @Jonahss @jlipps https://gist.github.com/tahirakhlaaq/53de659cb5fe89889ab9dec7432c135c