我在平台的不同页面上有很多表,并且想要创建一个通用函数,例如-提供表名和列标签,并希望该函数返回的文本返回测试。
我已将此函数导入测试中,并且能够发送表定义,而无需在函数中也具有选择器声明。对于初学者,我正在努力将tdText返回测试。有什么见解-还是我完全错了?
export async function columnMatcher(tableDefinition){
const table = tableDefinition;
const rowCount = await table.find('tbody > tr').count;
const columnCount = await table.find('tbody > tr').nth(0).find('*').count;
for(let i = 0; i < rowCount; i++) {
for(let j = 0; j < columnCount; j++) {
let tdText = await table.find('tbody > tr').nth(i).find('*').nth(j).textContent;
}
}
}
更新:我能够只添加return tdText,它起作用。但是,我希望将此作为客户端功能。仍在研究使用客户端功能。
辅助功能:
import {t} from "testcafe"
export async function columnMatcher(tableDefinition, columnValue, columnReference,columnValuer,columnReferencer){
const table = tableDefinition;
const rowCount = await table.find('tbody > tr').count;
for(let i = 0; i < rowCount; i++) {
const tdText = await table.find('tbody > tr').nth(i).find('*').nth(columnValuer).textContent;
const tdReferrer = await table.find('tbody > tr').nth(i).find('*').nth(columnReferencer).textContent;
if (tdText == columnValue && tdReferrer == columnReference){
const foundMatch = true
return foundMatch;
}
}
}
在我的测试中:
const foundMatch = await columnMatcher(messagingListPage.messageListtable,userdata.reasontype,userdata.templatename,columnvaluer,columnreferencer)
if (foundMatch != true){
console.log ("Match was not found")
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句