ngStorage icon indicating copy to clipboard operation
ngStorage copied to clipboard

Protractor & ngStorage not working together as expected

Open cayleyh opened this issue 9 years ago • 7 comments

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

cayleyh avatar Jun 28 '16 18:06 cayleyh

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.

egilkh avatar Jul 01 '16 13:07 egilkh

+1

zcsongor avatar Sep 13 '16 10:09 zcsongor

+1

aBnormaLz avatar Sep 13 '16 11:09 aBnormaLz

@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.

cayleyh avatar Sep 13 '16 15:09 cayleyh

+1

azachar avatar Oct 02 '16 22:10 azachar

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

elishaterada avatar Nov 08 '16 00:11 elishaterada

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

azachar avatar Nov 25 '16 07:11 azachar