【问题标题】:wait for scope evaluation protractor等待范围评估量角器
【发布时间】:2014-04-10 19:16:28
【问题描述】:

考虑这个简单的量角器测试:

<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);
        });
    });
});

有没有比量角器 sleep() 函数更好的方法来等待“myValue”被加载到作用域中?

谢谢

【问题讨论】:

    标签: angularjs protractor


    【解决方案1】:

    试试 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)
    

    其中 10000 是以毫秒为单位的超时时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多