【发布时间】:2015-08-04 21:46:23
【问题描述】:
在这个例子中,我正在测试一个元素是否位于页面底部。我在 Protractor/Webdriver 中使用了 Promise,但我认为我用错了,因为我认为它不应该看起来如此混乱。
describe('Element', function(){
it('should be placed at bottom', function(){
element(by.id('page').getSize().then(function(dimP){
element(by.id('element').getLocation().then(function(locE){
element(by.id('element').getSize().then(function(dimE){
expect(locE.y + dimE.height).toEqual(dimP.height);
})
});
});
})
});
我怎样才能以更简洁的方式做到这一点?我正在使用 Protractor 2.1.0 版。
我尝试过这样做:
expect(element(by.id('page').getSize().height).toEqual(1000);
但它说 Expected undefined to equal 1000. 所以看起来我不能使用这里解释的返回值:https://github.com/angular/protractor/blob/master/docs/control-flow.md
(我在实际测试中使用的是页面对象,所以变量没有示例中那么难看。)
【问题讨论】:
标签: javascript selenium-webdriver promise protractor