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