如何期望 url 在 TestCafe 中被重定向?

How to expect url is redirect in TestCafe?

我想检测 URL 在单击需要先登录的内容时被重定向到登录页面。

有什么办法可以实现吗?

这是 testcafe v0.16.x 的解决方案。您可以使用 ClientFunction 获取页面的 url:

import { ClientFunction, t } from 'testcafe';

fixture `check url`
    .page `http://example.com`;

test('check url', async t => {
    const getLocation = ClientFunction(() => document.location.href);

    await t.expect(getLocation()).contains('example.com');
});