Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 无法使用Browsermob代理执行http基本身份验证_Selenium_Selenium Webdriver_Http Authentication_Browsermob Proxy - Fatal编程技术网

Selenium 无法使用Browsermob代理执行http基本身份验证

Selenium 无法使用Browsermob代理执行http基本身份验证,selenium,selenium-webdriver,http-authentication,browsermob-proxy,Selenium,Selenium Webdriver,Http Authentication,Browsermob Proxy,我正在尝试使用Browsermob代理来实现跨不同浏览器的基本http身份验证。但面对这些问题,他试图在Browsermob的GITHUB页面上搜索解决方案,但没有找到多少帮助 以下是我实现身份验证的代码: // start the proxy BrowserMobProxy proxy = new BrowserMobProxyServer(); proxy.start(); proxy.autoAuthorization("", "username", "p

我正在尝试使用Browsermob代理来实现跨不同浏览器的基本http身份验证。但面对这些问题,他试图在Browsermob的GITHUB页面上搜索解决方案,但没有找到多少帮助

以下是我实现身份验证的代码:

    // start the proxy
    BrowserMobProxy proxy = new BrowserMobProxyServer();
    proxy.start();

    proxy.autoAuthorization("", "username", "password", AuthType.BASIC);

    // get the Selenium proxy object
    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

    // configure it as a desired capability
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
如果我在chrome上运行上面的代码,那么它仍然要求auth。错误控制台中不会显示任何内容

System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + config.getChromeDriverPath());
WebDriver driver = new ChromeDriver(capabilities);

如果我在firefox上运行上述代码,则会出现错误

您的连接不安全

在控制台中出现以下错误:

FAILED CONFIGURATION: @BeforeClass launchBrowser
org.openqa.selenium.WebDriverException: 
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'USER', ip: '192.168.43.57', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: false, browserName: firefox, browserVersion: 60.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 8180, moz:profile: C:\Users\USER\AppDat..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 6.3, proxy: Proxy(manual, http=tarun:49..., rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 6b53fdb7-78fe-44cb-a3b9-2592494ae7a5
什么是不正确的

proxy.autoAuthorization("", "guest", "guest", AuthType.BASIC);
此功能不起作用

改用这个:

String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString("login:password".getBytes()));
proxy.addHeader("Authorization", encodedCreadentials);

在课前启动浏览器之前,你能给我们看一下吗?@DebanjanB:谢谢你的帮助。以下是该课程的链接:
String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString("login:password".getBytes()));
proxy.addHeader("Authorization", encodedCreadentials);