diff --git a/playwright-local/tests/submit/validFormSubmission.spec.js b/playwright-local/tests/submit/validFormSubmission.spec.js index 626103f2..9650167a 100644 --- a/playwright-local/tests/submit/validFormSubmission.spec.js +++ b/playwright-local/tests/submit/validFormSubmission.spec.js @@ -8,19 +8,24 @@ test('Valid giftaid submission', async ({ page }) => { await page.goto('/', { timeout: 30000 }); await page.waitForLoadState('domcontentloaded'); - - // Ensure the transaction ID input is visible - await expect(page.locator('input#field-input--transactionId')).toBeVisible(); - - // Populate all input fields with valid data - await commands.populateUpdateFormFields(page); - - // Select 'Yes' for GiftAid declaration - await page.locator('#giftAidClaimChoice>div:nth-child(2)>label').click(); - - // Submit the form and validate the thank you message - await page.locator('button[type=submit]').click(); - await expect(page.locator('div > h1')).toContainText('Thank you, test!'); + + // Click the Giftaid checkbox + await page.click('#field-label--giftaid'); + + // Populate all the form fields with valid inputs + await commands.populateFormFields(page); + + // Select marketing preferences as required + await commands.selectMarketingPrefs(page); + + // Submit the form and wait for the navigation to ensure the submission goes through + await Promise.all([ + page.waitForNavigation(), // This ensures that the navigation happens before the check + page.click('button[type=submit]') + ]); + + // Check for the thank you message to confirm successful submission + await expect(page.locator('div > h1')).toHaveText('Thank you, test!'); await page.close(); }); diff --git a/playwright-local/tests/update/formValidation.spec.js b/playwright-local/tests/update/formValidation.spec.js index c29d1f95..ee81f8ef 100644 --- a/playwright-local/tests/update/formValidation.spec.js +++ b/playwright-local/tests/update/formValidation.spec.js @@ -2,13 +2,16 @@ const { test, expect } = require('@playwright/test'); const { Commands } = require('../utils/commands'); const { v4: uuidv4 } = require('uuid'); -const transactionId = uuidv4(); +const Chance = require('chance'); +const chance = new Chance(); test.describe('Giftaid update form validation', () => { + let transactionId; test.beforeEach(async ({ page }) => { + transactionId = uuidv4(); // Ensure unique transaction ID for each test + await page.goto('/update', { timeout: 30000 }); - await page.waitForLoadState('domcontentloaded'); });