Guaranteeing Unique Sessions with IE

I have one client who is using Django’s default session support which means they get cookied upon authentication. The vast majority of the coverage we’re getting with Se is going to be run in Linux/Firefox, but there are some IE specific components that we need to tackle as well.

Firefox starts with a completely separate process/profile so sharing the cookie across browsers doesn’t happen. But with IE things can get pretty annoying if there is an open IE window that is logged in as User A and a script says to open a window and login as User B. The problem is that the cookie is shared between the windows so the new browser starts with being logged in as User A.

This this happens at all I would consider a bug but a quick hack at the IE launcher to pass in the -noframemerging flag did not work so I attacked the problem with a sledgehammer.

Now the script will kill all running iexplore.exe processes before launching a new one. (Well, depending on a config parameter that is; but the default is to do it.)

if"Selenium", "browser") == "*iexplore" and"General", "clean_ie_sessions"):
    import win32_utilities

self.selenium = wrapper().connect("Selenium", "server_host"), \
                        "Selenium", "server_port"), \
                        "Selenium", "browser"), \
                        "Selenium", "base_url"))
import win32api, win32pdhutil, win32con

def nuke_all_ie():
        win32pdhutil.FindPerformanceAttributesByName("Process", "ID Process", "iexplore")

    pids = win32pdhutil.FindPerformanceAttributesByName("iexplore")

    if len(pids) > 0:
        for p in pids:
            handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, p)

In the credit-given-when-due department, I got the inspiration for this code from

Post a Comment

Your email is never published nor shared. Required fields are marked *