return 来自辅助函数的值
return value from a helper function
我在平台的不同页面中有很多 table,我想创建一个通用功能,例如 - 提供 table 名称和列标签,并想要文本 return由函数返回测试。
我已将此函数导入到测试中,并且能够在函数中没有选择器声明的情况下发送 table 定义。对于初学者来说,return 将 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")
}
我在平台的不同页面中有很多 table,我想创建一个通用功能,例如 - 提供 table 名称和列标签,并想要文本 return由函数返回测试。
我已将此函数导入到测试中,并且能够在函数中没有选择器声明的情况下发送 table 定义。对于初学者来说,return 将 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")
}