我正在测试一个带有嵌入式视频的页面,可以在其中使用控制台播放,停止并获取当前播放时间。

当我尝试将其翻译为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
另请参阅:Start a Browser With Arguments

09-25 17:36
查看更多