Testcafe角色构造函数不执行认证功能

问题描述 投票:0回答:1

我的 Testcafe 测试目前无法运行,因为我定义的角色不会初始化。

我有一个功能,我想在登录过程中检索数据。但似乎在 Role 构造函数中跳过了整个登录逻辑。

我有一个自定义角色界面:

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

以及处理登录过程的函数:

// 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' );

role
实例已初始化,但作为参数传递的整个函数将被忽略。有人知道什么会导致这种行为吗?

typescript testing automated-tests e2e-testing testcafe
1个回答
2
投票

我尝试重现该问题,但我这边一切正常。 这是我的代码:

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');
});

控制台输出包含以下几行:

被处决

开始登录

登录完成

您是否在测试中使用通过 .useRole 方法创建的角色? 您能检查一下我的示例在您这边是否正常工作吗?

© www.soinside.com 2019 - 2024. All rights reserved.