How do I use Selenium to login to sites that require username and password?
Here's the suggestion that was made to me by Adam Goucher on the Selenium IRC channel ( irc://irc.freenode.net/selenium ):
Take advantage of the situation of a completely clean browser cache/cookie history. Code your test to do the login.
However, instead of hard-coding into your code a username and password, keep a deliberately non-source-code-revisioned configuration file with the username and password locally on the client with the username and password stored there, and have your Selenium client code retrieve the username and password from there when the Selenium code executes.
Thats because selenium server starts new profile for browser everytime, so your saved cookies and bookmarks do not exist on this profile.
First create a profile, for firefox it is given here
then bundle this profile to your selenium server like this
SeleniumServer server = new SeleniumServer(); RemoteControlConfiguration rcc = new RemoteControlConfiguration(); //rcc.setPort(4444); File newFirefoxProfileTemplate = new File(ReadConFile.readcoFile("fiefoxProfilePath")); rcc.setFirefoxProfileTemplate(newFirefoxProfileTemplate); server = new SeleniumServer(rcc); server.start(); DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*chrome",ReadConFile.readcoFile("serverName"));
to know your firefoxTemplate click here