Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Clear cookies before every test begins #195

Closed
esprehn opened this issue Dec 15, 2010 · 10 comments
Closed

Clear cookies before every test begins #195

esprehn opened this issue Dec 15, 2010 · 10 comments

Comments

@esprehn
Copy link
Contributor

esprehn commented Dec 15, 2010

before each it() (and associated beforeEach etc.) we should clear the cookies. We cannot clear the cookies on every navigateTo() otherwise you couldn't navigateTo() inside a test to check if there's persistent state that works in your app.

@IgorMinar
Copy link
Contributor

this behavior, while correct, should be documented so that it's not a surprise to users.

@dbrunner
Copy link

Is there any way to clear the cookies manually? As far as I can tell, cookies are not cleared, making it difficult to test sessions.

@esprehn
Copy link
Contributor Author

esprehn commented Jan 27, 2012

Something like this should work: http://pastie.org/3261820

You might have better luck requesting a URL from the server in beforeEach() that responds with cookie headers. That's also better since HttpOnly cookies can never be reset from JS, and your session cookies should really be HttpOnly for security reasons.

ex.

beforeEach(function() {
  browser().navigateTo('/newsession');
});

Where that page responds with a blank document but with Set-Cookie headers that cause your session cookies to expire (or just send new ones).

@dbrunner
Copy link

Elliott, thank you very much for this insightful advice! We will take the
approach you recommend.

Regards,

David

On Fri, Jan 27, 2012 at 12:03 AM, Elliott Sprehn <
reply@reply.github.com

wrote:

Something like this should work: http://pastie.org/3261820

You might have better luck requesting a URL from the server in
beforeEach() that responds with cookie headers. That's also better since
HttpOnly cookies can never be reset from JS, and your session cookies
should really be HttpOnly for security reasons.

ex.

beforeEach(function() {
browser().navigateTo('/newsession');
});

Where that page responds with a blank document but with Set-Cookie headers
that cause your session cookies to expire (or just send new ones).


Reply to this email directly or view it on GitHub:
#195 (comment)

@vojtajina
Copy link
Contributor

In http://pastie.org/3261820

instead of this:

var injector = $window.angular.injector(['ng']);

you should do:

var injector = $window.angular.element($window.document.body).inheritedData('$injector');

It's bit weird, I know :-D You don't want to create new injector, instead you want to get hold of current injector, which is assigned to jq data ('$injector'), so you need to wrap the element by jq from within the iframe ($document is iframe's document, but wrapped by jq in the main frame).

@dbrunner
Copy link

Thank you very much for your advice and clarifications. This is very
interesting. I can understand the need for these gymnastics given that I'm
trying to do something I shouldn't (actually, I will use the navigateTo
approach you suggested), but are there ever good reasons for needing to do
this? If so, it seems like a cleaner approach might be desirable!

Regards,

David

On Fri, Jan 27, 2012 at 2:26 PM, Vojta Jina <
reply@reply.github.com

wrote:

In http://pastie.org/3261820

instead of this:

var injector = $window.angular.injector(['ng']);

you should do:

var injector =
$window.angular.element($window.document.body).inheritedData('$injector');

It's bit weird, I know :-D You don't want to create new injector, instead
you want to get hold of current injector, which is assigned to jq data
('$injector'), so you need to wrap the element by jq from within the iframe
($document is iframe's document, but wrapped by jq in the main frame).


Reply to this email directly or view it on GitHub:
#195 (comment)

@vojtajina
Copy link
Contributor

You need gymnastic, because you are actually getting into a running app in the iframe :-D

We should provide some helpers (dsl) for getting hold of some basic stuff like $injector, I think that's a valid requirement.

@dbrunner
Copy link

Cool... Makes sense to me!

On Jan 27, 2012, at 5:48 PM, Vojta Jinareply@reply.github.com wrote:

You need gymnastic, because you are actually getting into a running app in the iframe :-D

We should provide some helpers (dsl) for getting hold of some basic stuff like $injector, I think that's a valid requirement.


Reply to this email directly or view it on GitHub:
#195 (comment)

@juniorconte
Copy link

Thanks guys =D

@IgorMinar
Copy link
Contributor

too old. likely resolved or we don't care any more. closing. please reopen if you still care.

we are migrating to use Protractor which gives you full control over the browser so flushing cookies is much easier.

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

5 participants