在 Testcafe 中执行 Javascript
Execute Javascript in Test Cafe
我完全不熟悉 Javascript 并在控制台浏览器中执行此类查询。
当我在 Chrome 控制台中执行此代码时,我知道我的代码下一步应该做什么。
if (scjs.getResponses()[385] &&
scjs.getResponses()[385].bids &&
scjs.getResponses()[385].bids.length === 1) {
console.log('true')
} else {
console.log('false')
}
而且它始终在控制台中运行。
我的问题是:如何在 Testcafe 中使用相同的代码来创建断言?
谢谢
为此,您可以使用 ClientFunction
方法。有关详细信息,请参阅 Obtain Client-Side Info TestCafe 文档主题。
谢谢。我知道这个答案,但没有用。
最后我找到了解决方案:
const getVisibility = ClientFunction((format) => {
let result;
if ((window as any).scjs.getResponses()[format] &&
(window as any).scjs.getResponses()[format].bids &&
(window as any).scjs.getResponses()[format].bids.length === 1) {
result = true
} else {
result = false
}
return result;
});
const isVisible = await getVisibility(format);
return isVisible;
};
我完全不熟悉 Javascript 并在控制台浏览器中执行此类查询。 当我在 Chrome 控制台中执行此代码时,我知道我的代码下一步应该做什么。
if (scjs.getResponses()[385] &&
scjs.getResponses()[385].bids &&
scjs.getResponses()[385].bids.length === 1) {
console.log('true')
} else {
console.log('false')
}
而且它始终在控制台中运行。 我的问题是:如何在 Testcafe 中使用相同的代码来创建断言?
谢谢
为此,您可以使用 ClientFunction
方法。有关详细信息,请参阅 Obtain Client-Side Info TestCafe 文档主题。
谢谢。我知道这个答案,但没有用。 最后我找到了解决方案:
const getVisibility = ClientFunction((format) => {
let result;
if ((window as any).scjs.getResponses()[format] &&
(window as any).scjs.getResponses()[format].bids &&
(window as any).scjs.getResponses()[format].bids.length === 1) {
result = true
} else {
result = false
}
return result;
});
const isVisible = await getVisibility(format);
return isVisible;
};