首页 > 解决方案 > 无法使用 Test Cafe 播放视频,Click 事件什么也不做

问题描述

无法使用 Test Cafe 播放视频,点击事件未播放视频。我可以将鼠标悬停到特定元素,但是当我单击它时应该开始播放视频。但它无法播放。

const logger = RequestLogger({ url: 'URL', method: 'post' },
  { logResponseBody: true, logRequestBody: true, stringifyResponseBody: true, stringifyRequestBody: true });

const obj = 'URL';
await t.navigateTo(obj.uri);
const loader = Selector('.web_player_loader.loader');
await t.expect(loader.exists).notOk({ timeout: 30000 });
console.log('Video Started....');
const playerBase=Selector('.player-base');
await t.hover(playerBase);
await t.click(playerBase);

console.log('Logger Request Length is ',logger.requests.length);```

I am running the script using following params.

testcafe chrome --autoplay-policy=no-user-gesture-required ./tests -s takeOnFails=true --skip-js-errors=true

Getting this error in the Console.

main.dad0fa6441f0af49d386.js:2 Uncaught (in promise) TypeError: Cannot read property 'topLPVs' of undefined
    at t.value (main.dad0fa6441f0af49d386.js:2)
    at e.value (main.dad0fa6441f0af49d386.js:2)
    at e.value (main.dad0fa6441f0af49d386.js:2)
    at t.<anonymous> (main.dad0fa6441f0af49d386.js:2)
    at l (vendor~main.58.ac1d1027b98ee8b3b2d1.js:9)
    at Generator._invoke (vendor~main.58.ac1d1027b98ee8b3b2d1.js:9)
    at Generator.next (vendor~main.58.ac1d1027b98ee8b3b2d1.js:9)
    at n (hammerhead.js:15)
    at value (hammerhead.js:6)
    at n (vendor~main.58.ac1d1027b98ee8b3b2d1.js:2)
    at a (vendor~main.58.ac1d1027b98ee8b3b2d1.js:2)

标签: javascripttestingautomated-testsui-automationtestcafe

解决方案


根据您提供的调用堆栈,您的应用程序中似乎发生了错误。发生此行为的原因是 testcafe 单击速度快于最终用户,并且测试页面上的初始化代码可能没有足够的时间来完成。如果您在悬停和单击操作之间添加延迟,您能否澄清一下是否会发生相同的错误?

t.hover(playerBase)
 .wait(1000)
 .click(playerBase);

如果重现错误,您能否分享一个显示该错误的示例?我会在本地研究它。


推荐阅读