I am trying to write a simple e2e test for the authentication we use in our project. Authentication is based on the json web token, which is set to window.localStorage.satellizer_token.
To install it, I use the code below, but for what I see, it really does not set the actual localStorage property of the window object.
describe('login', function () { it('should set the satellizer token and be allowed to get panel', function () { browser.driver.get('http://example.com/'); browser.driver.executeScript(function () { return window.localStorage; }).then(function (localStorage) { expect(localStorage.satellizer_token).toBe(undefined); localStorage.satellizer_token = "eyJ0fdaccKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjE3MjUzIiwiaWF0IjoxNDM0Mzc1NjU3LCJleHAiOjE0NjU5Mjk2NTd9.VbhdWQ_gOb7X8pmOGLDjBKURxcaWQlIXQGvLRansQCphk"; expect(localStorage.satellizer_token).toBe("eyJ0fdaccKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjE3MjUzIiwiaWF0IjoxNDM0Mzc1NjU3LCJleHAiOjE0NjU5Mjk2NTd9.VbhdWQ_gOb7X8pmOGLDjBKURxcaWQlIXQGvLRansQCphk"); browser.driver.get('http://example.com/panel'); expect(browser.driver.getTitle()).toEqual('http://example.com/panel'); expect(browser.driver.getCurrentUrl()).toEqual('http://example.com/panel'); }); });
});
I know that there is already something similar here and, but all the examples that I can find relate to access-only, I also need to change the properties of the window.
What is the correct way to interact with a window object in protractor tests?
source share