我正在测试一个带有嵌入式视频的页面,我可以使用控制台播放、停止和获取当前播放时间。
当我尝试将其转换为 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://标志/#autoplay-policy):
testcafe "chrome --autoplay-policy=no-user-gesture-required" test.js
关于javascript - Testcafe - 处理视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55182940/