ericmckean / chromedriver

Automatically exported from code.google.com/p/chromedriver
0 stars 0 forks source link

unrecognized chrome option: prefs => Java for Chrome in Android #1014

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Issue Description:
On trying to use "prefs" in ChromeOptions for Android chrome, I get an error, 
unrecognized chrome option: prefs

Steps to reproduce (if relevant, you MUST provide a simplified html page or
link to public site):

1. Connect an Android device and run the adb server
2. Run chromedriver.exe latest version (v2.13.307647)
3. Execute the below Java code

DesiredCapabilities capabilities = new DesiredCapabilities();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("androidPackage", "com.android.chrome");
chromeOptions.setExperimentalOption("prefs", new 
JSONObject().put("profile.default_content_settings.geolocation", 2));
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
capabilities.setCapability("locationContextEnabled", true);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), 
capabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("http://baidu.com");

-----Other helpful tips:
Log file
$>chromedriver.exe --verbose

Starting ChromeDriver 2.13.307647 (5a7d0541ebc58e69994a6fb2ed930f45261f3c29) on
port 9515
Only local connections are allowed.
[28.462][INFO]: COMMAND InitSession {
   "desiredCapabilities": {
      "chromeOptions": {
         "androidPackage": "com.android.chrome",
         "args": [ "--disable-translate", "--disable-save-password-bubble" ],
         "extensions": [  ],
         "prefs": {
            "profile.default_content_settings.geolocation": 2
         }
      },
      "locationContextEnabled": true
   }
}
[28.463][INFO]: RESPONSE InitSession unknown error: cannot parse capability: chr
omeOptions
from unknown error: unrecognized chrome option: prefs
[28.463][DEBUG]: Log type 'driver' lost 1 entries on destruction

Original issue reported on code.google.com by surat....@gmail.com on 11 Jan 2015 at 9:23

GoogleCodeExporter commented 9 years ago
Android version is 4.3 and device chrome version is 39.0.2171.93, chromedriver 
version is 2.13

Original comment by surat....@gmail.com on 11 Jan 2015 at 9:38

GoogleCodeExporter commented 9 years ago

Original comment by andrewch...@chromium.org on 21 Jan 2015 at 12:01

GoogleCodeExporter commented 9 years ago
do prefs  this way
        Map<String, Object> prefs = new Hashtable<String, Object>();
        prefs.put("profile.default_content_settings.geolocation", 2);
        // 
        ChromeOptions chromeOptions = new ChromeOptions(); 
        //chromeOptions.setExperimentalOption("androidPackage", "com.android.chrome");      
        chromeOptions.setExperimentalOption("prefs", prefs);  
        //
        DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); 
        capabilities.setCapability("locationContextEnabled", true);

Original comment by andrewch...@chromium.org on 21 Jan 2015 at 11:27

GoogleCodeExporter commented 9 years ago
With the proposed way, the test runs on the desktop chrome browser and it does 
not go to my connected Android device. I get "error : unrecognized chrome 
option: prefs." if I add this line of code.
chromeOptions.setExperimentalOption("androidPackage", "com.android.chrome");    

Original comment by surat....@gmail.com on 22 Jan 2015 at 8:46

GoogleCodeExporter commented 9 years ago
following work for me on emulator
        Map<String, Object> prefs = new Hashtable<String, Object>();
        prefs.put("profile.default_content_settings.geolocation", 2);
        Map<String, Object> chromeOptions = new HashMap<String, Object>();
        //chromeOptions.setExperimentalOption("androidPackage", "com.android.chrome");  
        chromeOptions.put("androidPackage", "com.android.browser"); 
        chromeOptions.put("androidActivity", "com.android.browser.BrowserActivity");    
        chromeOptions.put("androidDeviceSerial", "emulator-5554");  

    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); 
        capabilities.setCapability("locationContextEnabled", true);
        //
        capabilities.setCapability("prefs", prefs);  

Original comment by andrewch...@chromium.org on 26 Jan 2015 at 11:11

GoogleCodeExporter commented 9 years ago
Hi Andrew, I want to invoke com.android.chrome and not com.android.browser like 
in your example. Basically, I want to invoke chrome om my real device and then 
go to "http://www.baidu.com". There, I don't want to see the location prompt. 
So, I modified the code a bit but still that prefs is not applied, I still see 
the location prompt.

Map<String, Object> prefs = new Hashtable<String, Object>();
prefs.put("profile.default_content_settings.geolocation", 2);
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("androidPackage", "com.android.chrome");  
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); 
capabilities.setCapability("locationContextEnabled", true);
capabilities.setCapability("prefs", prefs);  
driver= new RemoteWebDriver(new URL("http://127.0.0.1:9515"), capabilities);

