【发布时间】:2014-08-08 23:28:26
【问题描述】:
我正在编写一个测试用例,用于使用 Protractor 在 Angular 应用程序的页面中添加商店信息,最初我在计算我已经拥有的商店数量,在测试块完成后,我希望计数增加一个所以为此,我通过创建承诺How to create and manipulate promises in Protractor? 的链接来做到这一点
describe('myApp', function() {
var items,startCount;
var testPromise = function(){
items = element.all(by.repeater('store in storelist'));
var deferred = protractor.promise.defer();
items.count().then(function(orgCount){
startCount = orgCount;
console.log('Start Count: '+ startCount); //prints correct value e.g, 6
}, function(error){
console.log(error);
});
return deferred.promise;
};
it('should accept valid data for adding new store', function() {
var cNum = null;
testPromise().then(function(result){
cNum = result;
console.log('cNUm value: '+ cNum); //this value doesn't get printed in console
});
/* Code for adding test fields in store page */
expect(items.count()).toBe(cNum+1);
});
});
我希望商店数量在测试结束时保持不变。 count() 正在解决一个承诺,并且在 testPromise() 中打印了存储计数的正确值,但是当我调用 testPromise().then 方法时它会阻塞它永远不会进入那个“then”块
最后的结果是
Message:
Expected 6 to be 1.
Stacktrace:
Error: Failed expectation
我还通过此链接http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_promise_Promise.html 对 webdriver.promise.Promise() 进行了更多研究,并尝试使用它来创建承诺并解决其价值,但不确定问题出在哪里。要么我收到错误消息说“预计 6 为 NaN”或“预计 6 为 1”我没有正确解决承诺或写“那么”块吗?非常感谢您对此问题的一些见解/帮助。
【问题讨论】:
标签: angularjs selenium protractor