【问题标题】:Leadfoot session object returns promisesLeadfoot 会话对象返回承诺
【发布时间】:2015-02-24 16:01:38
【问题描述】:

我正在尝试使用 Leadfoot 模块对实习生和 selenium 进行功能测试。

对于这个测试,我试图在一个地方点击一个按钮,然后检查页面其他地方的元素的显示属性。

我找不到扩展 findById 调用搜索的方法,因此我尝试使用 session 属性,这似乎可行,但结果是所有内容都返回了 Promise。

我发现使它工作的唯一方法是链接 then 函数。 是什么让会话(及其函数返回的元素)不同?

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

    });

我确信我做错了很多事情,所以任何和所有的建议都是值得赞赏的。

【问题讨论】:

    标签: javascript promise functional-testing intern leadfoot


    【解决方案1】:

    this.remote 对象是 Command 对象,而不是 SessionElement 对象。如果你想要一个 Session,你可以从 this.remote.session 得到它,但通常不是必需的,而且 Session 对象是不可链接的。

    您的第二个 findById 不起作用的原因是因为您没有 ending 过滤您在之前的 findBy 调用中添加的。当您在查找操作后不调用end 时,任何后续查找操作都将使用前一次查找中的元素作为根元素进行搜索。

    换句话说,当你运行this.remote.findById('a').findById('b')时,它会在元素'a'中搜索元素'b',而不是在整个文档中this.remote.findById('a').end().findById('b')会在'a'和'b'中搜索整个文档。

    此外,无论何时您从回调中执行异步操作,您都需要return 操作结果。如果您不这样做,测试将不会知道它需要等待更多操作完成。返回链接还可以防止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
        });
    

    【讨论】:

      猜你喜欢
      • 2020-01-04
      • 2014-10-05
      • 1970-01-01
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多