5

I'm testing a page with an embedded video where using the console I can play, stop, and get the current playing time.

When I try to translate that to Testcafe, I get errors. Here's what I have working on the console:

var vid = document.querySelector('.video-tech')
if (vid.paused === false) {
  vid.pause();
} else {
  vid.play();
}
document.querySelector('.video-current-time-display').innerText // 0:33

Then I try to get these elements using the Testcafe syntax:

const playVideo = ClientFunction(() => {
      document.querySelector('.video-tech').play();
    });

const pauseVideo = ClientFunction(() => {
      document.querySelector('.video-tech').pause();
    });

So far so good. The problem is that I cannot work with an If-Else statement and the ClientFunction.

My goal is to get the text from the current-time-display and let the vide play for a few seconds, then stop.

Zobia Kanwal
  • 4,085
  • 4
  • 15
  • 38

1 Answers1

5

It looks like a browser policy limitation, you might need to specify (in case of Chrome browser) the --autoplay-policy=no-user-gesture-required flag (chrome://flags/#autoplay-policy):  

testcafe "chrome --autoplay-policy=no-user-gesture-required" test.js

See also: Start a Browser With Arguments

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Vladimir A.
  • 2,202
  • 2
  • 10
  • 28