Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

session cookie lost when click made to a link that opens a window with window.open() #1486

Open
lukeis opened this issue Mar 2, 2016 · 41 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 1486

What steps will reproduce the problem?
1. Using InternetExplorerDriver log into any app securized by session cookies
2. Click on any link that calls a javascript function that opens a new window using
window.close()
3.

What is the expected output? What do you see instead?
The content of the window without requiring authentication. Instead I got the login
page in the new window

What version of the product are you using? On what operating system?
I'm using windows vista and IExplorer 7

Please provide any additional information below.

Reported by jcroig on 2011-03-30 18:43:16

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I've attached a simple test case containing two .html files and a WebDriver test case
(in C#, but you should be able to translate the test code into any language you choose).
When I run this test in my environment, the test succeeds, and the popup window receives
the session cookie, as verified by the background of the popup window being the appropriate
color. Does this test succeed or fail in your environment? Is this test case representative
of what is happening in your application, even at an overly simplified level? Does
the problem only reproduce using IE7, or does it reproduce on other versions of the
browser?

Reported by james.h.evans.jr on 2011-03-31 14:03:14

  • Status changed: NeedsClarification

- _Attachment: [SessionCookieTest.zip](https://storage.googleapis.com/google-code-attachments/selenium/issue-1486/comment-1/SessionCookieTest.zip)_

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am experiencing the same problem with pop-ups and losing cookies. This happens both
with IE and FireFox drivers (running on Windows).

I have found that if the window.open is the very last statement in the test, everything
works fine, but as soon as it's following by another webdriver/selenium command, the
cookies are lost.

Below is a Java example allowing me to reproduce the issue. It uses the HTML files
in James' test case.

So far I have been using Selenium 2.0b2, I will give b3 a go now.

public class CookieTest {
    @Test
    public void testCookieLost() {
        driver.get("http://localhost/sessioncookie.html");
        driver.findElement(By.id("openwindowbutton")).click();
        //sleep(2000);
        driver.switchTo().window("cookiedestwindow");
    }
}

Reported by jopdeklein@me.com on 2011-04-22 09:55:01

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Selenium 2.0b3 doesn't seem to fix the issue, unfortunately.

Reported by jopdeklein@me.com on 2011-04-22 11:39:53

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Forgive my confusion, I'm misunderstanding your comment. "window.open" doesn't appear
anywhere in your test code. Running your test code in the current IE driver appears
to work for me, in that I have the appropriate cookie both in the original window,
and the window opened via JavaScript on the page. Perhaps more context is required.

Reported by james.h.evans.jr on 2011-04-22 12:42:35

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@James, thanks for your reply. 
I used the HTML files you uploaded, so the window.open functionality is implemented
on click of #openwindowbutton in sessioncookie.html, like in your example.

It seems you are not experiencing the issue that the topic starter and I encounter,
thanks for testing.

Since I am experiencing issues with the session cookies getting lost, opening the new
window logs me out - therefore the rest of the test case is not relevant for my scenario
since it never loads sessioncookiedest.html. 

I will set up a separate test case without the authentication mechanism to see whether
this is related to session cookies specifically or cookies in general.

Reported by jopdeklein@me.com on 2011-04-22 13:14:30

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@James, the problem also occurs with 'regular' cookies - When I run your test case it
loses the cookie when the window is opened through Selenium 2.0.

When I run the scenario manually it works as expected. Additionally I've written a
similar test case in Watij which runs fine as well.

This seems to be a bug in the InternetExplorer driver as it works fine in Firefox on
my machine. Again it seems subsequent operations after the window.open trigger this
behavior.

Reported by jopdeklein@me.com on 2011-04-22 14:26:46

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Can you please make sure that IE is configured properly for using the IE driver. I've
just updated the IE driver wiki page[1] to include the correct configuration information
for the current incarnation (post 2.0b1) of the IE driver.

[1] http://code.google.com/p/selenium/wiki/InternetExplorerDriver

Reported by james.h.evans.jr on 2011-04-22 15:32:01

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am using IE6 on Windows XP here as a client still needs to support it, so the mentioned
Protected Mode settings don't apply in my case. I did verify all cookies are being
accepted.

Some background information; the reason it 'works' when no subsequent actions are called
is because the driver is destroyed (the unit test exists) and the apparent offending
code that causes the cookies to be lost won't be executed. If I manually destroy the
driver after clicking the link that opens the window, the cookies are still intact.
Obviously this isn't really a solution since I can't interact with the popup any further
afterwards :)

The thing that puzzles me is the timing; the window opens fine, and before the request
is made something happens that removes the cookies, but only if the driver is still
alive.

Any ideas? Thanks for your help.

Reported by jopdeklein@me.com on 2011-04-22 15:51:57

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Knowing that IE6 is a requirement for this application, it would still be an extremely
useful data point to know if the same behaviour appears under a more recent version
of IE, say, IE8.

The reason I ask is that in my test code, I'm performing several actions in both windows
via the WebDriver API after the window opens, and still able to interrogate the cookies.

Also, I understood you to say that using the test pages in the attachment above, you
are able to reproduce the problem, correct? In what versions of IE?

Reported by james.h.evans.jr on 2011-04-22 16:18:44

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am currently using IE 6.0.2900.5512 with XP SP3. Assuming the topic starter and I
are talking about the same issue, it apparently also occurs on IE7. 

I'll run the test case on a machine with XP and IE8 next week and will let you know
what happens.

I can indeed reproduce the problem with your attached test case. I did convert it to
Java and am running it from RAD.

Reported by jopdeklein@me.com on 2011-04-22 16:30:39

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Sorry to be pedantic, but when you say you can reproduce the problem using the attached
test case, how does the behaviour manifest itself? Is the popup document background
not set to the expected color? Are you doing other things after the code there, and
investigating the document cookie at that point? I'm trying to make sure I can reproduce
the failure in my environment, and I want to be sure that the attached test case adequately
describes the failing scenario, and that I'm looking at the correct symptoms to observe
that the test has, in fact, failed.

Reported by james.h.evans.jr on 2011-04-22 16:43:36

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

No worries. 

If i run the test case standalone, the background of the popup remains white, fiddler
shows no cookies being sent.

When i run the test case from within the authentication framework, it redirects the
popup to the login screen as the authentication cookies are missing.

Reported by jopdeklein@me.com on 2011-04-22 16:53:12

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

For the record, I just ran the attached test case on XP/IE6, and it passed for me. 

As an aside, I noticed in your comment earlier, you commented out the sleep() call.
Because the click() method opening the popup window is asynchronous, you need some
synchronization mechanism to wait for the popup window to appear and initialize. For
expediency in the example, I used a sleep() call in my test case; in practice, I'd
probably use a wait loop with a timeout to wait for the number of window handles returned
by getWindowHandles() to be 1 greater than the number I started with.

Reported by james.h.evans.jr on 2011-04-22 17:53:37

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Does it help if I send you the Java test case to eliminate the possibility of it being
a Java binding specific issue? 

In normal scenarios I would indeed use a wait loop to wait for the window to be loaded
before attempting to interact with it. For the test case it didn't have any affect
on the symptoms, so I took it out for the sake of simplicity.

Reported by jopdeklein@me.com on 2011-04-26 08:23:54

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Unless your Java version is substantially different from the code snippet in comment
2, then no, I don't need a Java version. That said, I'll try the Ruby bindings first,
simply because it's easier for me to use my Ruby environment to run tests than my Java
environment.

Reported by james.h.evans.jr on 2011-04-26 11:00:37

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

The Java testcase does the same thing as your C# example, so you should be good to go.

I do have some new insights to report; The issue isn't always reproducible, sometimes
it works, other times it doesn't.

First thing in the morning everything worked fine on two different machines - at the
end of the day it stopped working (cookies getting lost) on machine #1 while it still
worked fine on machine #2. After closing all other processes on machine #1 it works
fine again.

The above scenario leads me to believe this perhaps has something to do with memory
management, either in the IE driver, webdriver, or the process running it from the
RAD instance.
I've tried isolating the issue to IE plugins or other processes running, as well as
trying to max out memory usage to replicate the issue, but no luck so far.

Do you have any clue what might be going on, or have any pointers I can investigate
further?

Reported by jopdeklein@me.com on 2011-04-27 16:14:41

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

James, we've found out the issue consistently occurs when there are (certain?) 'zombie'
IE processes running in the background prior to running tests. If we kill all IE processes
before running the tests everything works as expected.

This workaround will allow us to continue using Selenium 2 in our project, however
it would be nice if Selenium would provide a way to 'start clean' and kill all IE instances
before running the tests.

By the way, this issue also occurs in IE8.

Reported by jopdeklein@me.com on 2011-04-28 09:16:45

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Before I attempt to drive in a 6pp nail with a 10-pound sledgehammer (killing all IE
processes), I'd like to find out where the background IE processes are coming from.
Is it any IE process, or just certain ones? For IE6 and to a certain degree IE7, this
is easier to debug, since 1 iexplore.exe == 1 top-level window of IE. 

With IE8, however, the IE architecture changed radically from a process management
standpoint. It is perfectly normal behaviour for iexplore.exe processes to remain in
your task list even after you've properly shut the top-level window down. Additionally,
crash protection ("tab recovery") in IE8 and later can make closing down and restarting
IE a challenge. Use your favorite search engine to search for the term "loosely-coupled
IE" or "LCIE" for more information about those changes.

Blindly attempting to shut down every IE instance before running a test is frought
with peril, and I'd be loathe to do it from with the Selenium code base. If we can
narrow down what properties of the pre-existing IE processes are causing the issue,
it might be easier to target the processes causing the problem.

Reported by james.h.evans.jr on 2011-04-28 12:13:38

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am experiencing the same problem.

When I open brower using FF3.6 using firefox web driver, I lose all my cookies.seems
like they are deleted or wiped off? 

is there any workaround?this is totally killing me?

Reported by kavita.sharda on 2011-05-27 22:23:12

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I had similar problem with different IE versions. It is caused by some
lingering IE instance so I created a small script that kills all running IE
instances using taskkill.exe.
It might work for FF as well...

HTH

Reported by ferenc4021 on 2011-05-31 12:22:11

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

@James, I see this issue is still marked as NeedsClarification. I don't know if I can
provide more information as this seems to be an IE core issue (regarding the lingering
IE instances). In my experience my IE instances got stuck 'at random', but if I find
a pattern I will let you know. 

Are you in contact with Microsoft? Perhaps they can point you in a direction.

Reported by jop@validweb.nl on 2011-07-11 13:47:39

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have the same issue. You can find a test case here : https://gist.github.com/1125243

For me, it only happens on IE 7 with Windows Vista, not Windows XP.

Vista IE version: 7.0.6.18005
XP IE version:     7.0.5730.13

Reported by adrien@fotonauts.com on 2011-08-04 14:17:16

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by barancev on 2011-10-12 21:02:28

  • Labels added: Component-WebDriver, Browser-IE

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Had the same issue, using Selenium's WebDriver v2.11 and IE 7.
Was also due to lingering IE instances in the background. Works wonderful when I take
care to kill them before...
Thanks HTH!

Greg

Reported by greg.junkietech on 2011-12-06 11:04:38

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I met the same issue on Windows 7 64 bit with IE8, and IE9. When there is a IE instance
before. So after I close all the IE instance before running the webdriver automation
tests. It works.

Reported by binken.zou on 2012-05-03 04:38:05

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Hi,

i reproduced this problem at Win7+IE8 32bit (and at Win7 + IE9 32bit).

Reproducible test is attached. Code of test is based on code from Comment #25.
Main point is having IE opened before starting work.
Also ie driver logs are attached: when no IE and when IE is started before.

I suppose that newly opened IE window is started using new IE session so cookies are
so on are not available. But i can not understand why :( 

Simple workaround is forcibly close all iexplore.exe processes
but when grid is used it can't be done easily.

Reported by a.u.savchuk on 2012-08-29 16:26:35


- _Attachment: [test.py](https://storage.googleapis.com/google-code-attachments/selenium/issue-1486/comment-29/test.py)_ - _Attachment: [ie_no_ie.log](https://storage.googleapis.com/google-code-attachments/selenium/issue-1486/comment-29/ie_no_ie.log)_ - _Attachment: [ie_with_ie.log](https://storage.googleapis.com/google-code-attachments/selenium/issue-1486/comment-29/ie_with_ie.log)_

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am seeing this on Windows 32bit and IE9.

Problem happens on Selenium 2.21 (which did not have IEDriverServer) and Selenium 2.25
(with IEDriverServer).

Reported by codywmack on 2012-10-11 14:18:45

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Is this still an issue? More IE isolation was added in 2.26 by revision 259bbebd31a2.
Would anyone recheck in a newer selenium version?

Reported by barancev on 2013-01-22 20:04:24

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Retested with the scenario provided in comment 29 -- reproduced in selenium 2.30

Reported by barancev on 2013-02-23 11:52:10

  • Status changed: Accepted

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Hi, me and others internally had the same issue. We got to isolate the issue internally.

If no "vanilla" IE window is open. Calling window.open from the driver will open a
new window. The new window will have the same process id as the original driver window.
As IE driver has session, new window will have also session

If one or more "vanilla" IE window are open(no session data in them). Calling window.open
from the driver will open a new window. The new window will share the process id of
the open vanilla IE window. As vanilla has no session, new window wont have also. If
it had, it would share.

A old IE session not closed will work sameway a "vanilla" IE window open. If session
exists it will be shared.

Small sample in attachment.
Session.zip has a simple asp.net server that i use the store and test the session.
Program.cs has a test (dont forget to point url at server).

Celso




Reported by celsoricardocosta on 2013-04-22 14:27:25


- _Attachment: [Session.zip](https://storage.googleapis.com/google-code-attachments/selenium/issue-1486/comment-33/Session.zip)_ - _Attachment: [Program.cs](https://storage.googleapis.com/google-code-attachments/selenium/issue-1486/comment-33/Program.cs)_

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am also seeing this same issue in IEDriverServer.exe version 2.33.0.0 with my tests
when there are other IE10 windows lingering around, whereby the session cookies are
not sent with the GET request when the site under test opens up a new window using
javascript window.open(). As a result my site under test brings up the login page again.
Been debugging quite a bit and I think I have narrowed down the issue. Running and
verifying all my tests with this fix at the moment - will post the fix once I have
verified that there are no side effects to the fix.

Reported by arasheedu on 2013-06-06 21:31:21

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have to apologize - my fix did not quite work. Went with the work around of not having
any other IE sessions before launching tests.

Reported by arasheedu on 2013-07-02 21:16:59

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 5805 has been merged into this issue.

Reported by barancev on 2013-08-08 23:17:38

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Issue 5990 has been merged into this issue.

Reported by a.u.savchuk on 2013-08-12 21:04:15

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I am facing the same problem in Java. Can any please suggest solution.

Reported by rajsourabh.gourav on 2014-03-06 16:00:21

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Guys I found the solution  from Issue 5990  .
Just close all the web browsers.

Reported by rajsourabh.gourav on 2014-03-06 16:03:14

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Please explain what you are trying to do, use as much details as possible.

Reported by info@mypenni.com on 2014-07-15 13:28:51

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Was this problem already fixed somehow? I see similar behaviour in my tests. I have
a test where a new window is opened with JavaScript windows.open method. My application
requires BASIC authentication so the JSESSIONID is passed in a cookie. As written in
the posts above, it will work correctly only when no other Internet Explorer windows
are opened:

Scenario 1
1. Close all IE instances. 
2. Run test 
-> During test, windows.open creates a new window and JSESSIONID is passed in the request
in the new window 

Scenario 2
1. Open some IE window. (Does not even need to navigate anywhere, just a blank IE window)
2. Run test 
-> During test, windows.open creates a new window and no JSESSIONID is passed in the
request 
-> BASIC authentication popup appears in the new window

Seems that closing all other IE windows before running tests is a workaround. But it
is rather a brittle solution so I'd like to ask whether is there some better fix provided?

Reported by godoniuk on 2014-11-10 10:25:10

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I had the same issue. As a workaround killed all my running IE, but was still having
issue.

On further debugging, found that no *visible* IE was running but found one running
in Process tree, killed that, and it started to work again. 

Not sure if this is addressed in IEDriver.exe though.

Reported by rajatjindal83 on 2015-03-23 18:23:18

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Here is a scenario I am troubled with, I have a situation where the application generates
a PDF report on click of submit button. Before clicking on the submit button, we have
to enter the start and end date during which the report is to be generated. 

Once the submit button is clicked it open a new window for the report but here it does
not generate the report it keeps asking for start and end date. So I doubt that the
new session is not able to read the input given in the previous session.
Any inputs on this? It works fine with Chrome, it only opens the report in a new tab
there. I am using IE8 32 bit.

Reported by sachinanto on 2015-04-27 05:09:01

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 17:44:24

  • Labels added: Restrict-AddIssueComment-Commit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant