How to expect url is redirect in TestCafe?
Asked Answered
P

1

9

I want to detect URL is redirected to the login page when clicking something that needs to log in first.

Is there any way to achieve that?

Photoactinic answered 3/7, 2017 at 6:13 Comment(0)
C
9

Here is a solution for the testcafe v0.16.x. You can use ClientFunction to get page's 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');
});
Confectionary answered 3/7, 2017 at 7:37 Comment(3)
I tried this before, and it still return the original URL, not the redirect onePhotoactinic
do you mean the expect assertion is failed? Could you please provide a simple example with the page to reproduce the problem?Confectionary
I just found out it works pretty well after upgrade the testcafe, sorry for botheringPhotoactinic

© 2022 - 2024 — McMap. All rights reserved.