Test "Remember me" a.k.a. SSO (Single Sign On) by being able to close the web browser, and re-start the browser with the same profile.

2,000 views
Skip to first unread message

Automated Test Spider

unread,
May 13, 2011, 6:04:59 PM5/13/11
to Selenium Users
I use the Selenium RC python client 2.0b3 with the selenium server
2.0b3. I am testing a typical log in page, that has typical "Remember
me" functionality. The web application will try to set a persistent
cookie, that has a Max-Age of 4 weeks (set in seconds). If the cookie
is set, then when the user opens the browser, navigates to the web
application, the cookie is sent, and the user is automatically logged
in.
(Typical login/remember me/persistent cookie web application behavior)

A test case for Remember me, would have the test case steps:
1) Open the browser
2) Navigate to the web application
3) Click login
4) Enter your login name and password, then click submit
5) Now that you are logged in, quit the browser application so that
all browser windows are closed
6) Start the browser
7) Navigate to the web application
Expected Results: You are automatically logged in

In Selenium, the typical situation is to initialize a new profile copy
into a temporary directory, either using a built-in template, or one
provided by the user. For most tests, this is very wise. However, for
some test cases, I think there is the desire to be able to close the
browser, then start the browser, using the actual same profile (not a
new copy from the template) as before.

I have read the documentation, blogs on the internet, and this group
fairly carefully.
I have seen people write their Selenium RC client code in a way so it
continues to use the same session, in order to avoid the time cost of
initializing a new copy of the profile template, but the browser is
never closed.

I have also seen workarounds where you write code to capture the
cookie through either 'get_cookie' or 'get_cookie_by_name', then after
closing and restarting the browser, you pull a fast-one by using
'create_cookie' to write the cookie out again....but here is where
that will get you into trouble....

