在企业代理(Java)背后使用Selenium RemoteWebDriver [英] Using Selenium RemoteWebDriver behind corporate proxy (Java)

查看:200
本文介绍了在企业代理(Java)背后使用Selenium RemoteWebDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一些远程自动化服务(Sauce Labs,Browserstack等)上运行Selenium测试,并遇到通过我的公司防火墙点击其API的问题。

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);

问题似乎是Selenium解释用户的问题:将url作为代理凭据键入,因此它永远不会离开我们的网络。是否有任何特定的技巧来配置它?它似乎使用Apache引擎盖下的HttpClient。

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.

认为我们正在使用NTLM代理,它似乎使用基本身份验证。可能是同一个问题从这里: https://code.google.com/p/selenium/问题/详细信息?id = 7286

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

推荐答案

您链接到的Google代码问题确实似乎是注意,问题已经解决,因此您现在可以在创建RemoteWebDriver时注入自己的CommandExecutor实现。

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:


  • Wri自定义的 org.openqa.selenium.remote.http.HttpClient.Factory 的实现,其行为类似于 https://github.com/SeleniumHQ/selenium/blob/master /java/client/src/org/openqa/selenium/remote/internal/ApacheHttpClient.java ,但允许您注入 HttpClient 实例(或 HttpClientFactory 实例,如果你想继承那个)。这是一个非常简单的界面,一个简单的复制实现,所以这应该很容易。

  • 创建一个 org.apache.http.impl.client的实例。 BasicCredentialsProvider 具有不同主机的不同凭据(有关详细信息,请参阅 org.apache.http.auth.AuthScope )。

  • 使用 org.apache.http.impl.HttpClientBuilder 使用您的凭据提供程序构建客户端。

  • 构造实例 HttpCommandExecutor ,传入自定义工厂的实例并注入客户端。

  • 构造的实例RemoteWebDriver ,传入命令执行程序。

  • 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.

这篇关于在企业代理(Java)背后使用Selenium RemoteWebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