We have a shortcut menu that if the user presses the .
key, a shortcut menu opens.
How can I mimic the user's behavior?
From the docs, the t.keyPress
works only on inputs and cannot be initiated out side it
You do not need an input element for t.keyPress
to work.
Edit:
Here is a simple test using 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>
So it doesn’t work when I try to await t.keyPress(‘.’)
I updated the answer with a working test. Could you share more details about your scenario? A simple example illustrating the issue would be appreciated.