gsklee / ngStorage

localStorage and sessionStorage done right for AngularJS.
MIT License
2.33k stars 461 forks source link

Protractor & ngStorage not working together as expected #226

Open cayleyh opened 8 years ago

cayleyh commented 8 years ago

When writing an e2e test in Protractor of behaviour that uses ngStorage, there are problems when the test refreshes the page and expects to see updated behaviour based on items persisted to localStorage.

Simple theoretical example is:

it('remains closed once dismissed', function() {
    browser.get('/');
    expect( element(by.css('.dismisable-element')).isDisplayed() ).toBe(true);

    element(by.css('.dismisable-element')).click();
    expect( element(by.css('.page-callout')).isDisplayed() ).toBe(false);

    browser.refresh();
    // FAILS
    expect( element(by.css('.dismisable-element')).isDisplayed() ).toBe(false);
});

Inserting a browser.sleep(125) before the browser.refresh() call will cause the test to pass every time. However, according to the protractor docs, this type of thing should not be necessary (http://www.protractortest.org/#/api?view=Protractor.prototype.waitForAngular).

Appears that localStorage is not being updated correctly both by the $timeout wait that protractor is supposed to do, and by the onbeforeunload handler.

There is a related discussion on stackoverflow here: https://stackoverflow.com/questions/28108148/protractor-testing-with-ngstorage/38083164#38083164

egilkh commented 8 years ago

As we debounce changes by 100ms this is probably the most likely reason. beforeunload should take care of that but if the event is not fast enough or browser to strong it's deaded.

I will need to think about this and check it. Thanks for the report. Hopefully we'll find a solution.

zcsongor commented 8 years ago

+1

aBnormaLz commented 8 years ago

+1

cayleyh commented 8 years ago

@egilkh even a method to force sync + some note in the docs on the debounce interval would be helpful here. I've also encountered issues related to this doing things like deleting a token from localStorage then reloading the entire page.

azachar commented 8 years ago

+1

elishaterada commented 7 years ago

+1, we are basically switching back to native local storage method because of this

azachar commented 7 years ago

How about to use $interval instead $timeout? Would it help?