From 98fe52efad25349c39c4e50d6544938e46a19e09 Mon Sep 17 00:00:00 2001 From: Elaine Krauss Date: Fri, 6 Sep 2024 12:25:35 -0400 Subject: [PATCH 1/4] Fixes race condition in checking the values of input fields --- .../reports-f24-independent-expenditures.cy.ts | 8 ++++---- front-end/cypress/e2e/F3X/disbursements.cy.ts | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/front-end/cypress/e2e/F24/reports-f24-independent-expenditures.cy.ts b/front-end/cypress/e2e/F24/reports-f24-independent-expenditures.cy.ts index af77c5a270..dc304cd7ee 100644 --- a/front-end/cypress/e2e/F24/reports-f24-independent-expenditures.cy.ts +++ b/front-end/cypress/e2e/F24/reports-f24-independent-expenditures.cy.ts @@ -48,13 +48,13 @@ describe('Form 24 Independent Expenditures', () => { PageUtils.clickButton('Save'); PageUtils.clickLink('Independent Expenditure'); - cy.contains(individualContactFormData.first_name).should('exist'); - cy.contains(individualContactFormData.last_name).should('exist'); + cy.get('#first_name').should('have.value', individualContactFormData.first_name); + cy.get('#last_name').should('have.value', individualContactFormData.last_name); ReportListPage.editReport('12-DAY PRE-GENERAL'); PageUtils.clickSidebarItem('Manage your transactions'); PageUtils.clickLink('Independent Expenditure'); - cy.contains(individualContactFormData.first_name).should('exist'); - cy.contains(individualContactFormData.last_name).should('exist'); + cy.get('#first_name').should('have.value', individualContactFormData.first_name); + cy.get('#last_name').should('have.value', individualContactFormData.last_name); }); }); diff --git a/front-end/cypress/e2e/F3X/disbursements.cy.ts b/front-end/cypress/e2e/F3X/disbursements.cy.ts index 7a1c2ef892..9c28594f73 100644 --- a/front-end/cypress/e2e/F3X/disbursements.cy.ts +++ b/front-end/cypress/e2e/F3X/disbursements.cy.ts @@ -48,9 +48,11 @@ describe('Disbursements', () => { TransactionDetailPage.enterScheduleFormData(defaultTransactionFormData); PageUtils.clickButton('Save'); + cy.contains('Transactions in this report').should('exist'); PageUtils.clickLink('100% Federal Election Activity Payment'); - cy.contains(individualContactFormData.first_name).should('exist'); - cy.contains(individualContactFormData.last_name).should('exist'); + cy.contains('Address').should('exist'); + cy.get('#last_name').should('have.value', individualContactFormData.last_name); + cy.get('#first_name').should('have.value', individualContactFormData.first_name); }); it('should test Independent Expenditure - Void Schedule E disbursement', () => { @@ -67,7 +69,8 @@ describe('Disbursements', () => { PageUtils.clickButton('Save'); PageUtils.clickLink('Independent Expenditure - Void'); - cy.contains(organizationFormData.name).should('exist'); + cy.contains('Address').should('exist'); + cy.get('#organization_name').should('have.value', organizationFormData.name); }); it('should be able to link an Independent Expenditure to a Form 24', () => { @@ -85,8 +88,8 @@ describe('Disbursements', () => { PageUtils.clickButton('Save'); PageUtils.clickLink('Independent Expenditure'); - cy.contains(individualContactFormData.first_name).should('exist'); - cy.contains(individualContactFormData.last_name).should('exist'); + cy.get('#first_name').should('have.value', individualContactFormData.first_name); + cy.get('#last_name').should('have.value', individualContactFormData.last_name); PageUtils.clickSidebarItem('Manage your transactions'); PageUtils.getKabob('Independent Expenditure').click(); @@ -98,8 +101,8 @@ describe('Disbursements', () => { ReportListPage.editReport('FORM 24'); PageUtils.clickLink('Independent Expenditure'); - cy.contains(individualContactFormData.first_name).should('exist'); - cy.contains(individualContactFormData.last_name).should('exist'); + cy.get('#first_name').should('have.value', individualContactFormData.first_name); + cy.get('#last_name').should('have.value', individualContactFormData.last_name); }); it('Create an Other Disbursement transaction', () => { From 351ff5c38f9ab940292937b722fc8e41d001e865 Mon Sep 17 00:00:00 2001 From: Elaine Krauss Date: Mon, 9 Sep 2024 15:50:55 -0400 Subject: [PATCH 2/4] Adds checks that ensure that new pages have loaded --- .../cypress/e2e/F24/reports-f24-independent-expenditures.cy.ts | 2 ++ front-end/cypress/e2e/F3X/disbursements.cy.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/front-end/cypress/e2e/F24/reports-f24-independent-expenditures.cy.ts b/front-end/cypress/e2e/F24/reports-f24-independent-expenditures.cy.ts index dc304cd7ee..e3fcde422c 100644 --- a/front-end/cypress/e2e/F24/reports-f24-independent-expenditures.cy.ts +++ b/front-end/cypress/e2e/F24/reports-f24-independent-expenditures.cy.ts @@ -48,12 +48,14 @@ describe('Form 24 Independent Expenditures', () => { PageUtils.clickButton('Save'); PageUtils.clickLink('Independent Expenditure'); + cy.contains('Address').should('exist'); cy.get('#first_name').should('have.value', individualContactFormData.first_name); cy.get('#last_name').should('have.value', individualContactFormData.last_name); ReportListPage.editReport('12-DAY PRE-GENERAL'); PageUtils.clickSidebarItem('Manage your transactions'); PageUtils.clickLink('Independent Expenditure'); + cy.contains('Address').should('exist'); cy.get('#first_name').should('have.value', individualContactFormData.first_name); cy.get('#last_name').should('have.value', individualContactFormData.last_name); }); diff --git a/front-end/cypress/e2e/F3X/disbursements.cy.ts b/front-end/cypress/e2e/F3X/disbursements.cy.ts index 9c28594f73..821ec956ec 100644 --- a/front-end/cypress/e2e/F3X/disbursements.cy.ts +++ b/front-end/cypress/e2e/F3X/disbursements.cy.ts @@ -88,6 +88,7 @@ describe('Disbursements', () => { PageUtils.clickButton('Save'); PageUtils.clickLink('Independent Expenditure'); + cy.contains('Address').should('exist'); cy.get('#first_name').should('have.value', individualContactFormData.first_name); cy.get('#last_name').should('have.value', individualContactFormData.last_name); PageUtils.clickSidebarItem('Manage your transactions'); @@ -101,6 +102,7 @@ describe('Disbursements', () => { ReportListPage.editReport('FORM 24'); PageUtils.clickLink('Independent Expenditure'); + cy.contains('Address').should('exist'); cy.get('#first_name').should('have.value', individualContactFormData.first_name); cy.get('#last_name').should('have.value', individualContactFormData.last_name); }); From 33e3dcdb91b41681bcb3f3a0459fcf4c5cf40d0b Mon Sep 17 00:00:00 2001 From: Elaine Krauss Date: Mon, 9 Sep 2024 16:06:59 -0400 Subject: [PATCH 3/4] Updates README with tips on writing tests --- front-end/cypress/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/front-end/cypress/README.md b/front-end/cypress/README.md index 8d9c0afbb8..b75c2e4b02 100644 --- a/front-end/cypress/README.md +++ b/front-end/cypress/README.md @@ -67,3 +67,7 @@ export CYPRESS_COMMITTEE_ID='' export CYPRESS_PASSWORD='' sudo circleci local execute -e CIRCLE_BRANCH=${CIRCLE_BRANCH} -e E2E_DJANGO_SECRET_KEY=${E2E_DJANGO_SECRET_KEY} -e E2E_DATABASE_URL=${E2E_DATABASE_URL} -e CYPRESS_EMAIL=${CYPRESS_EMAIL} -e CYPRESS_COMMITTEE_ID=${CYPRESS_COMMITTEE_ID} -e CYPRESS_PASSWORD=${CYPRESS_PASSWORD} --job e2e-test ``` + +## Tips for Writing E2E Tests +- Assertions made immediately after a page load will sometimes check the previous page before the new page loads. Add checks to ensure that the new page has loaded where possible. +- The `.contains()` Cypress method cannot find the value of a text input field. For assertions, you can instead use the `.should('have.value', VALUE)` method. From e3db8026c90adba24049adc2b843dd4e80a0b3ad Mon Sep 17 00:00:00 2001 From: toddlees Date: Tue, 10 Sep 2024 16:34:20 -0400 Subject: [PATCH 4/4] lint --- front-end/cypress/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/front-end/cypress/README.md b/front-end/cypress/README.md index b75c2e4b02..35315a9593 100644 --- a/front-end/cypress/README.md +++ b/front-end/cypress/README.md @@ -69,5 +69,6 @@ sudo circleci local execute -e CIRCLE_BRANCH=${CIRCLE_BRANCH} -e E2E_DJANGO_SECR ``` ## Tips for Writing E2E Tests -- Assertions made immediately after a page load will sometimes check the previous page before the new page loads. Add checks to ensure that the new page has loaded where possible. -- The `.contains()` Cypress method cannot find the value of a text input field. For assertions, you can instead use the `.should('have.value', VALUE)` method. + +- Assertions made immediately after a page load will sometimes check the previous page before the new page loads. Add checks to ensure that the new page has loaded where possible. +- The `.contains()` Cypress method cannot find the value of a text input field. For assertions, you can instead use the `.should('have.value', VALUE)` method.