Search code examples
javascripttestingdomautomated-teststestcafe

Execute Javascript in Test Cafe


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


Solution

  • 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;
    };