cypress-example-recipes
cypress-example-recipes copied to clipboard
Recipe for Firebase authentication
import firebase from 'firebase'
firebase.initializeApp({
apiKey: '',
authDomain: '',
databaseURL: '',
projectId: '',
storageBucket: '',
messagingSenderId: ''
})
describe('Home', () => {
beforeEach(function () {
cy.exec('firebase database:set / cypress/fixtures/seed.json --confirm')
firebase.auth().signInWithEmailAndPassword('[username]', '[password]')
})
it('logs in programmatically without using the UI', function () {
cy.visit('/')
cy.get('#username').contains(firebase.auth().currentUser.email)
})
})
Hi I'm trying to understand the solution here. Can you please explain the solution, and whether it is the best practice to mock firebase auth? I'm learning the best way to mock the firebase auth. Thanks!
@iancrowther I don't understand how you can call firebase.initializeApp({ ... })
if it is already called in app bootstrapping.
I have looked at Firebase auth here: https://github.com/bahmutov/cypress-firebase-auth-example and it is pretty straightforward to log in using UI or firebase.auth().signInWithEmailAndPassword
and I probably will a little bit more into this.
Related:
- https://github.com/prescottprue/cypress-firebase
- https://github.com/bahmutov/cypress-firebase-auth-example
I don't understand how you can call firebase.initializeApp({ ... }) if it is already called in app bootstrapping.
Cypress is not aware of the initialised instance of Firebase when the integration test is run. But the app's initialised Firebase instance could be imported/re-used perhaps? import firebase from '../../src/lib/firebase';
or similar
I also wanna know how to use the browser's firebase instance, as opposed to creating a new firebase instance.
any advice?