简体   繁体   English

如何将代理设置为 selenium 远程 Web 驱动程序?

[英]How can I set proxy to selenium remote web driver?

I'm trying to execute aws device farm sample behind corporate proxy.我正在尝试在公司代理后面执行 aws 设备场示例。 At first I faced a proxy problem when connecting aws.起初我在连接 aws 时遇到了代理问题。 I managed to solve this one by setting aws Proxy Configuration.我设法通过设置 aws 代理配置来解决这个问题。 my another question on this matter 我关于这个问题的另一个问题

Now I'm facing another proxy problem.现在我面临另一个代理问题。 When creating remotewebdriver unknown host name error occurred.创建 remotewebdriver 时发生未知主机名错误。 This is my source code.这是我的源代码。

@Before
public void setUp() {
    try {
        ProxyConfiguration.Builder proxyConfig = ProxyConfiguration.builder();
        proxyConfig.endpoint(new URI("<YOUR PROXY URL>"));
        proxyConfig.username("<YOUR USER ID>");
        proxyConfig.password("YOUR PASSWORD");
        ApacheHttpClient.Builder httpClientBuilder =
                ApacheHttpClient.builder()
                                .proxyConfiguration(proxyConfig.build());

        String myARN = "<YOUR ARN>";
        DeviceFarmClient client  = DeviceFarmClient.builder()
                .credentialsProvider(DefaultCredentialsProvider.create())
                .region(Region.US_WEST_2)
                .httpClientBuilder(httpClientBuilder)
                .overrideConfiguration(ClientOverrideConfiguration.builder().build())
                .build();
        CreateTestGridUrlRequest request = CreateTestGridUrlRequest.builder()
                .expiresInSeconds(300)        // 5 minutes
                .projectArn(myARN)
                .build();
        URL testGridUrl = null;
        CreateTestGridUrlResponse response = client.createTestGridUrl(request);
        testGridUrl = new URL(response.url());
        driver = new RemoteWebDriver(testGridUrl, DesiredCapabilities.chrome()); //error occurred at this line.
    } catch (Exception e) {
        e.printStackTrace();
    }
}

It's the error log.这是错误日志。

UnknownHostException: testgrid-devicefarm.us-west-2.amazonaws.com

I tryed some measures to soleve this problem, but none of these works well.我尝试了一些措施来解决这个问题,但这些措施都没有奏效。 Below are some of my trials.下面是我的一些尝试。

  1. use browsermob library使用 browsermob 库
DesiredCapabilities cap = DesiredCapabilities.chrome();
BrowserMobProxy bmp = new BrowserMobProxyServer();
bmp.setChainedProxy(
        new InetSocketAddress("<PROXY HOST>", Integer.valueOf("<PROXY PORT>")));
bmp.chainedProxyAuthorization("<USER>", "<PASSWORD>", AuthType.BASIC);
bmp.setTrustAllServers(true);
bmp.start();
Proxy proxy = ClientUtil.createSeleniumProxy(bmp);
cap.setCapability(CapabilityType.PROXY, proxy);
driver = new RemoteWebDriver(testGridUrl, cap);
  1. use browserup instead of browsermob使用 browserup 而不是 browsermob

It also didn't work well and same error (UnknownHostException) was occurred.它也不能很好地工作,并且发生了相同的错误 (UnknownHostException)。

  1. use Authenticator.setDefault使用 Authenticator.setDefault

It also didn't work well.它也没有很好地工作。

Authenticator.setDefault(new Authenticator() {
    public PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(proxyUserName, proxyPassword.toCharArray());
    }
} );
System.setProperty("http.proxyUser", proxyUserName);
System.setProperty("http.proxyPassword", proxyPassword);

The error message is..错误信息是..

java.io.IOException: Failed to authenticate with proxy

How can I address this issue?我该如何解决这个问题?

Thanks.谢谢。

The Selenium client running in your computer needs to connect to AWS Device Farm using the corporate proxy.在您的计算机中运行的 Selenium 客户端需要使用公司代理连接到 AWS Device Farm。

The proxy for your webdriver connection need to be set.需要设置 webdriver 连接的代理。

The example in Javascript is below. Javascript 中的示例如下。

const driver = await new Builder()
  .usingWebDriverProxy(process.env.HTTPS_PROXY || '')
  .usingServer(urlString)
  .withCapabilities(...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用python在selenium chrome web驱动程序中使用身份验证设置代理 - How can i set proxy with authentication in selenium chrome web driver using python 如何使用远程驱动程序在selenium中进行auth代理 - How to auth proxy in selenium with Remote driver 如何实例化远程Web驱动程序,以便我可以在Java和Selenium中通过Serenity并行运行测试 - How to instantiate Remote Web Driver so I can run tests in parallel using Java and Selenium with Serenity Selenium远程Web驱动程序无法启动 - Selenium remote web driver can't start Selenium:如何使用web Driver设置selenium - Selenium: how to set up selenium with web Driver 如何使用selenium web-driver设置新的元素样式 - How can i set new style of element using selenium web-driver 如何在传递 ChromeOptions 和 Selenium Grid 独立服务器 url 时使用 WebDriverManager 初始化 Chrome Remote web 驱动程序? - How can I initialize Chrome Remote web driver using WebDriverManager while passing ChromeOptions and a Selenium Grid standalone server url? 如何在不将IE驱动程序或Chrome驱动程序添加到硒Web驱动程序的情况下启动已安装的浏览器? - How can I start installed browser without adding IE driver or Chrome driver in selenium web driver? 我如何处理Selenium Web驱动程序中的动态“ Id”? - how i can handle dynamic “Id” in Selenium web driver? 如何在Selenium的Javascript Web驱动程序中处理警报? - How Can I Handle Alerts In Selenium's Javascript Web Driver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM