So I am logging in to a site using splinter then I am grabbing the cookies after I am logged in and then saving it as a pickled object for later use.
def save_cookie(username, password):
browser = Browser()
browser.visit("https://somesite.com")
browser.fill('username', username)
browser.fill('password', password)
login_button = browser.find_by_xpath('the_login_button_x_path')
login_button.click()
# make a file and save the pickled object.
file_Name = "the_cookie"
fileObject = open(file_Name,'wb')
pickle.dump(browser.cookies.all(verbose=True) ,fileObject)
fileObject.close()
# so file is saved.
# I take screen shot so that I know that the user is logged in.
browser.driver.save_screenshot('screenshot.png')
So I want to be able to save that cookie data so that I can use it again later in another instance of splinter Browser() . this would allow me to login once instead of logging in every time I wanted to test a page that requires a logged in state.
def visit_site_as_logged_in_user():
browser = Browser()
#open the previously pickled cookies object and load it
the_previously_saved_cookies = pickle.load( open( "the_cookie", "rb"))
#set the cookies on this new browser instance
browser.cookies.add(the_previously_saved_cookies)
#visit the site
browser.visit("https://somesite.com")
# I take screen shot so that I know that the user is logged in.
browser.driver.save_screenshot('screenshot.png')
So I expect for the user to visit the site and be in a logged in state since I am taking the exact same cookies from the first instance and applying it to a new instance. I am probably misunderstanding how splinter handles cookies though. The documentaion is not very descriptive . http://splinter.readthedocs.org/en/latest/cookies.html
When I look at the screen shot the user is just visiting the site and is not in a logged in state.