Question

I'm having trouble doing a very simple adding & getting cookie test in Protractor for Angularjs. This is the test block:

describe("Homepage", function () {
    var ptor;

    beforeEach(function () {
        ptor = protractor.getInstance();
        browser.get('/');
        ptor.manage().addCookie("test", "testValue");
    });


    it('should have cookie with name test and value textValue', function () {
        ptor.manage().getCookie("test").then(function(data){
            expect(data.value).toBe("testValue");
        });

    });
});

This test fails and says data is null. If I print getCookies() it'll print all the cookies but the test cookie will not be in there. Would really appreciate some help on this! Thanks!

Was it helpful?

Solution 2

Answer to this question: https://github.com/angular/protractor/issues/341

Thanks to Julie for her help!!

OTHER TIPS

if you use angular $cookies in your actual code to read cookie value, using ngCookies module inside protoractor spec code might be easier. The following spec code works for me.

describe('angularjs test', function() {

  it('should do something with cookie', function() {
    var mock_code = function () {
      angular.module('httpBackendMock', ['ngMockE2E','ngCookies'])
      .run(function ($httpBackend, $cookies) {
        $cookies.foo = 'bar';
      });
    };
    browser.addMockModule('httpBackendMock', mock_code);
    browser.get('/');

    // test code

  });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top