Attempting to create a cookie in a protractor testing scenario. Using Protractor 3.3.0, Angular 1.5.x, and Node.js 6.9.1
Here is the specified test:
(function() {
'use strict';
describe('Dummytest', function() {
beforeEach(function() {
browser.get('./');
});
it('should set a cookie', function() {
browser.manage().addCookie("test", "fail_cookie", '/', 'localhost');
});
});
})();
An error message is generated as follows:
browser.get
wasn't used prior to successful cookie read/write operations.(function() { 'use strict'; describe('Dummytest', function() { it('should set a cookie', function() { browser.manage().addCookie("test", "fail_cookie", '/', '127.0.0.1'); browser.manage().getCookie('test').then(function(cookie) { console.log('cookie test', cookie); browser.get('./'); browser.manage().getCookie('test').then(function(cookie) { console.log('cookie test 2', cookie); }); }); }); }); })();
The output generated displayed below:
browser.get('./')
. How can I establish a cookie for that domain without triggering the initial error?Further Update:
Discovered a related query (Setting cookies before browser.get) suggesting to initiate with
browser.driver.get
first, followed by setting the cookie. However, utilizing this method led to the sameUnableToSetCookieError
. Seek alternative resolutions.Additional Notes:
In addition to the issues mentioned above, locating documentation pertaining to the
addCookie
function and its parameters has proven challenging. Especially since the latest release of Protractor (as of 2016-01-31) requires an object rather than a list of parameters. Fortunately, found the essential information and included a reference link here: https://github.com/SeleniumHQ/selenium/blob/022644c47c643ce6fe797...Final Edit:
Making progress! Setting the domain to
.localhost
(with the dot at the start) appears to have resolved the issue. Further investigations underway with findings to follow. Appreciate insights on why the dot holds significance and why that specific domain address works effectively :)