Get help with testing, discuss unit testing strategies etc.


Post by Kurt »

Hi there,

I am writing a new test for localStorage testing. To do so, I need to swipe the localstorage set it via Siesta and afterwards run the app.

I did not find another way than to use window.location.href and waitForPageLoad.
But after loading the page I need to reference everything via window (that goes for localStorage as well as for the App).

Is there a way around or did I miss something?

Best regards

Kurt

Post by mats »

The window object of the new page is available as the first param of your callback, see docs here: https://www.bryntum.com/docs/siesta/#!/a ... orPageLoad

Post by Kurt »

I know, that's what i am doing at the moment.
But after loading the new page i need to do all calls with window at the beginning.

E.g.
StartTest(function (t) {
	localStorage.clear();
	t.is(localStorage.length, 0, 'LocalStorage is cleared');

	t.diag("Load App");
	window.location.href = "index.html";
	t.waitForPageLoad(function (window) {
		appLoaded(t, window);
	});

	function appLoaded(t, window) {
		t.diag("localStorage length: " + window.localStorage.length);

		t.done();
	}
});
Inside appLoaded I access quite some window items.
As you can see I can access the localstorage at the beginning without the use of "window." , which I would prefer.

Is there a way to get to this?

Post by mats »

Just save a ref to it in the outer scope:
    StartTest(function (t) {
       localStorage.clear();
       var outerLocal = localStorage;

       t.is(localStorage.length, 0, 'LocalStorage is cleared');

       t.diag("Load App");
       window.location.href = "index.html";
       t.waitForPageLoad(function (window) {
          appLoaded(t, window);
       });

       function appLoaded(t, window) {
          t.diag("localStorage length: " + window.localStorage.length);

          t.done();
       }
    });

Post by nickolay »

I guess you can also do
var localStorage = window.localStorage
at any time.

Post Reply