Java-client: Set ChromeOptions with androidProcess in DesiredCapabilities will raise error

Created on 7 Jul 2018  Â·  36Comments  Â·  Source: appium/java-client

Description

Set DediredCapabilities with androidProcess in ChromeOptions as below:

DesiredCapabilities desired_capabilities = new DesiredCapabilities(); desired_capabilities.setCapability(AndroidMobileCapabilityType.PLATFORM, "Android"); desired_capabilities.setCapability(AndroidMobileCapabilityType.VERSION, "6.0"); desired_capabilities.setCapability("deviceName", "Android"); desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.tencent.mm"); desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "ui.LauncherUI"); desired_capabilities.setCapability("showChromedriverLog", true); desired_capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true); desired_capabilities.setCapability("noReset", true); ChromeOptions chrome_options = new ChromeOptions(); chrome_options.setExperimentalOption("androidProcess", "com.tencent.mm:tools"); desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);

When try to launch driver, appium will give the Error: Could not find package com.android.chrome on the device

This error happened with java client 6.0.0, but it is ok with 5.0.0

Environment

  • java client build version or git revision if you use some shapshot: 6.0.0
  • Appium server version or git revision if you use some shapshot: 1.8.1
  • Desktop OS/version used to run Appium if necessary: Mac High Sierra
  • Node.js version (unless using Appium.app|exe) or Appium CLI or Appium.app|exe: 10.1.0
  • Mobile platform/version under test: Android 6.0
  • Real device or emulator/simulator: emulator

Details

Please provide more details, if necessary.

Code To Reproduce Issue [ Good To Have ]

Ecxeption stacktraces

https://gist.github.com/megolee/9e010f6efb7d9572494cbb3fd4c00061

Link to Appium logs

java client 6.0.0: https://gist.github.com/megolee/8d9c4dd279d70e34dd5934c0e9886ce8

java client 5.0.0: https://gist.github.com/megolee/60d9b9746531343bea886ae1e4757c7c

User side probleproblem of an external tool

Most helpful comment

@megolee @512433465 we need to raise this to selenium. They are setting browserName to chrome by default when ChromeOptions object is created.

As workaround can u try this

DesiredCapabilities desired_capabilities = new DesiredCapabilities();
ChromeOptions chrome_options = new ChromeOptions();
    chrome_options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
    desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.PLATFORM, "Android");
    desired_capabilities.setCapability(AndroidMobileCapabilityType.VERSION, "6.0");
    desired_capabilities.setCapability("deviceName", "Android");
    desired_capabilities.setCapability(MobileCapabilityType.FORCE_MJSONWP, true);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.tencent.mm");
    desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "ui.LauncherUI");
    desired_capabilities.setCapability("showChromedriverLog", true);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
    desired_capabilities.setCapability("noReset", true);
        desired_capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,"");
    desired_capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");



    try {
        driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),desired_capabilities);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }


}

All 36 comments

The capabilities are incorrect. One can either set browser name or app activity but not both

@mykola-mokhnach The capabilities works on both java client 5.0.0 and latest python client, why it is incorrect for java client 6.0.0?

Since the app I tested is a hybird app, and the weview is running on a different process rather than the native view. So I have to set the chrome_options with androidProcess, otherwise appium cannot switch to the webview. Is there any workround?

Many Thanks.

Check https://github.com/appium/appium/issues/10970. Perhaps the problem, which is described there, is similar to yours.

Still not working

@megolee Have you had a look at this issue: https://github.com/appium/appium/issues/8958 ?

I think that it might be relevant to your struggles.

@SrinivasanTarget Why this issue closed? It still happens.

@megolee Can you check in latest appium server and java client (from latest master commit) and update the logs here. Also try setting capability forceMjsonwp to true and give a try.

Java Client Latest Commit
@SrinivasanTarget Hi, this is the log with java client latest commit and appium 1.9.1@beta2, appium through an error when session create. I have also tried with the same code and env only change the java client to 5.0.0, java client 5.0.0 still working.

Seems that the desired capabilities will take the browserName:chrome automatic, as I didn't define this capability in the code. But the appium logs say it need appPackage or browserName.

https://gist.github.com/megolee/a7e916d1ac0abb875b31ff6287aeac29#file-java-client-last-commit-L24

