Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxies: Whats works and what doesn't #1019

Closed
fredericOfTestfabrik opened this issue Oct 18, 2017 · 10 comments
Closed

Proxies: Whats works and what doesn't #1019

fredericOfTestfabrik opened this issue Oct 18, 2017 · 10 comments

Comments

@fredericOfTestfabrik
Copy link

System

  • Version: v0.19.0
  • Platform: Windows/Mac/Ubuntu
  • Firefox: 54-56
  • Selenium: 3.6 / Java Bindings

I am trying to evaluate how Firefox can be configured to use a proxy during a selenium service. The only Version that works for me right now is FF47. as this version does not use the new geckodriver.

Using a google search, I get multiple contradicting approaches. Some say you can configure it using Profiles (which is not an option for me), others say you can do it using a specifically built capability. The latest info I could find in this repo was, that proxies will start working with Firefox 57.

As of now, using the Proxy Object from Selenium 3.6 in the capabilities, I only get the following error:

org.openqa.selenium.WebDriverException: com.google.gson.JsonPrimitive cannot be cast to com.google.gson.JsonObject
Command duration or timeout: 1.63 seconds
Build info: version: '3.6.0-TF-0.1', revision: 'eb50837', time: '2017-10-13T12:16:32.25Z'
System info: host: 'dhcp75-39.start.uni-saarland.de', ip: '134.96.75.39', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_102'
Driver info: driver.version: RemoteWebDriver
....

Unfortunately, I could not find any official Documentation or Guide on what works and how it works.

To summarize my question in one sentence:

Which Firefox Version can use proxies with Selenium 3.6, how do I configure it and which geckodriver version do I need?

@andreastt
Copy link
Contributor

I’m not entirely up to speed in this area and @whimboo will probably be able to give a better answer, but generally everything to do with proxies and the proxy configuration object apart from HTTP proxy authentication should work in the latest Firefox Nightly, possibly also in 57, with geckodriver 0.19.0.

The error message you mention, org.openqa.selenium.WebDriverException: com.google.gson.JsonPrimitive cannot be cast to com.google.gson.JsonObject, stems from the Selenium client you are using and you should file a bug for that.

@schmidtkp
Copy link

@fredericOfTestfabrik I use the Java client bindings and also have to use several proxies. Currently, the Proxy object does not work (for me) using Java client bindings v3.6.0, GeckoDriver v0.19.0, and Firefox v56.0 (stable). It hasn't worked for me for some time now (since v3.3.x approx). For a brief period I was able to use the capability "requiredCapabilities" and setting its value to a JsonObject that defined the proxy. This is no longer viable. Currently I use FirefoxProfile.setPreference() and set appropriate "network.proxy.*" preferences, as such:

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("network.proxy.type", 1) // Proxy.ProxyType.MANUAL ordinal value
profile.setPreference("network.proxy.http", host);
profile.setPreference("network.proxy.http_port", port);
profile.setPreference("network.proxy.ssl", host);
profile.setPreference("network.proxy.ssl_port", port);
profile.setPreference("network.proxy.ftp", host);
profile.setPreference("network.proxy.ftp_port", port);
profile.setPreference("network.proxy.socks", host);
profile.setPreference("network.proxy.socks_port", port);

This is working well for me for the time being. Waiting on Firefox v57 (stable) for alleged fix that will allow for using the Proxy object again.

@andreastt
Copy link
Contributor

It sounds to me like a bug needs to be filed on Selenium to get the Proxy object in the Java client fixed. Setting the preferences on the profile and passing that in is extremely wasteful, and using the prefs key on the moz:firefoxOptions object is a better workaround.

@whimboo
Copy link
Collaborator

whimboo commented Oct 18, 2017

Yes, by using Firefox 57 beta and geckodriver 0.19 everything should work for proxies. If you have problems with the proxy capabilities please let me know, and as best also attach a trace level log. Thanks.

@schmidtkp
Copy link

@andreastt Forgive my ignorance, but how does one utilize the prefs key and moz:firefoxOptions with the Java client bindings? Any documentation regarding this "better workaround"?

@andreastt
Copy link
Contributor

@schmidtkp Sorry, I don’t know exactly how, or even if exposed, in the Java client bindings.

The resultant JSON Object should look like this:

{"moz:firefoxOptions":
  {"prefs": {
    "foo": "bar"
  }
}

@thc202
Copy link
Contributor

thc202 commented Oct 19, 2017

It's exposed in Java bindings with the FirefoxOptions class.

@fredericOfTestfabrik
Copy link
Author

@andreastt @whimboo

Thank you for the Information. The prefs workaround works flawlessly in Firefox 54 and 55 using geckodriver 0.18 and 0.19

@whimboo
Copy link
Collaborator

whimboo commented Oct 20, 2017

Great. That's wonderful to hear. Looks like we can close this issue.

@whimboo whimboo closed this as completed Oct 20, 2017
@lock
Copy link

lock bot commented Aug 17, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.

@lock lock bot locked and limited conversation to collaborators Aug 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants