-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Proxy support #97
Comments
The proxy capability is not yet supported. You can currently provide a custom profile with the proxy settings in the prefs file as a workaround. Let me know if you need help with that. |
How do you provide a custom profile? We are having trouble doing that, Marionette is saying it's not a valid option. |
@sermoa Can you provide a reproducible test case? What input are you giving, what errors are you getting back? |
It looks like proxy support was added in https://hg.mozilla.org/mozilla-central/rev/27039dda138e as part of bug 1165449, so it would be interesting to find out why it does not work for you. It should be possible to use a SOCKS proxy with the following capabilities (pseudo code): capabilities = {
"requiredCapabilities": {
"proxy": {
"proxyType": "manual",
"socksProxy": url,
"socksProxyPort": port,
"socksVersion": 4,
"socksUsername": "cake",
"socksPassword": "made with cake"
}
}
}
driver = new_session(capabilities) |
I'm using c# and would love to see an example of the proxy workaround mentioned by jgraham above. Currently I've got:
and have setup the proxy_profile but the firefox instance that runs up does not use the proxy. When I manually run up firefox from a dos prompt using the same arguments, it uses the proxy fine. |
@serge-nikitin Can you provide more debug information? If you see my above comment, Marionette does have proxy support, and it works in our internal tests. |
Code:
Output in console:
Firefox 47.0, OS X 10.11.5. So this Firefox via MarionetteDriver when opens https://httpbin.org/ip shows my IP, not the proxy. When I input this proxy localhost:22001 in Firefox manually via Preferences -> Network manually it works fine. |
It looks like geckodriver only looks for proxy settings in the "requiredCapabilities" parameter. Specifying a proxy via desiredCapabilities (notice the return session capabilities shows no proxy settings):
Specifying a proxy using requiredCapabilities:
|
Yes, you are right[1]. We should work around this. [1] https://dxr.mozilla.org/mozilla-central/source/testing/marionette/driver.js#601 |
Filed bug 1282873. |
I also noticed marionette requires host and port be specified separately: Marionette is probably doing the right thing, but would it be possible for it to return an error if httpProxy is set but not httpProxyPort? (and likewise for other proxy types) |
I believe Marionette (and the spec) is doing what FirefoxDriver used to do, and it looks like that only very recently changed by a commit from @juangj: SeleniumHQ/selenium@5d1741b |
I don't think I changed how the proxy capabilities are read. As far as I can tell, FirefoxDriver has always read just the single 'httpProxy' value; I can't find any reference to 'httpProxyPort' in FirefoxDriver code, now or in the past. The fact that ChromeDriver does the same thing makes me believe that this is just a difference between OSS and W3C, and not a behavior change in FirefoxDriver. |
The geckodriver follows the W3C spec for proxy capabilities (where host and port are specified separately), so we need to translate the legacy Selenium proxy config object. This logic should be reversed (defaulting to W3C spec) when more browsers support W3C over legacy. Also, geckodriver requires the proxy to be configured through requiredCapabilities, see mozilla/geckodriver#97
@jgraham When you say "We should work around this", is it something we can work around in Geckodriver, or should we wait until Marionette itself handles it? |
Geckodriver can ensure that the proxy capability is set in the requiredCapabilities passed to marionette, regardless of where it is set in the new session command. |
I suppose the downside of that would be that Marionette would return an error in cases where the user might prefer that it failed silently. Though I don't know what sort of user actually intends for proxy settings to be merely desired instead of required. I don't suppose today's F2F discussions shed any light on this? |
Is there any update to this issue? Or any suitable/temporary work-around? Can I set "requiredCapabilities" directly using Java bindings? |
I was able to successfully work-around this by construction a JSONObject with all the necessary proxy information and setting the the desired capability "requiredCapabilities". |
@schmidtkp You should be able to: |
@andreastt Ahhh!!!! Missed the RemoteWebDriver constructor taking the requiredCapabilities! Thanks. |
Of course, I should I add we hope to fix this soon. The WebDriver WG decided to go with an entirely different design than desired- and required capabilities, which gives us an opportunity to rip out the existing capabilities implementation in Marionette. |
@andreastt Gotta love being on the bleeding edge :-) |
@andreastt Well I gave this a shot using Selenium v3.0.0-beta4 and GeckoDriver v0.11.1: DesiredCapabilities capabilities = DesiredCapabilities.firefox(); Didn't work: I suspect that it is because the requiredCapabilities JSON is not getting constructed as needed by GeckoDriver: {"requiredCapabilities": {proxy:{proxyType:manual,httpProxy:,httpProxyPort:}}} |
@jleyba You Have metioned to set RequiredCapabilities , Can you please explain how to set Required capabilities . |
Hi @schmidtkp and @andreastt and @jleyba, Got it working with Selenium v3.0.0-beta4 and GeckoDriver v0.11.1 Here is the trick, no more Proxy object, just pass a json with the new Marionette proxy format
`
` Here is a class that should be added as the new example for selenium and firefox proxy instead of the deprecated one here http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp ` import java.io.File;
` |
@smatei Yes, your approach is correct, however, it will not currently work if using RemoteWebDriver(urlAddress, cap, requiredCaps). Per Luke's comment in https://groups.google.com/forum/#!topic/selenium-developers/d8KpXpmDp2g it will be resolved in Selenium v3.1. If you wish to use RemoteWebDriver(urlAddress, cap) in the meantime, you can do so by creating a similar JSON object and adding it to the cap using the key "requiredCapabilities". |
@andreastt It's what I did, look my last line, the third parameter is the required capabilities. |
@thibaut-sticky I believe the issue is that you did not set your proxy JSON to the "requiredCapabilities" key in your DesiredCapabilities object. For example:
Also, you need to construct your proxy JSON as such:
|
@schmidtkp Look at my code, it was what I did. |
@thibaut-sticky You’re producing a desired capabilities object and passing that around to both ctor arguments, so I’m guessing you are seeing some double-wrapping. You should include a trace-level verbose geckodriver log so we can see what is going on. |
So using the code I provide in my previous comment, here the log I got. I've also tried given a required capabilities with only the proxy without success.
|
You apparently didn’t read my comment properly. You need to include a verbose, trace-level log from geckodriver. You do that by either starting geckodriver with the |
Thx for your help. I thought debug was more verbose than trace. So I tried to set the verbosity to trace, but apparently I don't do it correctly.
JsonObject options = new JsonObject();
JsonObject log = new JsonObject();
log.addProperty("level", "trace");
options.add("log", log);
capabilities.setCapability("moz:firefoxOptions", options); I know there is also a FirefoxOptions class, but there is not way to set the log verbosity. |
@thibaut-sticky That certainly looks like a bug in Selenium. |
@thibaut-sticky What I see in your code is As for why your webdriver crashes when you try |
|
@andreastt Yes indeed, the error is raised in FirefoxDriver, they check if the object they get is an instance of FirefoxOptions. And of course it's not the case. @schmidtkp Can you give me a link where I can see one of your example? |
@thibaut-sticky I would file a bug against Selenium about that. Selenium should rely on geckodriver for validation. |
I checked on the selenium repo, there is aleady a ticket about this: SeleniumHQ/selenium#3055 |
@thibaut-sticky I think I know why it might not be working for you, but I cannot explain why. When I first attempted setting the
This failed for me as well. I did not understand why (still don't), so I changed the way I constructed my JsonObject as such (note: It is being returned from a convenience/helper method in my code) :
The result from this method is used as the argument to the
Like I said, I cannot explain why |
I should note that setting proxy preferences in firefox profile fails too:
When I execute this code and watch about:config I see that network.proxy.type and network.proxy.http have the specified values, but network.proxy.http_port is equal to 0. Why so? |
Following https://bugzilla.mozilla.org/show_bug.cgi?id=1326534 setting the proxy as a desired capability should work. The fix is available in Firefox 52 onwards. |
I tried with FF 52 and 53. Proxy object is now well received. But, geckodriver complain about the type of the object:
And I'm correctly giving an object and not a String: String port = proxy.getHttpProxy().substring(proxy.getHttpProxy().indexOf(":") + 1);
String host = proxy.getHttpProxy().substring(0, proxy.getHttpProxy().indexOf(":"));
JsonObject json = new JsonObject();
json.addProperty("proxyType", "MANUAL");
json.addProperty("httpProxy", host);
json.addProperty("httpProxyPort", port);
json.addProperty("sslProxy", host);
json.addProperty("sslProxyPort", port);
capabilities.setCapability(CapabilityType.PROXY, json); |
@thibaut-sticky That would be #490 you’re running in to. The WebDriver specification says that null is not an allowed value for most of the proxy settings. I will dig into the spec to see if this is actually true and whether we need to make a change to it. |
@andreastt Thanks for the issue number, I will keep an eye on it. |
Selenium: 3.3.1 After reading through all the comments above, I tried two assumed "working" suggestions to config proxy in capabilities, and both of them failed. Can someone working on geockodriver/selenium confirm that geckodriver proxy doesn't work for selenium 3.3, as comment right above this one concluded? -------results from option 1------------------------------------------------- -----------results from option 2-------------- --------------option 1--------------------------------------------------------
-----------option 2---------------------------------- |
@stone8 I suspect the issue you’re having is https://github.com/mozilla/webdriver-rust/issues/86. |
Work in Selenium 3.14.2, Firefox 62, C# .NET 4.5 FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"GeckoDriver19", "geckodriver.exe");
|
Can not get to work new Firefox 47 / MarionetteDriver via socks proxy. Here is my code:
But browser use my machine IP, not this socks. This socks proxy is absolutely working, when I set up it in Firefox 47 via Preferences -> Network manually it works fine.
How to set up socks proxy for Selenium MarionetteDriver?
The text was updated successfully, but these errors were encountered: