Reputation: 103
I'm totally new to Javascript and executing this kind of queries in the console browser. When I execute this code in the Chrome console I have an answser what my code should do next.
if (scjs.getResponses()[385] &&
scjs.getResponses()[385].bids &&
scjs.getResponses()[385].bids.length === 1) {
console.log('true')
} else {
console.log('false')
}
And it always works in the console. My question is: how can I use the same code in Testcafe to create an assertion?
Thank you
Upvotes: 1
Views: 1188
Reputation: 103
Thank you. I know this answer but it didn't work. Finaly I found the solution:
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;
};
Upvotes: 3
Reputation: 2348
You can use the ClientFunction
approach for this purpose. Refer the Obtain Client-Side Info TestCafe documentation topic for details.
Upvotes: 2