Search code examples
seleniumselenium-webdriverbehatmink

How to handle Behat Mink HTTP basic authentication


I am working in Firefox, via the Behat Mink framework's bridge to the Selenium 2 driver. When I run the test, I get an HTTP proxy authentication popup. My behat.yaml file has a basic authentication username and password but they don't work. Could you please give me an idea to handle this popup authentication?

enter image description here

I also tried with the setBasicAuth() function, but it did not work for me:

$this->getSession()->getDriver()->setBasicAuth('dharmalingam' ,'Welcome123');

My behat.yml contains:

extensions:
      Behat\MinkExtension\Extension:
        default_session: selenium2
        javascript_session: selenium2
        goutte:              ~
        selenium2:
          browser: 'firefox'
          wd_host: http://dharmainin:[email protected]:80/wd/hub
          capabilities:
              version: ~
              platform: 'Windows 2008'
      features/extensions/SauceIntegration.php:
        param1: value1
    context:
        parameters:
          base_url: "http://example.com/"
          basic_auth:
            username: 'dharmalingam'
            password: 'Welcome123'

Solution

  • Are you being prompted for authentication details for an HTTP proxy, or the site itself? If the site itself, you should be able to embed the username and password into the URL itself, using the username:password@domain standard. The following should work in your behat.yml file:

    base_url: http://dharmalingam:[email protected]/
    

    (Similar to the authentication details embedded into the saucelabs URL in the snippet above.)