cypress-example-recipes icon indicating copy to clipboard operation
cypress-example-recipes copied to clipboard

Recipe for Firebase authentication

Open kuceb opened this issue 6 years ago • 7 comments

kuceb avatar Mar 02 '18 15:03 kuceb

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)
  })
})

iancrowther avatar May 08 '18 09:05 iancrowther

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!

fikrikarim avatar Aug 17 '18 09:08 fikrikarim

@iancrowther I don't understand how you can call firebase.initializeApp({ ... }) if it is already called in app bootstrapping.

romines avatar Sep 11 '18 23:09 romines

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.

bahmutov avatar Mar 26 '19 13:03 bahmutov

Related:

  • https://github.com/prescottprue/cypress-firebase
  • https://github.com/bahmutov/cypress-firebase-auth-example

bahmutov avatar Mar 26 '19 13:03 bahmutov

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

logicalicy avatar May 25 '20 01:05 logicalicy

I also wanna know how to use the browser's firebase instance, as opposed to creating a new firebase instance.

any advice?

mesqueeb avatar Jun 13 '20 00:06 mesqueeb