typescript - Testcafe Role 构造函数不执行认证功能
问题描述
我的 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
实例已初始化,但此处作为参数传递的整个函数将被忽略。有人知道什么会导致这种行为吗?
解决方案
我试图重现这个问题,但我这边一切正常。这是我的代码:
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 方法创建的角色?你会检查我的例子在你身边是否正常工作吗?
推荐阅读
- java - 解决 Webflux 中的 Pageable
- python - 在滚动游戏期间调用函数
- javascript - 如何在悬停时强制 div 溢出 ul 容器?
- algolia - 字符串属性与给定字符串匹配的 Algolia 搜索
- angularjs - 在AngularJS中将表格从HTML转换为Javascript数组
- java - 在 JUnit 5 ConsoleLauncher 中未发现测试,没有错误
- android - 从 firebase 到 android 检索 2018 年 5 月 12 日 15:59:56 UTC-5 的时间戳
- python - 使用 Python 3 删除“编码大于 3 个字节的字符”
- angular - 如何让源映射在 Angular 4 和 Laravel 5.6 中工作(构建后缺少 .map 文件)
- javascript - 使用 jQuery 淡入文本,出现断断续续,相互替换