5

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

当我尝试将其翻译到 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并让视频播放几秒钟,然后停止。

4

1 回答 1

5

它看起来像浏览器策略限制,您可能需要指定(如果是 Chrome 浏览器)--autoplay-policy=no-user-gesture-required标志(chrome://flags/#autoplay-policy):  

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

另请参阅:使用参数启动浏览器

于 2019-03-15T14:42:27.690 回答