0

I am trying to use Browsermob proxy for achieving the basic http authentication across different browsers. But facing issues, tried to search for a solution on Browsermob's GITHUB page but didn't find much help there.

Here is my code for the achieving the auth:

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

If I run above code on chrome then it still asks for auth. And nothing appears in the error console.

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

Chrome Results

If I run above code on firefox then it gives error

Your connection is not secure.

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

Firefox results

And in the console following error appears:

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

What is not correct?

Veijo
  • 264
  • 2
  • 9
Jagjeet singh
  • 31
  • 1
  • 4

1 Answers1

0
proxy.autoAuthorization("", "guest", "guest", AuthType.BASIC);

this feature does not work.

Use this instead:

String encodedCreadentials = "Basic " + (Base64.getEncoder().encodeToString("login:password".getBytes()));
proxy.addHeader("Authorization", encodedCreadentials);
oguz ismail
  • 1
  • 16
  • 47
  • 69