Here's how to solve this problem. James Islett hinted at a solution when he mentioned the session identifier above. jscn showed how to set up a session, but he did not mention the importance of the session key for the solution, nor did he discuss how to associate the session state with the Selenium browser object.
First, you need to understand that when creating a session key / value pair (e.g. 'uid' = 1), Django middleware will create a session / data / expiration record in your selection backend (database, file, and etc.). The response object will then send that session key to the cookie back to the client browser. When the browser sends a subsequent request, it will send back a cookie containing this key, which is then used by the middleware to search for user session elements.
Thus, a solution is required 1.) find a way to obtain the session key that is generated when the session item is created, and then; 2.) find a way to pass this key to the cookie via the Selenium Firefox web browser. Here is the code that does this:
selenium_test.py: ----------------- from django.conf import settings from django.test import LiveServerTestCase from selenium import webdriver from django.test.client import Client import pdb def create_session_store(): """ Creates a session storage object. """ from django.utils.importlib import import_module engine = import_module(settings.SESSION_ENGINE)
Ralph source share