Basic Auth with Geb and FirefoxDriver

Update: Unfortunately this solution is not working any more with recent versions of Firefox and FirefoxDriver.

I spent some time currently to automate integration tests and webtests, mainly using spock and, for the web test part, geb.

Unfortunately I did not find any (simple) working example with basic auth. I spent quite a few hours trying it and found a solution now. As stated here, it should be possible to pass username and password in your url: http://user:pass@host.tld.

To avoid an alert box warning the user that the browser is going to login with the given credentitals, Firefox' property signon.autologin.proxy has to be set to true.

This can be achieved initializing FirefoxDriver (Groovy example) with:

driver = {
	FirefoxProfile profile = new FirefoxProfile();
	// this avoids the "Your are signing in to..." alert
	profile.setPreference("signon.autologin.proxy", true);
	DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
	desiredCapabilities.setCapability('acceptInsecureCerts', true);
	FirefoxOptions options = new FirefoxOptions().setProfile(profile)
	new FirefoxDriver(options)

There is an excellent example project by geb which uses the latest versions of selenium and FirefoxDriver (marionette).

I created a pull request on this example project for documentation purposes implementing this change.