I have a test case in which the user shuts down the browser and re-opens it, to test if some login cookies are loaded correctly.
browser.get("domain1.com")
cookies_domain1 = browser.get_cookies()
browser.get("domain2.com")
cookies_domain2 = browser.get_cookies()
//close browser
//re-open browser
browser.get("domain1.com")
for cookie in cookies_domain1:
driver.add_cookie(cookie)
browser.get("domain2.com")
for cookie in cookies_domain2:
driver.add_cookie(cookie)
But this doesn't look good. I need the cookies loaded before opening the page. Selenium seems to allow only adding the cookies from a page to that page only!
Another way i've tried to do this was to save the browser.profile.path
directory, back it up, and on re-connect, pass it on a FirefoxProfile
, which gets passed to a webdriver.Firefox(FirefoxProfile(path_to_directory_backup))
. Unfortunately, this doesn't seem to save the cookies.