https://gist.github.com/megolee/a7e916d1ac0abb875b31ff6287aeac29#file-java-client-last-commit-L31

@megolee https://gist.github.com/megolee/a7e916d1ac0abb875b31ff6287aeac29#file-java-client-last-commit-L4

i see you have given browserName: chrome

@SrinivasanTarget I didn't give browserName: chrome in my code, below is my code.

Actually, when I use java client 6.0.0 or the latest commit, it will take the browserName:chrome automatic. But when I roll back to 5.0.0, browserName:chrome does not appear in the logs.

`import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;

public class JavaSimple {

public static AndroidDriver<AndroidElement> driver;

public static void main(String[] args) {

    DesiredCapabilities desired_capabilities = new DesiredCapabilities();
    desired_capabilities.setCapability(AndroidMobileCapabilityType.PLATFORM, "Android");
    desired_capabilities.setCapability(AndroidMobileCapabilityType.VERSION, "6.0");
    desired_capabilities.setCapability("deviceName", "Android");
    desired_capabilities.setCapability(MobileCapabilityType.FORCE_MJSONWP, true);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.tencent.mm");
    desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "ui.LauncherUI");
    desired_capabilities.setCapability("showChromedriverLog", true);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
    desired_capabilities.setCapability("noReset", true);
    ChromeOptions chrome_options = new ChromeOptions();
    chrome_options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
    desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);

    try {
        driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),desired_capabilities);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }


}

}`

@megolee just curious why do u have this in your caps

ChromeOptions chrome_options = new ChromeOptions();
    chrome_options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
    desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);

@saikrishna321 As the web view of the app is running on an independent process rather than the native view. So I have to set the chrome_options with androidProcess, otherwise appium cannot switch to the web view.

i have the same issue as this tickets. when test hybrid and set chromeoption, it switch to chrome automaticly by 6.0.0. and i switch webview failed by 6.0.0beta4 and 6.1.1 with selenium 3.14

i have the same issue as this tickets. when test hybrid and set chromeoption, it switch to chrome automaticly by 6.0.0. and i switch webview failed by 6.0.0beta4 and 6.1.1 with selenium 3.14

i have the same issue as this tickets. when test hybrid and set chromeoption, it switch to chrome automaticly by 6.0.0. and i switch webview failed by 6.0.0beta4 and 6.1.1 with selenium 3.14

Environment

  1. Java-client : 6.1.0
  2. Android System WebView : 57.0
  3. chromedriver : 2.29
  4. Appium server:1.8.1
  5. Mobile : Android 6.0

Test Source

DesiredCapabilities desired_capabilities = new DesiredCapabilities();
desired_capabilities.setCapability(AndroidMobileCapabilityType.PLATFORM, "Android");
desired_capabilities.setCapability(AndroidMobileCapabilityType.VERSION, "6.0");
desired_capabilities.setCapability("deviceName", "Android");
desired_capabilities.setCapability(MobileCapabilityType.FORCE_MJSONWP, true);
desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.tencent.mm");
desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "ui.LauncherUI");
desired_capabilities.setCapability("showChromedriverLog", true);
desired_capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
desired_capabilities.setCapability("noReset", true);
ChromeOptions chrome_options = new ChromeOptions();
chrome_options.setExperimentalOption("androidProcess", "com.tencent.mm:appbrand0");
desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);

try {
    driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),desired_capabilities);
} catch (MalformedURLException e) {
    e.printStackTrace();
}

Error Log:

