gpt4 book ai didi

angularjs - 等待范围评估 Protractor

转载 作者:行者123 更新时间:2023-12-03 06:47:24 25 4
gpt4 key购买 nike

考虑这个简单的 Protractor 测试:

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

是否有比 Protractor sleep() 函数更好的方法来等待“myValue”加载到作用域中?

谢谢

最佳答案

尝试 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 是以毫秒为单位的超时。

关于angularjs - 等待范围评估 Protractor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22997058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com