【发布时间】: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。
我想要实现的是点击了正确的行。
【问题讨论】: