|
1 | 1 | // @ts-check |
2 | 2 | const { expect } = require('@playwright/test'); |
3 | 3 | const { test } = require('../../browserstack'); |
| 4 | +const { selectors } = require('../utils/locators'); |
4 | 5 |
|
5 | 6 | test.describe('Address validation @sanity @nightly-sanity', () => { |
6 | 7 |
|
7 | 8 | test.beforeEach(async ({ page }) => { |
8 | 9 | // Navigate to the giftaid page |
9 | 10 | await page.goto(process.env.BASE_URL, { timeout: 30000 }); |
10 | 11 | await page.waitForLoadState('domcontentloaded'); |
11 | | - await page.locator('#field-label--giftaid').click(); |
12 | | - await page.locator('#field-input--mobile').fill('07123456789'); |
13 | | - await page.locator('input#field-input--firstname').fill('test'); |
14 | | - await page.locator('input#field-input--lastname').fill('user'); |
| 12 | + await page.locator(selectors.giftaid.option).click(); |
| 13 | + await page.locator(selectors.formFields.mobile).fill('07123456789'); |
| 14 | + await page.locator(selectors.formFields.firstName).fill('test'); |
| 15 | + await page.locator(selectors.formFields.lastName).fill('user'); |
15 | 16 | }); |
16 | 17 |
|
17 | 18 | test('empty postcode should show error message', async ({ page }) => { |
18 | | - await page.locator('input#field-input--postcode').fill(''); |
19 | | - await page.locator('button[type=submit]').click(); |
20 | | - await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter your postcode'); |
| 19 | + await page.locator(selectors.formFields.postcode).fill(''); |
| 20 | + await page.locator(selectors.formFields.submitButton).click(); |
| 21 | + await expect(page.locator(selectors.errorMessages.postcode)).toHaveText('Please enter your postcode'); |
21 | 22 | await page.close(); |
22 | 23 | }); |
23 | 24 |
|
24 | 25 | test('invalid postcodes should show error messages', async ({ page }) => { |
25 | | - await page.locator('input#field-input--postcode').fill('12SE17TP'); |
26 | | - await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.'); |
27 | | - await page.locator('input#field-input--postcode').fill('comic relief'); |
28 | | - await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.'); |
29 | | - await page.locator('input#field-input--postcode').fill('cro 7tp'); |
30 | | - await expect(page.locator('div#field-error--postcode > span')).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.'); |
| 26 | + await page.locator(selectors.formFields.postcode).fill('12SE17TP'); |
| 27 | + await expect(page.locator(selectors.errorMessages.postcode)).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.'); |
| 28 | + |
| 29 | + await page.locator(selectors.formFields.postcode).fill('comic relief'); |
| 30 | + await expect(page.locator(selectors.errorMessages.postcode)).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.'); |
| 31 | + |
| 32 | + await page.locator(selectors.formFields.postcode).fill('cro 7tp'); |
| 33 | + await expect(page.locator(selectors.errorMessages.postcode)).toHaveText('Please enter a valid UK postcode, using a space. For non-UK addresses, please use manual entry below.'); |
| 34 | + |
31 | 35 | await page.close(); |
32 | 36 | }); |
33 | 37 |
|
34 | 38 | test('enter postcode but submit without selecting address should show error message', async ({ page }) => { |
35 | | - await page.locator('input#field-input--postcode').fill('SE1 7TP'); |
36 | | - await page.locator('#postcode_button').click(); |
37 | | - await expect(page.locator('#field-select--addressSelect')).toBeVisible(); |
38 | | - await page.locator('button[type=submit]').click(); |
39 | | - await expect(page.locator('div#field-error--addressSelect > span')).toHaveText('Please select your address'); |
| 39 | + await page.locator(selectors.formFields.postcode).fill('SE1 7TP'); |
| 40 | + await page.locator(selectors.formFields.postcodeLookup).click(); |
| 41 | + await expect(page.locator(selectors.address.addressSelect)).toBeVisible(); |
| 42 | + |
| 43 | + await page.locator(selectors.formFields.submitButton).click(); |
| 44 | + await expect(page.locator(selectors.errorMessages.addressSelect)).toHaveText('Please select your address'); |
| 45 | + |
40 | 46 | await page.close(); |
41 | 47 | }); |
42 | 48 |
|
43 | 49 | test('clicking on manual address link should show address fields', async ({ page }) => { |
44 | | - await page.locator('input#field-input--postcode').fill('SE1 7TP'); |
45 | | - await expect(page.locator('a[aria-describedby=field-error--addressDetails]')).toBeVisible(); |
46 | | - await page.locator('a[aria-describedby=field-error--addressDetails]').click(); |
47 | | - await expect(page.locator('#field-input--address1')).toBeVisible(); |
48 | | - await expect(page.locator('#field-input--address2')).toBeVisible(); |
49 | | - await expect(page.locator('#field-input--address3')).toBeVisible(); |
50 | | - await expect(page.locator('#field-input--town')).toBeVisible(); |
51 | | - await expect(page.locator('select#field-select--country')).toBeVisible(); |
| 50 | + await page.locator(selectors.formFields.postcode).fill('SE1 7TP'); |
| 51 | + await expect(page.locator(selectors.address.manualAddressLink)).toBeVisible(); |
| 52 | + |
| 53 | + await page.locator(selectors.address.manualAddressLink).click(); |
| 54 | + await expect(page.locator(selectors.address.address1)).toBeVisible(); |
| 55 | + await expect(page.locator(selectors.address.address2)).toBeVisible(); |
| 56 | + await expect(page.locator(selectors.address.address3)).toBeVisible(); |
| 57 | + await expect(page.locator(selectors.address.town)).toBeVisible(); |
| 58 | + await expect(page.locator(selectors.address.country)).toBeVisible(); |
| 59 | + |
52 | 60 | await page.close(); |
53 | 61 | }); |
54 | 62 |
|
55 | 63 | test('validate address fields', async ({ page }) => { |
56 | | - await page.locator('input#field-input--postcode').fill('SE1 7TP'); |
57 | | - await page.locator('a[aria-describedby=field-error--addressDetails]').click(); |
58 | | - |
| 64 | + await page.locator(selectors.formFields.postcode).fill('SE1 7TP'); |
| 65 | + await page.locator(selectors.address.manualAddressLink).click(); |
| 66 | + |
59 | 67 | // Should see error message for address1 when inout with special characters is entered |
60 | | - await page.locator('#field-input--address1').fill('@£%3dComic Relief'); |
61 | | - await expect(page.locator('#field-error--address1 > span')).toHaveText("This field only accepts alphanumeric characters and ' . - & _ /"); |
62 | | - await page.locator('#field-input--town').fill(' Comic Relief'); |
63 | | - await expect(page.locator('#field-error--town > span')).toHaveText("This field only accepts alphanumeric characters and ' . - & _ /"); |
64 | | - |
| 68 | + await page.locator(selectors.address.address1).fill('@£%3dComic Relief'); |
| 69 | + await expect(page.locator(selectors.errorMessages.address1)).toHaveText("This field only accepts alphanumeric characters and ' . - & _ /"); |
| 70 | + |
| 71 | + await page.locator(selectors.address.town).fill(' Comic Relief'); |
| 72 | + await expect(page.locator(selectors.errorMessages.town)).toHaveText("This field only accepts alphanumeric characters and ' . - & _ /"); |
| 73 | + |
65 | 74 | await page.close(); |
66 | 75 | }); |
67 | 76 | }); |
0 commit comments