Skip to content

Commit

Permalink
test: fix local tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KrupaPammi committed May 17, 2024
1 parent 36b0b6d commit 4beebaf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
const { test, expect } = require('@playwright/test');
const { Commands } = require('../utils/commands');

const Chance = require('chance');
const chance = new Chance();

const email = `giftaid-staging-${Date.now().toString()}@email.sls.comicrelief.com`;
const phone = chance.phone({ country: 'uk', mobile: true }).replace(/\s/g, '');

test.describe('Marketing preferences validation', () => {

test.beforeEach(async ({ page }) => {
Expand Down
150 changes: 61 additions & 89 deletions playwright-local/tests/utils/commands.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,82 @@
const faker = require('faker');
const { v4: uuidv4 } = require('uuid');
const transactionId = uuidv4();
const Chance = require('chance');
const chance = new Chance();

class Commands {
constructor(page) {
this.page = page;

// form inputs
this.transactionID = page.locator('input#field-input--transactionId');
this.mobile = page.locator('#field-input--mobile');
this.phone = page.locator('#field-input--phone');
this.firstName = page.locator('input#field-input--firstname');
this.lastName = page.locator('input#field-input--lastname');
this.email = page.locator('input#field-input--email');
this.postcode = page.locator('input#field-input--postcode');
this.submit = page.locator('button[type=submit]');

// enter address manually link
this.manualAddressLink = page.locator('a[aria-describedby=field-error--addressDetails]');
this.address1 = page.locator('input#field-input--address1');
this.address2 = page.locator('input#field-input--address2');
this.address3 = page.locator('input#field-input--address3');
this.town = page.locator('input#field-input--town');
this.country = page.locator('#field-select--country');

// marketing preferences
this.mpEmail = page.locator('#field-wrapper--Email > div');
this.mpPhone = page.locator('#field-wrapper--Phone > div');
//this.mpPost = page.locator('input#field-label--Post--Post');
this.mpSMS = page.locator('input#field-label--Text--SMS');
this.inputMPEmail = page.locator('input#field-input--email');
this.inputMPPhone = page.locator('input#field-input--phone');
this.transactionId = uuidv4();
}

/**
* Populate giftaid from fields
* @param userData
* @param page - Playwright page object.
* @param userData - Optional user data for form filling.
*/
async populateFormFields(
{
mobile = faker.phone.phoneNumber('078########'),
firstName = 'test',
lastName = 'user',
postcode = 'SE1 7TP',
address1 = 'COMIC RELIEF',
address2 = 'CAMELFORD HOUSE 87-90',
address3 = 'ALBERT EMBANKMENT',
town = 'London',
} = {},
) {
await this.mobile.type(mobile);
await this.firstName.type(firstName);
await this.lastName.type(lastName);
await this.postcode.type(postcode);
await this.manualAddressLink.click();
await this.address1.type(address1);
await this.address2.type(address2);
await this.address3.type(address3);
await this.town.type(town);
async populateFormFields(page, {
mobile = chance.phone({ country: 'uk', mobile: true }).replace(/\s/g, ''), // Remove spaces from the phone number
firstName = 'test',
lastName = chance.last(),
postcode = chance.postcode(),
address1 = chance.address(),
address2 = chance.street(),
address3 = 'test address 3',
town = chance.city(),
} = {}) {
await page.locator('#field-input--mobile').type(mobile);
await page.locator('input#field-input--firstname').type(firstName);
await page.locator('input#field-input--lastname').type(lastName);
await page.locator('input#field-input--postcode').type(postcode);
await page.locator('a[aria-describedby=field-error--addressDetails]').click();
await page.locator('input#field-input--address1').type(address1);
await page.locator('input#field-input--address2').type(address2);
await page.locator('input#field-input--address3').type(address3);
await page.locator('input#field-input--town').type(town);
}

/**
* Select marketing preferences opt ins
* @param page - Playwright page object.
* @param options - Optional marketing preferences.
*/
async selectMarketingPrefs(
{
email = '[email protected]',
phone = faker.phone.phoneNumber('0208#######'),
} = {},
) {
await this.mpEmail.click();
await this.inputMPEmail.type(email);
// await this.mpPost.click();
await this.mpPhone.click();
await this.inputMPPhone.type(phone, { delay: 200 });
await this.mpSMS.click();
async selectMarketingPrefs(page, {
email = `giftaid-staging-${chance.email()}`,
phone = chance.phone({ country: 'uk', mobile: false }).replace(/\s/g, '') // UK phone number
} = {}) {
await page.locator('#field-wrapper--Email > div').click();
await page.locator('input#field-input--email').type(email);
await page.locator('#field-wrapper--Phone > div').click();
await page.locator('input#field-input--phone').type(phone, { delay: 200 });
await page.locator('input#field-label--Text--SMS').click();
}

/**
* Populate giftaid update from fields
* @param userData
* @param page - Playwright page object.
* @param userData - Optional user data for form filling.
*/
async populateUpdateFormFields(
{
transactionID = transactionId,
firstName = 'test',
lastName = 'user',
email = '[email protected]',
postcode = 'SE1 7TP',
address1 = 'COMIC RELIEF',
address2 = 'CAMELFORD HOUSE 87-90',
address3 = 'ALBERT EMBANKMENT',
town = 'London',
} = {},
) {
await this.transactionID.type(transactionID);
async populateUpdateFormFields(page, {
transactionID = this.transactionId,
firstName = 'test',
lastName = chance.last(),
email = `giftaid-update-staging-${chance.email()}`,
postcode = chance.postcode(),
address1 = chance.address(),
address2 = chance.street(),
address3 = 'test address 3',
town = chance.city(),
} = {}) {
await page.locator('input#field-input--transactionId').fill(transactionID);
console.log('transactionId is:', transactionID);
await this.firstName.type(firstName);
await this.lastName.type(lastName);
await this.postcode.type(postcode);
await this.email.type(email);
await this.manualAddressLink.click();
await this.address1.type(address1);
await this.address2.type(address2);
await this.address3.type(address3);
await this.town.type(town);
await page.locator('input#field-input--firstname').fill(firstName);
await page.locator('input#field-input--lastname').fill(lastName);
await page.locator('input#field-input--postcode').fill(postcode);
await page.locator('input#field-input--email').fill(email);
await page.locator('a[aria-describedby=field-error--addressDetails]').click();
await page.locator('input#field-input--address1').fill(address1);
await page.locator('input#field-input--address2').fill(address2);
await page.locator('input#field-input--address3').fill(address3);
await page.locator('input#field-input--town').fill(town);
}
}

Expand Down

0 comments on commit 4beebaf

Please sign in to comment.