angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

Never is created a cookie with browser.manage().addCookie() #4317

Closed djom202 closed 7 years ago

djom202 commented 7 years ago

Hi there!

I'm using cucumber with protractor and in my test I need to create a cookie to do not login and go to dashboard directly. I'm have been try to create a cookie with this command:

browser.manage().addCookie({"name": "foo", "value": "bar"});

The test ran without problems, all is successful but when I go to the browser never was created the cookie and I stay in the login page.

image

Also when I try to get the cookie with browser manager, I got null:

browser.manage().getCookie('foo').then(function(cookie) {
     console.log('cookie test', cookie);
});

My cucumber Feature:

Feature: This is a scenario to simulate a Cookie

  Scenario: The user has a session created
    Given that the user was logged in
    When the user open the url site
    Then the user is inside the dashboard

And my steps:

Given(/^that the user was logged in$/, function(cb) {
   browser.manage().addCookie({'name': 'foo', 'value': 'bar'});
   cb();
});

When(/^the user open the url site$/, function(cb) {
   browser.get(browser.baseUrl + '/dashboard');
});

Then(/^the user is inside the dashboard$/, function(cb) {
   browser.manage().getCookie('foo').then(function(cookie) {
      console.log('cookie test 2', cookie);
   }).then(cb);
});

Bug report

NickTomlin commented 7 years ago

My knowledge of cucumber is a little weak but from this it appears that you are adding a cookie before navigating to a page. There's been some chatter on the selenium project about this https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/1953 and the response there as far as I can see is a wont fix.

I do think this makes sense because there's no "domain" to set the cookie on before you've loaded your page. You can load another page on your domain first, set the cookie there, and then navigate to your dashboard page if you have to test this functionality.

I'm going to close this because it is a question of selenium behavior and not an issue with Protractor itself.