Question

Consider this simple protractor test:

<body>
    <div ng-app="test2App" ng-controller="test2Ctrl">
        <input ng-model="myValue">
    </div>
</body>


var test2App = angular.module('test2App', [])
test2App.controller('test2Ctrl', function($scope,$timeout) {
    $timeout(function() {
       $scope.myValue = true;
    },10000);
});

describe('my suite',function() {
    it('wait for a model to be defined',function() {
        element(by.model('myValue')).evaluate('myValue')
        .then(function(v) {
            expect(v).toBe(true);
        });
    });
});

Is there a better way than the protractor sleep() function to wait for "myValue" to be loaded into scope?

thx

Was it helpful?

Solution

Try browser.wait()

https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#519

browser.wait(function(){
  // Wait until condition is true.
  return element(by.model('myValue')).evaluate('myValue')
    .then(function(v) {
        // I'm not sure if it will evaluate to a string, try it.
        return v === 'true';
    });
}, 10000)

Where 10000 is the timeout in ms.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top