t activity/process
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"da744c12e471a6a87df315131e59dd66","status":13,"value":{"
message":"unknown error: known package com.android.chrome does not accept activity/process\n (Driver info: chromedriver=2.
29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64)"}}
[Chromedriver] Error: Failed to start Chromedriver session: An unknown server-side error occurred while processing the comm
and. (Original error: unknown error: known package com.android.chrome does not accept activity/process
[Chromedriver] (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.
7601 SP1 x86_64))
[Chromedriver] at Object.wrappedLogger.errorAndThrow (C:\nodejs\node-global\node_modules\appium\node_modules\appium-sup
port\lib\logging.js:78:13)
[Chromedriver] at Chromedriver.callee$2$0$ (C:\nodejs\node-global\node_modules\appium\node_modules\appium-chromedriver\
lib\chromedriver.js:357:13)
[Chromedriver] at tryCatch (C:\nodejs\node-global\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js
:67:40)
[Chromedriver] at GeneratorFunctionPrototype.invoke [as _invoke] (C:\nodejs\node-global\node_modules\appium\node_module
s\babel-runtime\regenerator\runtime.js:315:22)
[Chromedriver] at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\nodejs\node-global\node_modu
les\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
[Chromedriver] at GeneratorFunctionPrototype.invoke (C:\nodejs\node-global\node_modules\appium\node_modules\babel-runti
me\regenerator\runtime.js:136:37)
[Chromedriver] Chromedriver exited unexpectedly with code null, signal SIGTERM
[debug] [Chromedriver] Changed state to 'stopped'
[Chromedriver] Error: Failed to start Chromedriver session: An unknown server-side error occurred while processing the comm
and. (Original error: unknown error: known package com.android.chrome does not accept activity/process
[Chromedriver] (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.
7601 SP1 x86_64))
[Chromedriver] at Object.wrappedLogger.errorAndThrow (C:\nodejs\node-global\node_modules\appium\node_modules\appium-sup
port\lib\logging.js:78:13)

I hava the same trouble

@SrinivasanTarget Could you help me,many thanks?

@saikrishna321
I know why he set the follow ChromeOptions 。

  • ChromeOptions chrome_options = new ChromeOptions();
  • chrome_options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
  • desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);

Because he want to test WeChat‘s Applets。 A special WebView that belong to WeChat。Now WeChat‘s Applets is very popular in China。

I had try to use the same mobile and the same OS,but just use Python to do the same operation。Python client do work OK。 Is it java-client's Bug ? @saikrishna321 @SrinivasanTarget

@512433465 Can you share the Appium server logs from both python client and java client? please provide logs in form of gist.

@SrinivasanTarget Thank you very much ~

Here is java log. I am very curious that i have not set the [capabilities.setCapability("browserName", "XXX");] in my caps,but when i run my case ,chrome run first.
https://github.com/512433465/LvmamaXmlKit/blob/master/javalog.txt
and here is python log.
https://github.com/512433465/LvmamaXmlKit/blob/master/pythonlog.txt

@512433465 Appium 1.6.4 is years old. Can you please test and tell me on latest appium server beta and java client latest commit (refer here) and also on python client(latest version) then share your logs so it will help me to debug further?

@SrinivasanTarget I think I can help to share you the logs of python and java client.

Python Client 0.30 : https://gist.github.com/megolee/fad60f3579a1c69d2e062af4888cfe59
`
from appium import webdriver

def initdriver():
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['automationName'] = 'uiautomator2'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['forceMjsonwp'] = True
desired_caps['appPackage'] = 'com.tencent.mm'
desired_caps['appActivity'] = 'ui.LauncherUI'
desired_caps['showChromedriverLog'] = True
desired_caps['autoGrantPermissions'] = True
desired_caps['noReset'] = True

desired_caps['chromeOptions'] = {"androidProcess": "com.tencent.mm:tools"}

return webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

if __name__ == '__main__':

driver = initdriver()`

JavaClient Lastest Commit: https://gist.github.com/megolee/2633e04a76b18b45d92740268d2ac847

`
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;

public class JavaSimple {

public static AndroidDriver<AndroidElement> driver;

public static void main(String[] args) {

    DesiredCapabilities desired_capabilities = new DesiredCapabilities();
    desired_capabilities.setCapability(AndroidMobileCapabilityType.PLATFORM, "Android");
    desired_capabilities.setCapability(AndroidMobileCapabilityType.VERSION, "6.0");
    desired_capabilities.setCapability("deviceName", "Android");
    desired_capabilities.setCapability(MobileCapabilityType.FORCE_MJSONWP, true);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.tencent.mm");
    desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "ui.LauncherUI");
    desired_capabilities.setCapability("showChromedriverLog", true);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
    desired_capabilities.setCapability("noReset", true);
    desired_capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");

    ChromeOptions chrome_options = new ChromeOptions();
    chrome_options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
    desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);

    try {
        driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),desired_capabilities);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }


}

}
`

@SrinivasanTarget I have done some tests, and this issue seems related to selenium java library.

https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/chrome/ChromeOptions.java#L86

