1

How to implement "Rememeber me" automation in Firefox with web driver? I am using web driver 2.20, Eclipse IDE, Firefox 9.0

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ShravRao
  • 11
  • 3
  • What do you mean by Remember me automation? Add more details please. – vidit Jul 11 '12 at 16:31
  • I have LoginPage with username,Password and rememberme Checkbox. Automation of logging in by checking the rememberme checkbox, and closing the browser. If I try to login again, it asks me for the credentials. Expecte behaviour : Login in without asking for credentials. In IE its working fine but in Firefox the rememberme cookie gets cleared and it doesnt login. – ShravRao Jul 20 '12 at 11:41

2 Answers2

0

The reason you are experiencing that is because every time you start firefox, webdriver creates a new anonymous profile with no cookies. You can make it use a particular profile, which should retain cookies.

File profileDir = new File("path/to/profile");
FirefoxProfile profile = new FirefoxProfile(profileDir);
WebDriver driver = new FirefoxDriver(profile);

FirefoxProfile has many other options, like adding extensions and all.

vidit
  • 6,293
  • 3
  • 32
  • 50
0

I understand you need a solution for firefox, but I have the below working version for Chrome. You can refer this link for a firefox solution: How to start Selenium RemoteWebDriver or WebDriver without clearing cookies or cache?

For Chrome (config): You have to set the path to user-dir which will save all the login info after you login for the first time. The next time you login again, login info from the user-dir will be taken.

System.setProperty("webdriver.chrome.driver", "res/chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("user-data-dir=D:/temp/");
capabilities.setCapability("chrome.binary","res/chromedriver.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY,options);
WebDriver driver = new ChromeDriver(capabilities);

Login for the first time:

driver.get("https://gmail.com");
//Your login script typing username password, check 'keep me signed in' and so on

Close the driver (do NOT quit):

driver.close(); 

Re-initialize the driver and navigate to the site. You should not be asked for username and password again:

driver = new ChromeDriver(capabilities);
driver.get("http://gmail.com");

The above can be implemented for firefox using a firefox profile.

Community
  • 1
  • 1
LittlePanda
  • 2,496
  • 1
  • 21
  • 33