Luis Garcia
Luis Garcia

Reputation: 21

How can I redirect to another page using testcafe after logging with TestCafe

I am trying to redirect to another page after a login with testCafe, but after the login that other page remains blank, that is, it never loads, or at other times it simply closes the session without entering. The fact is that it does not let me go to the main page after login. I use a VPN connection. Do you know what it could be, a login token or VPN problem? How can I solve it?

This my code

import { Selector } from 'testcafe';
import { Role } from 'testcafe'

const role = Role('login_page', async t => {
    await t
      .wait(10000)

      .click(Selector('button.btn.btn-dark.btn-lg.btn-block'))
      .typeText('input[name="loginfmt"]', 'my_user')
      .pressKey('enter')
      .typeText('input[name="Password"]', 'my_password')
      .click('span[id="submitButton"]')
      .click('input[id="idSIButton9"]')

}, { preserveUrl: true });

fixture `My Fixture`;

test('My test', async t => {
    await t
        .navigateTo('home_page_after_login')
        .useRole(role);
});

Upvotes: 2

Views: 1378

Answers (1)

Janaaaa
Janaaaa

Reputation: 1406

You seem to be navigating to the 'home_page_after_login' page before actually logging in.

Could you try this?

test('My test', async t => {
    await t
        .useRole(role);
        .navigateTo('home_page_after_login')
        
});

Also, there was a known issue in 'Roles' module. So, you might have to use a 'wait' after clicking 'login' button.

const role = Role('login_page', async t => {
    await t
      .wait(10000)
      .click(Selector('button.btn.btn-dark.btn-lg.btn-block'))
      .typeText('input[name="loginfmt"]', 'my_user')
      .pressKey('enter')
      .typeText('input[name="Password"]', 'my_password')
      .click('span[id="submitButton"]')
      .click('input[id="idSIButton9"]')
      .wait(5000)

}, { preserveUrl: true });

Upvotes: 2

Related Questions