How to start Selenium RemoteWebDriver or WebDriver without clearing cookies or cache? -
use case: login username, navigated 2nd factor authentication page 1 of number of things (i.e. answer knowledge based question), , navigated final page enter password. close browser , attempt login again username. time 2nd factor authentication page bypassed because app recognizes cookies , user prompted enter password directly.
problem: using selenium remotewebdriver run these tests on separate test machine , when close first browser , open new instance of remotewebdriver appears starts clearing cookies , cache , 2nd factor authentication page comes every time attempt login.
what need: figure out how create new instance of remotewebdriver without automatically clearing cookies or cache, 2nd factor authentication page bypassed. need ie, chrome, firefox , safari.
i don’t have code clears explicitly, don’t have attempts force not clear (if that’s in existence.) haven’t tried of else because have no idea try.
versions: selenium webdriver: 2.45.0.0, selenium grid: 2.45.0
thanks!
to preserve cookies on firefox; create custom profile (see here example) , use each time when starting new remotewebdriver instance. way firefox reuse same profile existing cookies across sessions. doesn't save cookies received during test itself. see alternative approach below solution.
a similar approach works chrome - link.
for internet explorer instead of custom profile, ensurecleansession capability needs set false prevent cleaning cookies on session start - link.
alternative solution: cookies can manipulated within test itself:
get cookies when test ends:
readonlycollection<cookie> cookies = driver.manage().cookies.allcookies;
store them somewhere. how depends on automation setup, simple serialization disk should work fine.
de-serialize cookies on test start , add them through webdriver:
foreach (var cookie in cookies) driver.manage().cookies.addcookie(cookie);
Comments
Post a Comment