On the web application, I mentioned the cookie was using the Max-Age
attribute. As it turns out, Internet Explorer (up to and including
IE8, not sure about IE9) does not support the cookie Max-Age
attribute. You must use the expires cookie attribute. While IE
ignores the Max-Age attribute, causing the cookie not to persist, it
does appear to honor the cookie for the session. :(

What this means is, if you do the, "I'll save the cookie, and set it
myself, after I restart the browser" hack, on Internet Explorer, you
will have a test case that appears to pass, when in fact, a proper
automated simulation of the test case, should fail, just like it would
if you did it manually.

I have attempted to work around Selenium profile initialization. As
far as I can tell, there is no RC programmatic way to reuse the same
initialized profile. Once you do a close(), on your last browser
window, shutting down the browser application, you don't really have
much choice, but to do stop(), then start(), which will initialize a
new copy of the profile template, thereby losing any cookies that were
set. If I'm wrong about there not being a RC programmatic way, please
let me know. However, I am not interested in any wrapper hacks which
involve copying the initialized profile on the file system, and
restarting the selenium server with --firefoxProfileTemplate.

I have also attempted to thwart profile initialization by using the
*custom browser type, along with specifying the path to firefox or ie.
I configure the default firefox profile with all the appropriate prefs
(I know my way around prefs.js, and I know what prefs are set in the
embedded selenium firefox profile), and configure the proxy settings
in firefox. Many selenium commands, like "waitForPageToLoad" respond
with:
Exception: Permission denied for <http://mydomain.com> to get property
Window.document
Perhaps there is an additional firefox configuration that I have
missed that would allow me to circumvent this permission check. If
someone could shed light how to do that, please let me know.

Is there a way to automate the test case above, in Selenium RC, which
would properly simulate manual user behavior, such that, if the
browser failed to persist the cookie (as it would in the case of IE),
the test case would fail?

thank you,
Automated Test Spider

Automated Test

unread,
May 17, 2011, 12:02:50 PM5/17/11
to Selenium Users
Still hoping to get a response on this. Even if it is merely someone familiar enough with Selenium capabilities to confirm that, reusing a profile (session) after closing the browser is unsupported. Or perhaps some instructions on how to use Firefox and IE via *custom, that will get around the permission issues.

Luke Inman-Semerau

unread,
May 17, 2011, 12:33:05 PM5/17/11
to seleniu...@googlegroups.com
I don't normally use python bindings for my test... but I use them to poke around / play with the UI.

Can you re-use the profile for the next instantiated Firefox?

Here's what I tried, but not sure if the cookies persisted from the last session:

import shutils
from selenium import webdriver as wd

ff1 = wd.Firefox()  // or use your profile that you had pre-baked
// do stuff with ff1, like login
ff1.quit()
shutils.rmtree(ff1.firefox_profile.profile_dir + '/extensions/fxdr...@googlecode.com')
ff2 = wd.Firefox(ff1.firefox_profile)
// hopefully still logged in?

Can you let me know if that works?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Automated Test

unread,
Jun 29, 2011, 2:22:43 PM6/29/11
to seleniu...@googlegroups.com
Hey Luke, sorry it took me a while to get back to you on this. In my original post, I was using Selenium RC python client 2.0b3 with the selenium server 2.0b3, using the Selenium driver, not WebDriver.  As far as I can tell, being able to shut down the browser, and start it up again, using the same profile, can't be done with the Selenium driver. I am testing on Windows, with both Firefox and IE.

Based on your suggestion, I dived into WebDriver, with the 2.0rc3. When I implemented the scenario in WebDriver it _APPEARED_ to work.

I was able to create some tests with cookies, where the cookies had different attributes; expires, Max-Age, expires and Max-Age. Ran tests with FF and IE using WebDriver. I was able to start a session, quit the browser, and start the browser again using the same session, and verify that the cookie did indeed get saved. (Except in the case of IE, where IE does not support the Max-Age attribute, and thus does not save the cookie. As expected.)

I got this message when doing quit(), and when trying to do your suggested deletion of the extensions section.
[Error 32] The process cannot access the file because it is being used by another process: 'c:\\docume~1\\spider\\locals~1\\temp\\tmpxsp5az\\Cache\\_CACHE_001_'

In webdriver.py there is the quit method, which will attempt to clean up the old profile. shutil.rmtree(self.profile.path)
Firefox must still have a hold on something in the profile path, and rmtree fails, giving the windows error 32, ERROR_SHARING_VIOLATION.

It is because of this error, that the FF profile does not get cleaned up. If I add a, time.sleep(5), in front of the, shutil.rmtree(self.profile.path), it gives FF enough time to exit, and you don't get the error. Unfortunately, this allows the entire profile path to be deleted, and thus isn't there when doing, wd.Firefox(ff1.firefox_profile). :(

The only reason is appeared to work in FF, was due to a bug in quit(), where it tries to clean up the profiles dir, before the FF process has released them. When that bug is fixed, the profiles dir gets deleted. Reported issue: http://code.google.com/p/selenium/issues/detail?id=1938

Adding a time.sleep(1) in front of the shutil.rmtree(self.profile.path) in webdriver.py:WebDriver.quit() fixed the error 32 issue for me. Then I made another change to quit(), where I added a delete_profile_path parameter, defaulted to True.  This allows me to call quit() within my test case, specifying to not delete the profile path. quit(delete_profile_path=False). Then, similar to your suggestion, I initialize a new webdriver browser session, using the profile from the previous session. I use the same webdriver instance name, that gets used in setUp, and tearDown, so that when quit() gets called in tearDown, the profile path gets cleaned up at the end of the test! :)

I have some an auxiliary question. What was the purpose of trying to delete the /extensions/fxdr...@googlecode.com?
shutils.rmtree(ff1.firefox_profile.profile_dir + '/extensions/fxdr...@googlecode.com')


thank you,
Automated Test Spider

Luke Inman-Semerau

unread,
Jun 29, 2011, 2:54:43 PM6/29/11
to seleniu...@googlegroups.com
Trying to remember... i think i was doing that because when starting up a new instance of firefox and providing a profile, it tries to write to that directory (without checking for the existence of it or something like that) which cause some io error that this was trying to get around.

Automated Test

unread,
Jun 29, 2011, 3:12:49 PM6/29/11
to seleniu...@googlegroups.com
Thanks man. I didn't have that issue when I left it out, on my platform (WinXP, Python 2.6, Selenium 2.0rc3). Wanted to make sure, just in case I was missing out on a useful workaround. :) Thanks again. :)

Luke Inman-Semerau

unread,
Jun 29, 2011, 4:04:25 PM6/29/11
to seleniu...@googlegroups.com
Glad I could help... I was either running on Ubuntu or Mac when I wrote this... usually only on windows to debug why my tests script aren't working on IE :)
Reply all
Reply to author
Forward
0 new messages