我正在尝试使用 leadfoot 模块对 intern 和 selenium 进行功能测试。
对于这个测试,我试图在一个地方点击一个按钮,然后检查页面其他地方元素的显示属性。
我找不到扩展 findById 调用搜索的方法,所以我尝试使用 session 属性,这似乎有效,但结果是所有内容都返回一个 promise 。
我发现使它起作用的唯一方法是链接 then 函数。 是什么让 session (及其函数返回的元素)不同?
return this.remote
.findById('buttonContainer')
.findByClassName('buttonClass')
.click()
.session
.findById('stagePanel')
.then(function(element) {
element.findByClassName('itemList')
.then(function(element) {
element.getComputedStyle('display')
.then(function (display) {
// check display property
});
});
});
我确信我做错了很多事情,所以任何和所有的建议都会受到赞赏。
最佳答案
this.remote
对象是一个 Command对象,不是 Session或 Element目的。如果您想要一个 Session,您可以从 this.remote.session
获取它,但通常不需要,而且 Session 对象不可链接。
你的第二个 findById
不工作的原因是因为你不是 end
ing过滤您在之前的 findBy
调用中添加的内容。如果您在查找操作后未调用 end
,则任何后续查找操作都将使用前一个查找中的元素作为要搜索的根元素。
换句话说,当您运行 this.remote.findById('a').findById('b')
时,它将在元素 'a' 内搜索元素 'b',不在整个文档中 this.remote.findById('a').end().findById('b')
将在整个文档中搜索 'a' 和 'b'。
此外,任何时候从回调中执行异步操作时,您都需要返回
操作的结果。如果不这样做,测试将不知道它需要等待更多操作完成。返回链接也阻止了 callback pyramids :
return this.remote
.findById('buttonContainer')
.findByClassName('buttonClass')
.click()
.end(2)
.findById('stagePanel')
.then(function(stagePanel) {
return stagePanel.findByClassName('itemList');
}).then(function(itemList) {
return itemList.getComputedStyle('display');
}).then(function (display) {
// check display property
});
关于javascript - Leadfoot session 对象返回 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28700514/