【发布时间】:2021-02-03 15:49:26
【问题描述】:
我有一个使用 OAuth 的外部登录页面。我想将它与 Testcafe 一起使用来运行 e2e 测试。在正常情况下,我可以毫无问题地登录。没有给出错误。如果我运行 testcafe,我会收到以下错误:
- Error in Role initializer -
A JavaScript error occurred on ...
Repeat test actions in the browser and check the console for errors.
If you see this error, it means that the tested website caused it. You can fix it or disable tracking JavaScript errors in TestCafe. To do the
latter, enable the "--skip-js-errors" option.
If this error does not occur, please write a new issue at:
"https://github.com/DevExpress/testcafe/issues/new?template=bug-report.md".
JavaScript error details:
SyntaxError: In strict mode code, functions can only be declared at top level or inside a block.
Browser: Chrome 88.0.4324.146 / macOS 10.15.7
跳过错误不是解决方案,因为脚本不会加载,我无法登录网站。
测试如下所示:
export const adminRole = Role(
`https://url of the oauth site`,
async (t) => {
await t
.typeText(Selector('#username'), 'username')
.typeText(Selector('#password'), 'strongpassword')
.click(Selector('#mainButton'));
},
{ preserveUrl: true }
);
fixture('Home page');
test('Show profile page', async (t) => {
await t.useRole(adminRole);
await t.navigateTo('http://tested site/profile');
await waitForAngular();
});
【问题讨论】:
-
我无法重现您提到的错误。你能举一个复制它的页面的例子吗?另外,您能否在不使用
Role和.useRole的情况下重写测试并检查错误是否可重现?此外,您可以在github 上提交错误。
标签: testing automation automated-tests e2e-testing testcafe