我们有一个快捷菜单,如果用户按下该.
键,则会打开一个快捷菜单。我如何模仿用户的行为?从文档来看,该t.keyPress
作品只能在输入上使用,而不能在其外部启动
您不需要输入元素t.keyPress
即可工作。
编辑:
这是使用的简单测试t.pressKey('.')
:
import { Selector } from 'testcafe';
fixture`Press key`
.page`./index.html`;
test('Press dot', async t => {
await t
.pressKey('.')
.expect(Selector('p').textContent).eql('Dot is pressed');
});
index.html
<html>
<body>
<p id='paragraph'>Press key</p>
<script>
document.addEventListener('keydown', event => {
if (event.key === '.')
document.getElementById('paragraph').textContent = 'Dot is pressed';
});
</script>
</body>
</html>
因此,当我尝试等待t.keyPress('。')时,它不起作用
我通过工作测试更新了答案。您能否分享有关您的方案的更多详细信息?一个简单的例子说明这个问题将不胜感激。