9

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

有没有办法做到这一点?

4

1 回答 1

8

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

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');
});
于 2017-07-03T07:37:30.073 回答