Skip to content

Commit

Permalink
bug(e2e): flaky assertion in beforeEach (#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol authored Nov 6, 2024
1 parent 54af0cc commit c521ddd
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 26 deletions.
4 changes: 4 additions & 0 deletions cypress/e2e/10-resources/t10-create-taxes.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { TAX_TEN_CODE, TAX_TWENTY_CODE } from '../../support/reusableConstants'

describe('Create taxes', () => {
beforeEach(() => {
cy.login()
})

it('should create taxes', () => {
cy.visit('/settings/taxes')
cy.url().should('include', '/settings/taxes')
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/10-resources/t20-create-customer.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { customerName } from '../../support/reusableConstants'

describe('Create customer', () => {
beforeEach(() => {
cy.visit('/customers')
cy.login().visit('/customers')
})

it('should create customer', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/10-resources/t30-create-bm.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Create billable metrics', () => {
beforeEach(() => {
cy.visit('/billable-metrics')
cy.login().visit('/billable-metrics')
})

it('should create count billable metric', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/10-resources/t40-create-plan.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { planWithChargesName } from '../../support/reusableConstants'

describe('Create plan', () => {
beforeEach(() => {
cy.visit('/plans')
cy.login().visit('/plans')
})

it('should be able to access plans', () => {
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/10-resources/t50-edit-plan.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
} from '../../support/reusableConstants'

describe('Edit plan', () => {
beforeEach(() => {
cy.login()
})

it('should be able to close the form without warning dialog when no data has changed', () => {
cy.visit('/plans')
cy.get(`[data-test="${planWithChargesName}-wrapper"]`).within(() => {
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/10-resources/t60-coupons-create-edit-apply.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { customerName } from '../../support/reusableConstants'
const couponName = `Coupon-${Math.round(Math.random() * 10000)}`

describe('Coupons', () => {
beforeEach(() => {
cy.login()
})

it('should be able create a coupon with plan limitation', () => {
cy.visit('/coupons')
cy.get(`[data-test="add-coupon"]`).click()
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/10-resources/t70-addon-create-edit.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
describe('Add On', () => {
beforeEach(() => {
cy.login()
})

const addOnName = `AddOn-${Math.round(Math.random() * 10000)}`
const description =
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Necessitatibus aliquam at dolor consectetur tempore quis molestiae cumque voluptatem deserunt similique blanditiis aperiam, distinctio nam, asperiores enim officiis culpa aut. Molestias?'
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/t10-add-subscription.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { customerName } from '../support/reusableConstants'

describe('Subscriptions', () => {
beforeEach(() => {
cy.visit('/customers')
cy.login().visit('/customers')
cy.get(`[data-test="${customerName}"]`).click()
})

Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/t20-invitations.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
describe('Invitations', () => {
beforeEach(() => {
cy.login()
})

const inviteEmail = `test-invite-${Math.round(Math.random() * 10000)}@gmail.com`

it('should be able to create an invitation', () => {
Expand Down
6 changes: 5 additions & 1 deletion cypress/e2e/t30-create-one-off-invoice.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
import { customerName } from '../support/reusableConstants'

describe('Create one-off', () => {
beforeEach(() => {
cy.login()
})

it('should create a one-off invoice with correct amounts', () => {
cy.visit('/customers')
cy.get(`[data-test="${customerName}"]`).click({ force: true })
Expand All @@ -18,7 +22,7 @@ describe('Create one-off', () => {
cy.get('[data-option-index="0"]').click({ force: true })
cy.get('[data-test="invoice-item"]').should('have.length', 1)

// // Edit it's tax rate
// Edit it's tax rate
cy.get('[data-test="invoice-item-actions-button"]').click({ force: true })
cy.get('[data-test="invoice-item-edit-taxes"]').click({ force: true })
cy.get(`[data-test="add-tax-button"]`).click({ force: true })
Expand Down
4 changes: 3 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// <reference types="cypress" />
import { userEmail, userPassword } from './reusableConstants'

// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
Expand Down Expand Up @@ -36,7 +38,7 @@
// }
// }

Cypress.Commands.add('login', (email: string, password: string) => {
Cypress.Commands.add('login', (email: string = userEmail, password: string = userPassword) => {
cy.visit('/login')
cy.get('input[name="email"]').type(email)
cy.get('input[name="password"]').type(password)
Expand Down
19 changes: 0 additions & 19 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@ import './commands'
import { userEmail, userPassword } from './reusableConstants'

beforeEach(() => {
const { currentTest } = Cypress.mocha.getRunner().suite.ctx

if (
// Prevent to log for all "auth" test suite
!currentTest.invocationDetails.relativeFile.includes('auth') &&
// In case we ever need to skip login before one test, add '::preventLogin' in the test name
!currentTest.title.includes('::preventLogin')
) {
cy.session(
'LoginTestUser',
() => {
cy.login(userEmail, userPassword)
},
{
cacheAcrossSpecs: true,
},
)
}

// Allow access to broswer's clipboard api
Cypress.automation('remote:debugger:protocol', {
command: 'Browser.grantPermissions',
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare namespace Cypress {
* @example
* cy.login('[email protected]', 'P@ssw0rd')
*/
login(email: string, password: string): Chainable<unknown>
login(email?: string, password?: string): Chainable<unknown>
}

interface Cypress {
Expand Down

0 comments on commit c521ddd

Please sign in to comment.