+ Start a Discussion
Sourav HalderSourav Halder 

SFDC asking for 2 step verification for each Selenium Run

Currently I am working on some Automation testing on Salesforce using Selenium webdriver.Salesforce system asks for a two step verification code(mobile/email OTP) apart from the usual credentials.Now, once you verify the user with the OTP, the application supposedly saves it in the cookies. So, from next instances only user id-pwd combination is sufficient to logon.

So, for that I have created a custom profile in firefox and tried to launch it through my code.But each time I am running it, a new temp profile is getting created where the cookie details are not saved already.

This is the snippet of the code:
            ProfilesIni allProfiles = new ProfilesIni();
            FirefoxProfile profile = allProfiles.getProfile("SFDC");
            WebDriver driver = new FirefoxDriver(profile);
When I am trying to log in manually this(2 step verification) is not happening.The automated execution was working properly before 27th Jan.
Can you please help?
Tammer SalemTammer Salem
You will need to get Selenium to retrieve the cookies and save them.
Set<Cookie> allCookies = driver.manage().getCookies();
I would recommend persisting these to a file - then retrieving them again
so the logic would be:
  1. open your cookie file
  2. If you find it - add it to your driver (driver.manage().addCookie(cookie);)
  3. If you don't find it - then get it from the driver and save it to the cookie file
There is a good article on this here: http://www.guru99.com/handling-cookies-selenium-webdriver.html