Waiting for Ionic Loading dialogs with Protractor -
there similar questions (linked below) none solves problem. i'm writing protractor tests ionic project. need execute tests @ times when ionic loading dialog appears , disappears.
i've created repo bare bones of app , tests need made. solve , solve problem (i describe problem below): https://github.com/tmantman/stackoverflowq. adapt path chrome system in conf.js.
to simulate asynchronous ionic loading dialog add controller in blank ionic project:
$interval( function() { $ionicloading.show({ template: 'async ionicloading', duration: 5000 }); }, 5000 , 1); })
i need protractor wait dialog appear, tests, wait dialog disappear, , more tests. latest attempt in test file is:
it('should test when ionicloading appears', function() { browser.wait(function(){ return element(by.css('.loading-container.visible.active')).ispresent(); }, 10000); var ionicloadingtext = element(by.css('.loading-container.visible.active')).gettext(); expect(ionicloadingtext).toequal('async ionicloading'); }) it('should test once ionicloading disappears', function() { browser.wait(function() { var deferred = protractor.promise.defer(); var q = element(by.css('.loading-container.visible.active')).ispresent() q.then( function (ispresent) { deferred.fulfill(!ispresent); }); return deferred.promise; }); expect(1).toequal(1); })
i'm trying avoid using synchronous sleep function, code highly asynchronous. i've tried countless variations can't work. links i've used info includes:
the problem two-fold:
1) can deduce, duration property of $ionicloading method implemented timeout function. protractor not work $timeout. instead of using duration property, $ionicloading dialog can hidden $interval call (adapting code question):
$interval( function() { $ionicloading.show({ template: 'async ionicloading' }); $interval( function() { $ionicloading.hide(); }, 5000, 1) }, 5000 , 1);
2) code detect asynchronous change following:
it('should test when ionicloading appears', function() { browser.wait(function() { var deferred = protractor.promise.defer(); var q = element(by.css('.loading-container.visible.active')).ispresent() q.then( function (ispresent) { deferred.fulfill(ispresent); }); return deferred.promise; }, 10000); var ionicloadingtext = element(by.css('.loading-container.visible.active')).gettext(); expect(ionicloadingtext).toequal('async ionicloading'); }) it('should test once ionicloading disappears', function() { browser.wait(function() { var deferred = protractor.promise.defer(); var q = element(by.css('.loading-container.visible.active')).ispresent() q.then( function (ispresent) { deferred.fulfill(!ispresent); }); return deferred.promise; }, 10000); expect(1).toequal(1); })
then both tests pass.
Comments
Post a Comment