node.js - 如何在 Cypress.io 中使用 Firebase Auth 的 Google 登录选项
问题描述
在使用 Cypress 测试我的 Angular 6 应用程序时,我需要使用 Google Sign-In 的帮助。它无法使用登录弹出窗口,因此我尝试遵循赛普拉斯的建议“始终cy.request()
通过其 API 与 3rd 方服务器通信”。这来自https://docs.cypress.io/guides/references/best-practices.html#Visiting-external-sites然后将我们指向这个示例:https ://github.com/cypress-io/cypress-example -recipes/blob/master/examples/logging-in__single-sign-on/cypress/integration/logging-in-single-sign-on-spec.js - 有关如何执行此操作的更多信息,请参阅演示文稿中的第 23 分钟赛普拉斯作者:https ://www.youtube.com/watch?v=5XQOK0v_YRE
我正在使用视频解决方案并尝试根据https://firebase.google.com/docs/auth/web/google-signin#advanced-authenticate-with-firebase-in-nodejs为 Firebase Auth 修改它,但我'我陷入了如何获得正确的问题id_token
,到目前为止,我的 commands.js 文件中有这段代码:
Cypress.Commands.add('login', () => {
var id_token = ___?____;
cy.request({
method: 'POST',
url: 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key=[API_KEY]',
body: {
"requestUri": "http://localhost:3500",
"postBody": `id_token=${id_token}&providerId=google.com`,
"returnSecureToken": true,
"returnIdpCredential": true
}
})
})
我相信我需要使用不同的 API 来启动登录并请求用户凭据,其中将包括 id_token,因此我尝试了https://firebase.google.com/docs/auth/web/google-signin#advanced- authenticate-with-firebase-in-nodejs但还不够熟练,无法将外部 js 文件 ( https://apis.google.com/js/platform.js ) 拉入 Node (这在 js 文件中可能是不可能的它在 html 中的方式)。使用这个包:https ://github.com/google/google-auth-library-nodejs可能是我的下一个尝试。有没有人可以从这里取走?
Is it possible to use Cypress e2e testing with a firebase auth project?- 但他们正在使用用户登录并通过。
解决方案
推荐阅读
- lua - 无法在 Garry 的 Mod“Spartan Kick”插件中设置伤害值以秒杀 NPC/玩家
- android - Android工作室滑行问题
- python - 如何在Python中对包含分类变量的列的行数求和
- java - 有没有办法在 Java 中以类型安全的方式声明 List 的二维数组?
- mongodb - 如何在 MongoDB 中复制文档中的字段?
- python - Twilio Media Stream 和 websocket 服务器 socketio python
- machine-learning - 栖息地挑战:运行DD-PPO脚本时遇到文件**.scn不存在错误
- python - 使用 CELF 的网络中的影响最大化
- powershell - PowerShell 和 conda 的 vscode 问题
- javascript - 为什么类 JS 执行两次?