5 javascript video jquery-selectors testcafe current-time
我正在测试一个带有嵌入式视频的页面,使用控制台我可以播放、停止和获取当前播放时间。
当我尝试将其转换为 Testcafe 时,出现错误。这是我在控制台上的工作:
var vid = document.querySelector('.video-tech')
if (vid.paused === false) {
  vid.pause();
} else {
  vid.play();
}
document.querySelector('.video-current-time-display').innerText // 0:33
然后我尝试使用 Testcafe 语法获取这些元素:
const playVideo = ClientFunction(() => {
      document.querySelector('.video-tech').play();
    });
const pauseVideo = ClientFunction(() => {
      document.querySelector('.video-tech').pause();
    });
到现在为止还挺好。问题是我不能使用 If-Else 语句和ClientFunction.
我的目标是从 中获取文本current-time-display并让视频播放几秒钟,然后停止。
看起来像是浏览器政策限制,您可能需要指定(在 Chrome 浏览器的情况下)--autoplay-policy=no-user-gesture-required标志 (chrome://flags/#autoplay-policy):
 
testcafe "chrome --autoplay-policy=no-user-gesture-required" test.js
另请参阅:使用参数启动浏览器