boopathi boopathi - 3 months ago 51
Java Question

As a Automation(Selenium) tester , How to test "REMEMBER ME"(functionality) checkbox in Login Form

i am new to new selenium webdriver. i have one doubt, kindly give me a suggesstion. As a Automation(Selenium) tester , How to test "REMEMBER ME" checkbox in Login Form. Give me any sample code/script to test.

This is the scenario: (1).Enter the user name , password and click on the Remember me Checkbox.(2). Click on Login button. (3). After successfull login, close the browser without logout the account.(4). And if i open the URL, it needs to go to the home page with user already signed in. (5). Need to test whether this scenario is working or not

Answer

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.

Comments