Skip to content

Instantly share code, notes, and snippets.

@rightsaidjames
Created July 10, 2023 11:15
Show Gist options
  • Save rightsaidjames/ecb7c08ac5a3d9866903c39c2baedd28 to your computer and use it in GitHub Desktop.
Save rightsaidjames/ecb7c08ac5a3d9866903c39c2baedd28 to your computer and use it in GitHub Desktop.
Launch Darkly Cypress Custom Command
Cypress.Commands.add('checkFlag', key => {
const env = Cypress.env('launchDarklyEnvironment')
const projKey = 'default'
cy.fixture('auth').then(auth => {
const accessToken = auth.launchDarklyAccessToken
cy.request({
method: 'GET',
url: `https://app.launchdarkly.com/api/v2/flags/${projKey}/${key}`,
headers: {
Authorization: accessToken
},
qs: `env=${env}`
}).its(`body.environments.${env}.on`)
})
})
// Store Feature Flag value (retrieved from page object constructor method) as alias:
cy.checkFlag(addToBasket.basketNotificationFF).as('basketNotificationFF')
// Retrieve alias then skip steps based on Feature Flag boolean value
cy.get('@basketNotificationFF').then(basketNotificationFF => {
skipOn(basketNotificationFF === true, () => {
addToBasket.assertProductQuantityIsCorrect(1)
})
})
// Import feature flags from enum file at top of spec file:
import {
FeatureFlag
} from '../../../../src/config/constants/feature-flags'
// Only run test when FF is enabled (use inside it() block):
cy.checkFlag(FeatureFlag.CHECKOUT_PAYMENT_STRIPE_MULTIBANCO).then(
multibancoStripeEnabled => {
cy.onlyOn(multibancoStripeEnabled === true)
}
)
// Skip all tests in block when FF is enabled:
before(() => {
cy.checkFlag(FeatureFlag.ACCOUNT_FAVOURITES_GUEST_FAVOURITES).then(
guestFavourites => {
cy.skipOn(guestFavourites === true)
}
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment