Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expect url is redirect in TestCafe?

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?

like image 579
Knovour Avatar asked Jul 03 '17 06:07

Knovour


1 Answers

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');
});
like image 137
Alexander Moskovkin Avatar answered Nov 08 '22 04:11

Alexander Moskovkin