从帮助程序函数返回值



我在平台的不同页面中有很多表,并希望创建一个通用函数,例如 - 提供表名和列标签,并希望函数返回的文本返回到测试。

我已将此函数导入测试中,并且能够在函数中没有选择器声明的情况下发送表定义。对于初学者来说,将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;
}
}
}

更新:我能够添加返回 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")
}

最新更新