首页 > 解决方案 > 使用 amazon-congnito-identity-js 脚本的 testcafe 仅在 IE 或 Edge 上失败

问题描述

当我们在 IE 或 Edge 上运行 testcafe 时,它​​中止了。(Chrome/Safari/Firefox 工作正常)我们使用 amazon-congnito-identity-js 进行身份验证。

testcafe 命令

testcafe --live edge tests/* --screenshots my-fixture/edge
testcafe --live ie tests/* --screenshots my-fixture/ie

这是中止代码的一部分。

await t
        .click('#login')
        .wait(1000);

中止消息

1) - Error in Role initializer -
      An error occurred in the native dialog handler called for a native alert dialog on page 

所以我们像这样设置一个 setNativeDialogHandler 。

await t
.setNativeDialogHandler((type, text, url) => {
        throw 'alert was revoked: ' + text;
        })
.click('#login')
.wait(1000);

对话文本是这样的。

NotAuthorizedException: Incorrect username or password.

此消息可能从 AWS cognito 返回...

但是用户名和密码设置正确。

cognitoUser.authenticateUser(
      console.log("user is " + username);
      console.log("password is " + password);
      new AuthenticationDetails({
        Username: username,
        Password: password,
      }), {
        onSuccess: success,
        onFailure: failure,
      })

console.log(在调试模式下)

username is test // <- correct
password is 12345678 // <- correct

此错误仅发生在 IE 或 Edge 上。

你能帮助我吗?

环境

测试咖啡馆:1.2.1

节点:8.11.3

npm:5.6.0

即:11 边缘:17,18


更新

登录前显示获取控制台消息,这是显示的消息。

IE/边缘

{"log":[],"info":[],"warn":[],"error":["Error during service worker registration: SecurityError","Error during service worker registration: SecurityError"]}

铬/Safari/火狐

{"log":[],"info":[],"warn":[],"error":[]}
export const regularAccUser = Role(URL, async (t: TestController) => {
    await t
        .typeText(id, 'test')
        .typeText(pass, '12345678 ');
    
    const message = await t.getBrowserConsoleMessages();
    console.log(JSON.stringify(message));

    await t
        .click('#login')
        .setNativeDialogHandler((type, text, url) => {
            throw 'alert was revoked: ' + text;
            })
        .wait(1000);
    }, { preserveUrl: true }
);

反应源

import {
  CognitoUserPool,
  AuthenticationDetails,
  CognitoUser,
} from 'amazon-cognito-identity-js';

var cognitoUser = new CognitoUser({
    Username: username,
    Pool: userPool(),
  });

console.log("user is " + username);
console.log("password is " + password);

cognitoUser.authenticateUser(
      new AuthenticationDetails({
        Username: username,
        Password: password,
      }), {
        onSuccess: success,
        onFailure: failure,
      })

标签: automated-testsamazon-cognitoe2e-testingweb-testingtestcafe

解决方案


推荐阅读