有没有办法使用" this.remote"在里面呢?

时间:2016-02-15 07:39:37

标签: intern

有没有办法使用" this.remote"在里面?

return this.remote
.findByCssSelector('.myClass')
  .isDisplayed()
  .then(function(disp) {
     // How to use this.remote here?
  })
.end();

2 个答案:

答案 0 :(得分:2)

您可以通过预先保存参考来在回调中使用this.remote,例如:

var remote = this.remote;
return remote
    .findByCssSelector('.myClass')
    .isDisplayed()
    .then(function (disp) {
        return remote
            .doLeadfootThings()
    })

另一种选择是使用this.parent,例如:

return this.remote
    .findByCssSelector('.myClass')
    .isDisplayed()
    .then(function (disp) {
        return this.parent
            .doLeadfootThings()
    })

this.parent是指向父命令链的指针,因此它在then回调点具有命令链的上下文。差异对后续操作很重要。

return remote
    .findById('someTable')
    .then(function () {
        // context of this.parent is #someTable
        return this.parent
            .findByTagName('tr')
            // found TR is the first row in #someTable
            .getVisibleText();
    })

VS

return remote
    .findById('someTable')
    .then(function () {
        // context of remote is empty
        return remote
            .findByTagName('tr')
            // found TR is the first TF on the page, not necessarily the first
            // in #someTable
            .getVisibleText();
    })

答案 1 :(得分:0)

另一种方法是使用bind()

return this.remote
    .findByCssSelector('.myClass')
      .isDisplayed()
      .then(function(disp) {
         // How to use this.remote here?
         return this.remote...
      }.bind(this))
    .end();
相关问题