Patrik Schmolke
Patrik Schmolke

Reputation: 1

Testcafe Role constructor does not execute authentication function

My Testcafe tests cannot run at the moment because my defined roles wont initialize.

I have a function where I wanted to retrieve data during the login process. But it seems like the entire login logic is skipped in the Role constructor.

I have a custom Role interface:

interface MyRole extends Role {
   clientName?: string;
   aodRoles?: string[];
   sub?: string;
}

and a function that handles the login process:

// before role initialization
console.log( 'gets executed' );

const role: MyRole = Role( url, async t => {
         // everything in here is skipped...
         console.log( "Starting login" );
  
         userInfo = await this.login( t, name );
  
         console.log( "Login finished" );
        },
        // As the initial opening of the given url will automatically redirect to the openid-provider, it will never be of use.
        // Therefore, we keep the url after login
        { preserveUrl: true }
      );

console.log( 'gets also executed' );

The role instance is initialized but the entire function that is passed as an argument here is being ignored. Does somebody know what can cause this behavior?

Upvotes: 0

Views: 271

Answers (1)

Pavel Avsenin
Pavel Avsenin

Reputation: 254

I've tried to reproduce the issue, but everything works fine on my side. Here is my code:

import { Selector, Role } from 'testcafe';

interface MyRole extends Role {
    clientName?: string;
    aodRoles?: string[];
    sub?: string;
}

const developerName = Selector('#developer-name');
 
console.log( 'gets executed' );

const role: MyRole = Role('http://devexpress.github.io/testcafe/example/', async t => {
    // everything in here is skipped...
    console.log( "Starting login" );

    //userInfo = await this.login( t, name );

    console.log( "Login finished" );
  },
  // As the initial opening of the given url will automatically redirect to the openid-provider, it will never be of use.
  // Therefore, we keep the url after login
  { preserveUrl: true }
);

fixture `My Fixture`;

test('My test', async t => {
  await t
      .useRole(role)
      .typeText(developerName, 'Peter')
      .typeText(developerName, 'Paker', { replace: true })
      .typeText(developerName, 'r', { caretPos: 2 })
      .expect(developerName.value).eql('Parker');
});

The console output contains the following lines:

gets executed

Starting login

Login finished

Do you use the created role via .useRole method in your test? Would you check if my example works correctly on your side?

Upvotes: 2

Related Questions