Quick one today just to get the ball rolling – but not an unimportant one as I see this get asked a fair bit.
Let’s say you’re working on a web app that is secured with basic authentication, not that there’s anything wrong that with. Let’s say you’re also working with developers who are clearly happy enough to let the browser handle the authentication of the session. How do you get over that hurdle in your selenium script?
The alternative? Stick the credentials into the overall URI.
(As an aside before I jump into any code examples, most of the will be done with NodeJS because that’s just how I roll.)
driver = new webdriver.Builder().withCapabilities(capabilities).build(); driver.get('http://username:email@example.com:8080');
So, by simply including the username and password as a preface to the actual domain name, you can instruct the browser to use those credentials and in theory avoid the browser waiting for user input.
There are a few caveats with this approach, mostly I can’t guarantee it’d actually work on every single browser on every single OS combination. As of writing, this approach did work on the latest Firefox, Chrome and IE on OSX Yosemite and Windows 8.1. As for mobiles, I haven’t tried that yet.
Secondly, you should never be sending any form of credentials in a URL (or indeed in headers / query strings as you may do with basic auth anyway) over a non-HTTPS connection. But you knew that.
Of course a better approach is to tell your engineering team to not be lazy and just build a fecking log-in form, even if you are going to use basic authentication. Not that there’s anything wrong with that.