Chris Lowis
Chris Lowis

Reputation: 560

HTTP Basic Auth and Proxy for selenium-webdriver (ruby bindings)

I'm attempting to use the selenium-webdriver [ruby bindings][1] to access an internal web-site that requires a proxy to be configured, and HTTP Basic Auth.

I currently have:

  require "selenium-webdriver"
  driver = Selenium::WebDriver.for :firefox
  driver.navigate.to "http://my-internal-site.com"

But this fails due to both the proxy and http auth issues. If I add my username and password to the URL (i.e. http://username:[email protected]) I can do basic authentication on another site that doesn't require the proxy, but this doesn't seem like an ideal solution.

Any suggestions?

Upvotes: 1

Views: 4555

Answers (4)

Prashanth Sams
Prashanth Sams

Reputation: 21169

If you're using Google-Chrome, try creating a custom extension and import it through ChromeOptions. It supports http(s) that wasn't supported by browsermob_proxy in Chrome. In-case of redirects testing, this is the only way that will help you as of now...

For details, check this post https://devopsqa.wordpress.com/2018/08/05/handle-basic-authentication-in-selenium-for-chrome-browser/

Upvotes: 0

MushyPeas
MushyPeas

Reputation: 2518

I tried the approach with AutoIt and it worked fine until Selenium 2.18.0, because they implemented UnhandledAlertException, which will be thrown as soon as the proxy login dialog pops up. if you try to catch it, you end up with an driver=null, you would need to loop the attempt to create a driver and trust into your AutoIt Script to kill the window.

Upvotes: 0

David
David

Reputation: 3441

Until there is full support for this across browsers for WebDriver (or Selenium), alternate option is to integrate w/ desktop GUI automation tools, where the desktop GUI tool will automate the HTTP authentication part. You can probably find some examples for this or file downloads, uploads if you google for things like "Selenium AutoIt", etc.

For a cross platform solution, replace AutoIt with Sikuli or something similar.

Upvotes: 0

AutomatedTester
AutomatedTester

Reputation: 22438

Unfortunately doing http://username:[email protected] has been the standard way of doing but with more and more browsers blocking this approach. Patrick Lightbody of BrowserMob discussed in the company blog on how they get it to work.

Upvotes: 2

Related Questions