How Can I Sync The Html/session Used Between Django's 'client' And Selenium's Webdriver
Solution 1:
I've not tried doing exactly what you are trying to do but I've done something similar. What you need to do is set a cookie like this on your Selenium instance after you've logged into your Django site with your Client instance:
driver.add_cookie({'name': 'sessionid', 'value': session_key})
The name should be equal to your SESSION_COOKIE_NAME setting on the Django site (sessionid is the default). You need to figure out the value of session_key.
You can obtain it from a Client instance like this:
session_key = client.cookies["sessionid"].value
Note that Selenium won't be able to set the cookie for some browsers if SESSION_COOKIE_SECURE is True. You should have this setting be True for your production server but if you want your Selenium tests to set your session cookie, then you have to make it False for testing.
Once your Selenium instance has the cookie, it will look to Django as if you had logged into it with Selenium. As I said, I do something similar in my test suites. (I use something else than Client but the principle is the same.)
Post a Comment for "How Can I Sync The Html/session Used Between Django's 'client' And Selenium's Webdriver"