gpt4 book ai didi

firebase - 是否可以将 Cypress e2e 测试与 firebase auth 项目一起使用?

转载 作者:行者123 更新时间:2023-12-04 08:02:48 26 4
gpt4 key购买 nike

我正在探索 Cypress 进行 e2e 测试,看起来很棒的软件。
问题是身份验证, Cypress 文档解释了为什么使用 UI 非常糟糕 here .
所以我尝试查看我的应用程序的网络分接头,看看我是否可以创建一个对 firebase API 的 POST 请求,并在不使用 GUI 的情况下进行身份验证。但我可以看到至少有 2 个请求被触发,并且 token 保存到应用程序存储中。
那么我应该使用什么方法呢?

  • 使用我的应用程序的 UI 进行身份验证,并指示 Cypress 不要触摸本地存储
  • 继续尝试发送正确 POST 请求的方法,并将值保存到本地存储。
  • 让 Cypress 运行自定义 JS 代码,然后使用 Firebase SDK 登录。

  • 我真的在这里寻找一些建议:)

    最佳答案

    当我自己这样做时,我做了自定义命令(如 cy.login 用于身份验证,然后 cy.callRtdbcy.callFirestore 用于验证数据)。在厌倦了重复构建它们所需的逻辑之后,我将它包装到一个名为 cypress-firebase 的库中。 .它包括自定义命令和生成自定义身份验证 token 的 cli。

    设置主要只是在 cypress/support/commands.js 中添加自定义命令。 :

    import firebase from 'firebase/app';
    import 'firebase/auth';
    import 'firebase/database';
    import 'firebase/firestore';
    import { attachCustomCommands } from 'cypress-firebase';

    const fbConfig = {
    // Your config from Firebase Console
    };

    window.fbInstance = firebase.initializeApp(fbConfig);

    attachCustomCommands({ Cypress, cy, firebase })

    并将插件添加到 cypress/plugins/index.js :
    const cypressFirebasePlugin = require('cypress-firebase').plugin

    module.exports = (on, config) => {
    // `on` is used to hook into various events Cypress emits
    // `config` is the resolved Cypress config

    // Return extended config (with settings from .firebaserc)
    return cypressFirebasePlugin(config)
    }

    但是有关于设置的完整细节 are available in the setup docs .

    披露,我是 cypress-firebase的作者,这就是全部答案。

    关于firebase - 是否可以将 Cypress e2e 测试与 firebase auth 项目一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48735570/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com