I'm trying to run Selenium tests on a few remote automation services (Sauce Labs, Browserstack, etc) and run into issues hitting their API through my corporate firewall.
Just a note, the app I'm trying to test is not behind this firewall, it is publicly accessible.
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("platform", "Windows 7");
caps.setCapability("version", "9.0");
caps.setCapability("idleTimeout", "300");
caps.setCapability("name", "Invitation Tests");
driver = new RemoteWebDriver(new URL("https://user:key@saucelabs.com), caps);
The issue seems to be the plumbing of Selenium interprets the user:key in the url as proxy credentials, so it never leaves our network. Are there any specific tricks to configuring this? It seems to use Apache HttpClient under the hood.
I think we're using an NTLM proxy, it seems to use basic auth. It might be the same issue from here: https://code.google.com/p/selenium/issues/detail?id=7286
The Google Code issue that you linked to does indeed appear to be the cause. Note that the issue has been resolved, so you can now inject your own implementation of CommandExecutor when creating a RemoteWebDriver.
Specifically, you would probably do something like this:
- Write a custom implementation of
org.openqa.selenium.remote.http.HttpClient.Factory
that behaves similarly to the one at https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/remote/internal/ApacheHttpClient.java, but allows you to inject the HttpClient
instance (or HttpClientFactory
instance, if you want to subclass that). It's quite a simple interface, and a simple implementation to copy, so this should be easy.
- Create an instance of
org.apache.http.impl.client.BasicCredentialsProvider
with different credentials for the different hosts (see org.apache.http.auth.AuthScope
for details).
- Use
org.apache.http.impl.HttpClientBuilder
to construct a client with your credential provider.
- Construct an instance of
HttpCommandExecutor
, passing in an instance of your custom factory and injecting your client.
- Construct an instance of
RemoteWebDriver
, passing in the command executor.