如何在seleniumWebdriver中为Chrome浏览器设置代理身份验证 [英] How to set Proxy Authentication in seleniumWebdriver for Chrome Browser

查看:637
本文介绍了如何在seleniumWebdriver中为Chrome浏览器设置代理身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使Web应用程序selenium 2.0 [webdriver + java]自动化.该Web应用程序当前已部署在本地网络上的UAT服务器中.我的测试用例正在执行,但我必须手动输入Proxy Authentication测试执行开始时我的Chrome实例的详细信息.我已经尝试了堆栈溢出时提供的所有解决方案,但是仍然弹出验证消息.

I'm trying to Automate a web application selenium 2.0 [webdriver+java].The web application is currently deployed in our UAT servers on our local network.My test cases are executing, but I have to manually enter the Proxy Authentication details for my Chrome instance at the start of the test execution. I have tried all the solutions provided on stack overflow but still, the authentication message pops out.

这是我在驱动程序初始化过程中使用的代码

This is the code I'm using in my driver initializing process

包com.misyn.ess.ui;

package com.misyn.ess.ui;

import java.util.Arrays;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

/**
 *
 * @author User
 */
public class DriverClass {

    private String baseUrl;
    private String driverPath;
    private String driverName;
    private static WebDriver driver;
    private static DriverClass driverClass;

        private DriverClass() {
            try {
                baseUrl = "http://192.168.0.10:8282/ess";
                driverPath = "E:\\Work_Folder\\SelTools\\chromedriver.exe";
                driverName = "webdriver.chrome.driver";

                //Set the location of the ChromeDriver
            System.setProperty(driverName, driverPath);
            //Create a new desired capability
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            // Create a new proxy object and set the proxy
            Proxy proxy = new Proxy();
            proxy.setHttpProxy("192.168.0.200:3128");
            proxy.setSocksUsername("avishka");
            proxy.setSocksPassword("12345678");
            //Add the proxy to our capabilities 
            capabilities.setCapability("proxy", proxy);
            //Start a new ChromeDriver using the capabilities object we created and added the proxy to
            driver = new ChromeDriver(capabilities);

            //Navigation to a url and a look at the traffic logged in fiddler
            driver.navigate().to(baseUrl);


    //            System.setProperty(driverName, driverPath);
    //            driver = new ChromeDriver();
    //            driver.get(baseUrl);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

与在弹出式窗口中手动输入详细信息相比,有人能给我一个解决方案的方法,该方法是如何从应用程序本身中为该代理提供用户名和密码,这将非常感谢您.

Can anyone give me a solution how to give this proxy username and password thing from the application itself than manually entering details on the pop-up(Authentication), any help would be much appreciated.Thanks

当前回答的仅用于

从Selenium 3.4开始,它仍处于测试阶段 目前,仅针对InternetExplorerDriver实施了实现

As of Selenium 3.4 it is still in beta Right now implementation is only done for InternetExplorerDriver

我在使用硒3.0和Google Chrome作为我的网络浏览器的地方.

Where I'm using selenium 3.0 and Google Chrome as my web browser.

推荐答案

    public class DriverClass {

    private String baseUrl;
    private String driverPath;
    private String driverName;
    private static WebDriver driver;
    private static DriverClass driverClass;

    public DriverClass() {
        try {
            baseUrl = "http://192.168.0.10:8282/ess";
            driverPath = "E:\\Work_Folder\\SelTools\\chromedriver.exe";
            driverName = "webdriver.chrome.driver";
            System.setProperty(driverName, driverPath);

            Proxy proxy = new org.openqa.selenium.Proxy();
            proxy.setSslProxy("192.168.0.200" + ":" + 3128);
            proxy.setFtpProxy("192.168.0.200" + ":" + 3128);
            proxy.setSocksUsername("avishka");
            proxy.setSocksPassword("12345678");

            DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
            desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);


            driver = new ChromeDriver(desiredCapabilities);


            driver.get(baseUrl);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

已添加代理设置,并具有所需的功能,以将值传递给代理身份验证,终于可以使用

The proxy setting has been added with desired capabilities to pass values to proxy authentication,worked finally

这篇关于如何在seleniumWebdriver中为Chrome浏览器设置代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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