Search code examples
testingvideoautomated-testsweb-testingtestcafe

How to tell if html video is currently playing


I'm trying to test if an Html video is currently playing, but can't seem to figure out how to get the currentTime. I've been trying things like:

async videoIsPlaying(indexOfVideo = 0) {
    return ClientFunction(() => {
        const video = document.getElementsByTagName('video')[indexOfVideo];
        return video.currentTime > 0;
    });
}

but my expect:

await t.expect(await playerPage.videoIsPlaying()).eql(true);

is returning:

AssertionError: expected [Function: __$$clientFunction$$] to deeply equal true

What am I doing wrong? Also, I'm using .eql() because .ok() returns truthy for any result.


Solution

  • Ahhh... just needed to fire the function, and also pass in the index thusly...

    async videoIsPlaying(indexOfVideo = 0) {
        return await ClientFunction((indexOfVideo) => {
            const video = document.getElementsByTagName('video')[indexOfVideo];
            return video.currentTime > 0;
        })(indexOfVideo);
    }
    

    Just FYI, this function lives in a page object