Clear cookies before every test begins
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.
this behavior, while correct, should be documented so that it's not a surprise to users.
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.
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).
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 < [email protected]
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: https://github.com/angular/angular.js/issues/195#issuecomment-3683321
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).
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 < [email protected]
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: https://github.com/angular/angular.js/issues/195#issuecomment-3695318
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.
Cool... Makes sense to me!
On Jan 27, 2012, at 5:48 PM, Vojta [email protected] 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: https://github.com/angular/angular.js/issues/195#issuecomment-3697392
Thanks guys =D
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.