javascript - How do I make Protractor wait for a triggered promise to resolve? -
so have site upon clicking button, sends off angular service, makes promise, resolves it, gets data, , displays info on page. want angular test finds button, clicks it, , verifies got info back. however, test finishes before button resolves. tried browser.sleep(), paused things promise never resolved. many other promise-related questions here regarding protractor don't help, because promise not set in test, page itself.
here test:
it('should roll d2', function () { element(by.id('d2button')).click(); //whatever has here waiting occur expect(element(by.binding('rolls.d2')).gettext()).not.toequal('0'); });
here html:
<button id="d2button" type="button" class="btn btn-success" ng-click="rolld2()">roll</button> <span><b>{{rolls.d2 | number}}</b></span>
here brief summary of angular code called on click:
$scope.rolld2 = function () { diceservice.getd2roll($scope.quantities.d2).then(function (data) { $scope.rolls.d2 = data.roll; }); };
and here service call:
function getd2roll(quantity) { var url = "dice/d2/" + quantity; homecoming getpromise(url); } function getpromise(url) { var deferred = $q.defer(); $http.get(url).success(deferred.resolve).error(deferred.reject); homecoming deferred.promise; }
how create test wait correctly?
the reply here utilize built in browser.waitforangular()
functionality after button click. made mutual method tests utilize looks this:
app.clickbuttonandwaitforresolution = function (button) { button.click(); browser.waitforangular(); };
then test needs click button fires ajax phone call call function , pass in button element clicked.
javascript angularjs protractor angular-promise
No comments:
Post a Comment