Using Selenium RemoteWebDriver behind an Enterprise Proxy (Java)

I am trying to run Selenium tests on several remote automation services (Sauce Labs, Browserstack, etc.) and run into problems hitting their APIs through my corporate firewall.

Just notice, the application I'm trying to check is not behind this firewall, it is publicly available.

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 problem is that Selenium plumbing interprets the user: the key in the url is like the credentials of a proxy server, so it never leaves our network. Are there any specific tricks to tweaking this? It seems that Apache HttpClient is used under the hood.

I think we are using the NTLM proxy, it seems to use basic auth. This could be the same problem: https://code.google.com/p/selenium/issues/detail?id=7286

+4
source share
1 answer

The Google Code issue you're associated with is really the cause. Note that the problem has been resolved, so now you can enter your own implementation of CommandExecutor when creating RemoteWebDriver.

In particular, you would probably do something like this:

  • Write a custom implementation of org.openqa.selenium.remote.http.HttpClient.Factory , which behaves similarly https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/remote /internal/ApacheHttpClient.java , but allows you to enter an HttpClient instance (or HttpClientFactory if you want subclasses). This is a pretty simple interface and a simple implementation for copying, so it should be easy.
  • Create an instance of org.apache.http.impl.client.BasicCredentialsProvider with different credentials for different hosts (for more details see org.apache.http.auth.AuthScope ).
  • Use org.apache.http.impl.HttpClientBuilder to create a client with your credential provider.
  • Create an instance of HttpCommandExecutor by passing an instance of your custom factory and entering your client.
  • Create an instance of RemoteWebDriver by passing it to the command executor.
+3
source

Source: https://habr.com/ru/post/1240827/


All Articles