是否可以在Firebase身份验证项目中使用Cypress e2e测试? [英] Is it possible to use Cypress e2e testing with a firebase auth project?
问题描述
我正在探索赛普拉斯进行e2e测试,看起来像很棒的软件。
问题是身份验证,赛普拉斯文档解释了为什么使用UI非常糟糕此处。
I am exploring Cypress for e2e testing, looks like great software. The problem is Authentication, the Cypress documentation explains why using the UI is very bad here.
因此,我尝试查看应用程序的网络连接,以查看是否可以向该应用程序创建POST请求firebase API,无需使用GUI即可进行身份验证。但是我可以看到至少触发了2个请求,并且令牌已保存到应用程序存储中。
So I tried looking at the network tap of my application, to see if I could create a POST request to the firebase API, and authenticate without using the GUI. But I can see that there at least 2 request fired, and token saved to application storage.
那我应该使用什么方法?
So what approach should I use?
- 使用我的应用程序的UI进行身份验证,并指示赛普拉斯不要触摸本地存储
- 继续尝试发送正确的POST请求的方法,并将值保存到
- 让赛普拉斯运行自定义JS代码,然后使用Firebase SDK登录。
I我真的在这里寻找一些建议:)
I am really looking for some advice here :)
推荐答案
我自己做此操作时,就做出了自定义命令(例如 cy.login
进行身份验证,然后 cy.callRtdb
和 cy.callFirestore
进行验证) 。在厌倦了重复构建它们所需的逻辑之后,我将其包装到一个名为
When doing this myself I made custom commands (like cy.login
for auth then cy.callRtdb
and cy.callFirestore
for verifying data). After getting tired of repeating the logic it took to build them, I wrapped it up into a library called cypress-firebase. It includes custom commands and a cli to generate a custom auth token.
设置主要只包括在 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)
}
但有完整详细信息设置在设置文档中可用。
But there full details on setup are available in the setup docs.
披露,我是 cypress-firebase 的作者,这就是整个答案。
Disclosure, I am the author of cypress-firebase, which is the whole answer.
这篇关于是否可以在Firebase身份验证项目中使用Cypress e2e测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!