Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'alt+left' for going to previous page doesn't work with testcafe but works fine manually

I'm trying to go back to the previous page from the existing page from my TestCafe code using:

await t.pressKey('alt+left');

But this doesn't seem to work. There is no change in the page. But manually when I verify in the browser, it seems to work fine.

Could someone help me with this, I want to be able to go back to the previous page using keyboard strokes alone.

like image 920
Harinya Avatar asked Sep 03 '25 15:09

Harinya


1 Answers

TestCafe doesn't support the alt+left key combination (see the list of supported key combinations here).

You can use the browser's History API to navigate between pages.

See an example:

import { Selector, ClientFunction } from 'testcafe';

fixture `Fixture`
  .page `https://devexpress.github.io/testcafe/`;

const back = ClientFunction(() => window.history.back());

test('test', async t => {
    await t.navigateTo('https://devexpress.github.io/testcafe/documentation/getting-started/');

    await back();
});
like image 81
mlosev Avatar answered Sep 05 '25 04:09

mlosev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!