单击时 TestCafe 持久化数据

TestCafe persist data when clicking

在 TestCafe 中,单击锚标记后,我会重定向到一个新页面和一个基本上将单击事件记录到对象的事件。

我想在 TestCafe 中测试对象中单击事件的值,但是由于重定向发生,我丢失了对象。

我可以手动执行此操作,因为我可以在单击 link 的同时按住 shift 并为重定向页面打开一个新的 window,但保留原始页面在原来的 window 然后在控制台中看到该对象。

试图弄清楚是否有办法 "simulate" 点击,但不进行重定向。或者,能够在点击后立即以某种方式断言,但在重定向之前?

迷你示例:

await t
.click('a') // here it already redirects so I'll lose the object
.expect(object).contains('value')

以下测试展示了如何为 link:

禁用和启用导航
import { Selector, ClientFunction } from 'testcafe';

fixture `Navigation`
    .page `example.com`;

const enableNavigationControl = ClientFunction(selector => {
    const element = selector();

    element.addEventListener('click', event => window.disableNavigation && event.preventDefault());
});

const disableNavigation = ClientFunction(() => window.disableNavigation = true);
const enableNavigation  = ClientFunction(() => window.disableNavigation = false);

test('navigation', async t => {
    const link = Selector('a');

    await enableNavigationControl(link);
    await disableNavigation();

    await t.click(link);

    // Perform assertions...

    await enableNavigation();

    await t.click(link);
});