【问题标题】:Clicking on a page object in nightwatchjs单击 nightwatchjs 中的页面对象
【发布时间】:2019-12-24 15:18:37
【问题描述】:

我正在使用 nightwatch 测试来编写 e2e,该应用程序具有一个带有多选元素的表格的反应网络应用程序。

为了使测试不会因每个次要版本而中断,我想使用页面对象来导航页面。这些页面对象之一是指该表。该表应该有一个名为“selectRow(position)”的函数,它应该单击该位置引用的行。

这是我的页面对象:

const listCommands = {
  selectRow: async function(position) {
    console.log(
      await this.api.elements({
        selector: '@row',
        index: position
      }),
    )
    return await this.api.click({
      selector: '@row',
      index: position
    })
  }
}

module.exports = {
  url: 'http://test',
  sections: {
    table: {
      commands: [listCommands],
      selector: '#Table',
      elements: {
        rows: {
          selector: 'tr[id^="TableRow"]',
        },
      },
    },
  },
}

所以 rows 对象包含多行。在 selectRow 函数中,console.log 实际上打印了正确元素的值,但是 click 函数向我抛出了这个错误:Error while running .locateMultipleElements() protocol action: invalid selector: An invalid or illegal selector was specified

我想要实现的是点击了正确的行。

【问题讨论】:

    标签: javascript nightwatch.js


    【解决方案1】:

    在您的命令中,您将选择器称为@row,但在您的页面对象中,您将元素称为rows。他们需要匹配。

    另外,请确保您调用的是页面对象部分的selectRow 方法,而不是页面对象本身。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多