From selenium java library version 3.6.0, when initialize an instance of ChromeOption class, it will set the browser name capability as above link. This browser name capability makes appium response with error "The desired should not include both of an 'appPackage' and a 'browserName'".

And I have done some tests against several java client which depend on different versions selenium java library and got below results.

Java Client 5.0.0 --> Depend on selenium-java 3.5.2 --> Works fine

Java Client 5.0.1 --> Depend on selenium-java 3.5.2 --> Works fine

Java Client 5.0.2 --> Depend on selenium-java 3.5.3 --> Works fine

Java Client 5.0.3 --> Depend on selenium-java 3.5.3 --> Works fine

Java Client 5.0.4 --> Depend on selenium-java 3.6.0 --> Error as above

Java Client 6.0.0 --> Depend on selenium-java 3.12.0 --> Error as above

@SrinivasanTarget Hi, could you please help with this issue? Thanks very much.

@SrinivasanTarget I have the same question as megolee . Could you help me when you have time,thank you very much。Megolee had commited his logs。
Python Client 0.30 : https://gist.github.com/megolee/fad60f3579a1c69d2e062af4888cfe59
JavaClient Lastest Commit: https://gist.github.com/megolee/2633e04a76b18b45d92740268d2ac847

@megolee @512433465 will look into this.

Thank you very very much~ I am so sorry to trouble you so much.

@megolee @512433465 we need to raise this to selenium. They are setting browserName to chrome by default when ChromeOptions object is created.

As workaround can u try this

DesiredCapabilities desired_capabilities = new DesiredCapabilities();
ChromeOptions chrome_options = new ChromeOptions();
    chrome_options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
    desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.PLATFORM, "Android");
    desired_capabilities.setCapability(AndroidMobileCapabilityType.VERSION, "6.0");
    desired_capabilities.setCapability("deviceName", "Android");
    desired_capabilities.setCapability(MobileCapabilityType.FORCE_MJSONWP, true);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.tencent.mm");
    desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "ui.LauncherUI");
    desired_capabilities.setCapability("showChromedriverLog", true);
    desired_capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
    desired_capabilities.setCapability("noReset", true);
        desired_capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,"");
    desired_capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");



    try {
        driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),desired_capabilities);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }


}

@saikrishna321 Thank you so much, this workaround works for me.

@saikrishna321 @SrinivasanTarget Thank you very much. Sorry to trouble you so much. This workaround is OK for me too~

@512433465 @megolee No worries :) glad it helped.

Can you please raise this issue in selenium issue tracker and link the issue

@saikrishna321 Already raise an issue in selenium project https://github.com/SeleniumHQ/selenium/issues/6643

Issue was closed in Selenium project:

This is correct behaviour. You will need to either remove that key from the desired or Appium will need to

It seems like it should be fixed by Appium.

@megolee @512433465 we need to raise this to selenium. They are setting browserName to chrome by default when ChromeOptions object is created.

As workaround can u try this

DesiredCapabilities desired_capabilities = new DesiredCapabilities();
ChromeOptions chrome_options = new ChromeOptions();
chrome_options.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);
desired_capabilities.setCapability(AndroidMobileCapabilityType.PLATFORM, "Android");
desired_capabilities.setCapability(AndroidMobileCapabilityType.VERSION, "6.0");
desired_capabilities.setCapability("deviceName", "Android");
desired_capabilities.setCapability(MobileCapabilityType.FORCE_MJSONWP, true);
desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.tencent.mm");
desired_capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "ui.LauncherUI");
desired_capabilities.setCapability("showChromedriverLog", true);
desired_capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
desired_capabilities.setCapability("noReset", true);
desired_capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,"");
desired_capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");



  try {
      driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),desired_capabilities);
  } catch (MalformedURLException e) {
      e.printStackTrace();
  }


}

I was able to run with above configs plus

chrome_options.setExperimentalOption("androidPackage", "com.xxx.xxx");

so it looks like this

ChromeOptions chrome_options = new ChromeOptions(); chrome_options.setExperimentalOption("androidProcess", "com.xxx.xxx"); chrome_options.setExperimentalOption("androidPackage", "com.xxx.xxx"); desired_capabilities.setCapability(ChromeOptions.CAPABILITY, chrome_options);

Was this page helpful?
0 / 5 - 0 ratings