我正在尝试测试应用程序是否将用户重定向到经过身份验证的路由,因为他们不是管理员。
但我需要一种方法来等待所有重定向完成,然后再调用 getCurrentUrl()
it('should not allow regular user access', async (test) => {
await test.remote
.then(e2e.impersonate('test@test.com'))
.get('/protected-route')
//.waitForAllRedirects()
.getCurrentUrl()
.then(url => {
console.log('url', url);
expect(url.indexOf('/landing-page')).not.toBe(-1);
return true;
});
});
最佳答案
最简单的做法可能是查找应位于非 protected 页面而不是 protected 页面上的内容。找到预期的内容后,请检查 URL 以验证您是否位于应在的位置。
it('should not allow regular user access', test => {
return test.remote
.then(e2e.impersonate('test@test.com'))
.get('/protected-route')
.findByCssSelector('.something.that.should.be.visible')
.getCurrentUrl()
.then(url => {
console.log('url', url);
expect(url.indexOf('/landing-page')).not.toBe(-1);
return true;
});
});
关于javascript - 如何使用 intern/web 驱动程序等待所有重定向完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54206027/