Original comment by surat....@gmail.com on 27 Jan 2015 at 6:35

GoogleCodeExporter commented 9 years ago
Hi,

1. you would like to invoke chrome browser in a android device? 
2.  open http://www.baidu.com  can not tell what is location prompt.

Original comment by andrewch...@chromium.org on 27 Jan 2015 at 6:33

GoogleCodeExporter commented 9 years ago
Sorry, if I confused.

1. I am able to launch chrome on my Android device with the code snippet I 
shared following your suggestion. Thanks. - No issues here.
2. Now, I want chrome to suppress the location prompt in Android device. I 
thought of three options-
    a. Use command line argument for chromedriver.exe - I could not figure out a suitable option or argument to do this.
    b. Use chromeoptions or capability in the code to control this prompt (http://peter.sh/experiments/chromium-command-line-switches/) - I tried the options you suggested with prefs but not working. I still get the location prompt.
    c. Issue 138 had one idea which I was exploring to be able to use for Android chrome but is not working. 

Is it not possible to suppress the location prompt by chrome on Android at all ?

Original comment by surat....@gmail.com on 27 Jan 2015 at 7:16

GoogleCodeExporter commented 9 years ago
1. can you send(attach) me a screen shot of suppressing the location prompt in 
Android device
2. this won't be chromedriver.exe argument, it will be chrome switch.  Once I 
understand ,  we will figure out

Original comment by andrewch...@chromium.org on 27 Jan 2015 at 7:50

GoogleCodeExporter commented 9 years ago
Attached is the screenshot. The screenshot shows the location prompt which I am 
trying to suppress/dismiss but unable to.

Original comment by surat....@gmail.com on 28 Jan 2015 at 2:58

Attachments:

GoogleCodeExporter commented 9 years ago
you mean the URL box http://www.baidu.com?

Original comment by andrewch...@chromium.org on 28 Jan 2015 at 6:23

GoogleCodeExporter commented 9 years ago
I want to suppress/dismiss the prompt which says "http://www.baidul.com wants 
to use your device's location." prompt. These prompts block most of the browser 
window blocking further execution of my script.

Original comment by surat....@gmail.com on 28 Jan 2015 at 9:11

GoogleCodeExporter commented 9 years ago

   you want to turn off location sharing

1. --enable-strict-powerful-feature-restrictions ⊗    Blocks insecure usage of 
number of powerful features (geolocation, for example) that we haven't yet 
deprecated for the web at large

2. turn off manually -  https://support.google.com/chrome/answer/142065?hl=en

Original comment by andrewch...@chromium.org on 28 Jan 2015 at 11:02

GoogleCodeExporter commented 9 years ago
Thanks for the suggestion.

1. I am using below code which suppresses the translate prompt but still does 
not suppress the location prompt (Please refer to my earlier screenshot).

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("androidPackage", "com.android.chrome");
chromeOptions.addArguments("--enable-strict-powerful-feature-restrictions");
chromeOptions.addArguments("--disable-translate");
capabilities.setCapability("locationContextEnabled", true);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), capabilities);

2. Using similar option as per your suggestion (manual turn off), I am able to 
turn off. But unable to turn on for all sites. There is not such option to turn 
on in Android.

Original comment by surat....@gmail.com on 31 Jan 2015 at 1:06

GoogleCodeExporter commented 9 years ago
1. this is new to me, need some research.
2. you don't want to turn off for all sites.  only the site you S/W test on?

Original comment by andrewch...@chromium.org on 31 Jan 2015 at 1:20

GoogleCodeExporter commented 9 years ago
Thanks for looking into this. I will wait for your research findings.

Original comment by surat....@gmail.com on 31 Jan 2015 at 1:48

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Strange, why it does not work on the same way on my Android 4.3 device. I am 
using Sony Xperia M C1904 model. It still prompts location.

Original comment by surat....@gmail.com on 2 Feb 2015 at 8:47

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
tried Sansumg S4, and it will show up.  Nexus 7 does not show up.(may have 
other reason)
need more research.

Original comment by andrewch...@chromium.org on 2 Feb 2015 at 10:33

GoogleCodeExporter commented 9 years ago

Original comment by andrewch...@chromium.org on 3 Feb 2015 at 6:49

GoogleCodeExporter commented 9 years ago

Original comment by samu...@chromium.org on 21 Feb 2015 at 12:19