Actually, i am writing some test cases for one angular app but the first page is taking too much time too load and having a popup box for instruction. So i need to store some value in localStorage of browser for making that popup box invisible. So how can i run any javascript function before running any test case?
Asked
Active
Viewed 461 times
0
-
please don't suggest for beforeEach() function because i already tried that one but that's not working for me. – Shravan Jain Apr 07 '17 at 18:04
1 Answers
1
By default, protractor is syncing with angular, which makes it wait for $http or $timeout you can check if that's the case on this particular page with this: Canonical way to debug Protractor-to-Angular sync issues
or you can inject the behaviour with mocked module
protractor.config.js
onPrepare: function() {
var doTheFuncyStuff= function() {
angular
.module('doTheFuncyStuff', [])
.run([function(){
//do something here so the popup isn't displayed
window.localStorage.setItem('my-var', 'my-val');
}]);
};
browser.addMockModule('doTheFuncyStuff', doTheFuncyStuff);
}
-
Thanks for your quick reply buddy. Now i tried your provided solution but i need to use browser inside .run. So how can i use browser inside browser? – Shravan Jain Apr 07 '17 at 18:22
-
-
1You can run any code in the `run` block, whatever you put in executeScript you can do it there too – maurycy Apr 07 '17 at 18:27
-
but it is throwing the error when i am trying to access browser inside run `browser.executeScript("window.localStorage.setItem('my-var', 'my-val');");` – Shravan Jain Apr 07 '17 at 18:29
-
I've edited my answer, you just need to skip the `browser.executeScript` since the mocked module will run in browser, everything else runs in protractor instance – maurycy Apr 07 '17 at 18:40