我知道这个话题被讨论了很多,但我有一个独特的情况。
为了测试我们的接受环境,我们需要点击https://authentication-example.com,它运行一个脚本来添加一个会话cookie,从而对我们进行身份验证。然后,我们导航到https://acceptance-site.com来运行测试。
在尝试了许多选项之后,我能得到的最接近的解决方案是使用一个角色,比如
const a3 = Role('https://acceptance-site.com', async testController => {
await testController.navigateTo('https://authentication-example.com');
await testController.navigateTo('https://acceptance-site.com');
}, { preserveUrl: true });
fixture('Testing acceptance')
.beforeEach(async testController => {
await testController.useRole(authenticate);
});
test('example1', async testController => {
await testController.debug();
}).disablePageReloads;
test('example2', async testController => {
await testController.debug();
}).disablePageReloads;
test('example3', async testController => {
await testController.debug();
}).disablePageReloads;该解决方案使我无法加载任何与角色结束位置不同的新页面。
如果我从角色中删除{ preserveUrl: true },example2和example3会加载空白页面。如果我从测试中删除.disablePageReloads,则escond和第三个测试的身份验证失败,并收到错误"Failed to find a DNS-record for the resource for the resource at...“。另外,如果我的角色是
const a3 = Role('https://authentication-example.com', async testController => {
await testController.navigateTo('https://acceptance-site.com');
}, { preserveUrl: true });所有测试的身份验证都失败。
我注意到,当我成功工作时,我应该获得的cookie实际上在调试时被保存在application下的会话中,并且被这个锤头存储包装器更改。测试时的基本url是前面有随机字母的testCafe服务器的ip和端口,例如172.0.0.1:8080/hoi23hh/https://acceptance-site.com,这会导致我的cookie保存在会话中(而不是在不使用test cafe时通常出现的cookie下),作为url。
当我删除.disablePageReloads,但在角色上保留preserveUrl: true时,'cookie‘保持不变,但基本url更改为类似于172.0.0.1:8080/ohgbo223/https://acceptance-site.com
因此,url中的"hoi23hh“变为"ohgbo223”,并且cookie/会话密钥不再与url匹配,并且认证失败。
对于持久化身份验证,同时仍然能够更改页面等,您有什么建议
发布于 2018-10-25 18:07:20
我不建议对角色使用disablePageReloads功能,因为它是内部的,可能不稳定。preserveUrl option将允许每个测试从https://acceptance-site.com页面开始。因此,我认为这是最适合您的方式::
const a3 = Role('https://acceptance-site.com', async testController => {
...
}, { preserveUrl: true });
fixture('Testing acceptance')
.beforeEach(async testController => {
await testController.useRole(authenticate);
});
test('example1', async testController => {
await testController.debug();
})
test('example2', async testController => {
await testController.debug();
})https://stackoverflow.com/questions/52975982
复制相似问题