Skip to content

Commit

Permalink
Merge pull request #1574 from hmcts/ADOP-2505-new
Browse files Browse the repository at this point in the history
ADOP-2505: Improve playwright smoke test
  • Loading branch information
abigailsmith97 authored Jul 31, 2024
2 parents fae66f7 + 6979613 commit f10db8a
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 37 deletions.
84 changes: 84 additions & 0 deletions playwright-e2e/pages/app.page.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { faker } from '@faker-js/faker';
import { type Page } from '@playwright/test';

import AdoptionAgency from './adoptionAgency.page';
Expand Down Expand Up @@ -46,4 +47,87 @@ export default class App {
this.reviewSubmit = new ReviewSubmit(page);
this.pcq = new Pcq(page);
}

async childMoveIn(): Promise<void> {
await this.tasklist.dateChildMovedIn.click();
await this.dateChildMoved.dateChildMovedInToday();
await this.basePage.clickSaveAndContinue();
}

async applicantOneNameCreate(): Promise<{ appOneFirstName: string; appOneLastName: string; appOneFullname: string }> {
const appOneFirstName = faker.person.firstName();
const appOneLastName = faker.person.lastName();
const appOneFullname = appOneFirstName + ' ' + appOneLastName;

return { appOneFirstName, appOneLastName, appOneFullname };
}

async childNameCreate(): Promise<{
prevChildFirstName: string;
prevChildLastName: string;
newChildFirstName: string;
newChildLastName: string;
}> {
const prevChildFirstName = faker.person.firstName();
const prevChildLastName = faker.person.lastName();
const newChildFirstName = faker.person.firstName();
const newChildLastName = faker.person.lastName();
return { prevChildFirstName, prevChildLastName, newChildFirstName, newChildLastName };
}

async fillChildDetails(
prevChildFirstName: string,
prevChildLastName: string,
newChildFirstName: string,
newChildLastName: string
): Promise<void> {
await this.tasklist.childsDetails.click();
await this.basePage.fillFirstLastName(prevChildFirstName, prevChildLastName);
await this.basePage.clickSaveAndContinue();

// Child's details after adoption
await this.basePage.fillFirstLastName(newChildFirstName, newChildLastName);
await this.basePage.clickSaveAndContinue();
await this.childDetails.childsDob();
await this.basePage.clickSaveAndContinue();
}

async fillSocialWorkerLocation1(socialWorkLocation1: string): Promise<void> {
await this.tasklist.adoptionAgency.click();
await this.adoptionAgency.childsChildSocialWorkerDetails(socialWorkLocation1);
await this.basePage.saveAndContinue.click();
await this.adoptionAgency.childsYourSocialWorkerDetails(socialWorkLocation1);
await this.basePage.saveAndContinue.click();
await this.adoptionAgency.anotherAdoptionAgencyNo();
await this.basePage.saveAndContinue.click();
}

async fillFamilyCourtLocation(familyCourtLocation: string): Promise<void> {
await this.tasklist.familyCourtDetails.click();
await this.basePage.selectLocation(familyCourtLocation);
await this.basePage.clickSaveAndContinue();
await this.familyCourt.sameCourtYes();
await this.basePage.clickSaveAndContinue();
}
// function used to fill applicant details
async fillPersonalDetails(): Promise<void> {
await this.basePage.clickSaveAndContinue();
await this.addApplicants.otherNamesSelectNo();
await this.basePage.clickSaveAndContinue();
await this.addApplicants.dob();
await this.basePage.clickSaveAndContinue();
await this.addApplicants.addOccupationFirst();
await this.basePage.clickSaveAndContinue();
await this.extraSupport.noSupportNeeded();
await this.basePage.clickSaveAndContinue();
}

async fillContactDetails(postcode1: string, telephone1: string): Promise<void> {
await this.basePage.postcodeFindAddress(postcode1, '0');
await this.basePage.clickSaveAndContinue();
await this.contactDetails.fillContactDetails('test@local.com', telephone1);
await this.basePage.clickSaveAndContinue();
await this.contactDetails.englishLang.check();
await this.basePage.clickSaveAndContinue();
}
}
6 changes: 3 additions & 3 deletions playwright-e2e/pages/applicantsDetails.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default class AddApplicants {

async dob(): Promise<void> {
const today = new Date();
const dayString = `${today.getDate()}`;
const monthString = `${today.getMonth()}`;
const yearString = `${today.getFullYear() - 21}`;
const dayString = String(today.getDate());
const monthString = String(today.getMonth() + 1); //getMonth() uses zero-based index so + 1 is needed to convert it to correct month for inputting in test
const yearString = String(today.getFullYear() - 21);

await this.dayField.fill(dayString);
await this.monthField.fill(monthString);
Expand Down
4 changes: 2 additions & 2 deletions playwright-e2e/pages/childDetails.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default class ChildDetails {

async childsDob(): Promise<void> {
const today = new Date();
const day = String(today.getDate()).padStart(2, '0');
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate());
const month = String(today.getMonth() + 1); //getMonth() uses zero-based index so + 1 is needed to convert it to correct month for inputting in test
const year = String(today.getFullYear() - 5);

await this.day.fill(day);
Expand Down
12 changes: 6 additions & 6 deletions playwright-e2e/pages/dateChildMoved.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export default class DateChildMoved {

async dateChildMovedInToday(): Promise<void> {
const today = new Date();
const day = String(today.getDate()).padStart(2, '0');
const month = String(today.getMonth() + 1).padStart(2, '0');
const year = String(today.getFullYear() - 1);
const dayMoveIn = String(today.getDate());
const monthMoveIn = String(today.getMonth() + 1); //getMonth() uses zero-based index so + 1 is needed to convert it to correct month for inputting in test
const yearMoveIn = String(today.getFullYear() - 1);

await this.day.fill(day);
await this.month.fill(month);
await this.year.fill(year);
await this.day.fill(dayMoveIn);
await this.month.fill(monthMoveIn);
await this.year.fill(yearMoveIn);
}
}
10 changes: 8 additions & 2 deletions playwright-e2e/pages/numberOfApplicants.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ export default class NumberOfApplicants {
);
}

async applyWithSpouseOrCivil(): Promise<void> {
await this.withSpouseCivilRadio.click();
async numberOfApplication(option: string): Promise<void> {
if (option === 'alone') {
await this.applyOnOwnRadio.click();
} else if (option === 'spouseOrCivilPartner') {
await this.withSpouseCivilRadio.click();
} else if (option === 'notSpouseOrCivilPartner') {
await this.withNotSpouseCivilRadio.click();
}
}
}
26 changes: 20 additions & 6 deletions playwright-e2e/pages/reviewSubmit.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ export default class ReviewSubmit extends BasePage {
readonly postcode: Locator;
readonly appEmail: Locator;
readonly confirmPaymentButton: Locator;
readonly applyOnOwn: Locator;

constructor(page: Page) {
super(page);
this.h1 = page.getByRole('heading', { name: 'Review your answers' });
this.applyWithSpouseText = page.getByText("I'm applying with my spouse");
this.applyOnOwn = page.getByText("I'm applying on my own");
this.firstApplicantTruthStatement = page.getByLabel('I, the first applicant,');
this.secondApplicantTruthStatment = page.getByLabel('I am authorised by the second');
this.appOneName = page.getByLabel('Enter your full name');
this.appTwoName = page.getByLabel("Enter the second applicant's");
this.confirmPay = page.getByRole('button', { name: 'Confirm and pay' });
this.paySubmit = page.getByRole('button', { name: 'Pay and submit application' });
this.cost = page.locator('#card-details-wrap').getByText(201.00');
this.cost = page.locator('#card-details-wrap').getByText('£');
this.cardDetailsH1 = page.getByRole('heading', { name: 'Enter card details' });
this.cardNumber = page.getByLabel('Card number');
this.expMonth = page.getByLabel('Month');
Expand All @@ -51,12 +53,24 @@ export default class ReviewSubmit extends BasePage {
this.confirmPaymentButton = page.getByRole('button', { name: 'Confirm payment' });
}

async reviewAnswers(): Promise<void> {
async reviewAnswers(applicantNumber: string): Promise<void> {
await expect(this.h1).toBeVisible();
await expect(this.applyWithSpouseText).toBeVisible();
if (applicantNumber === 'alone') {
await expect(this.applyOnOwn).toBeVisible();
} else if (applicantNumber === 'spouseOrCivilPartner') {
await expect(this.applyWithSpouseText).toBeVisible();
}
}
async statementOfTruthOne(applicantOne: string): Promise<void> {
await this.firstApplicantTruthStatement.check();
await this.appOneName.fill(applicantOne);
await this.confirmPay.click();
await this.paySubmit.click();
await expect(this.cardDetailsH1).toBeVisible();
await expect(this.cost).toBeVisible();
}

async statementOfTruth(applicantOne: string, applicantTwo: string): Promise<void> {
async statementOfTruthTwo(applicantOne: string, applicantTwo: string): Promise<void> {
await this.firstApplicantTruthStatement.check();
await this.secondApplicantTruthStatment.check();
await this.appOneName.fill(applicantOne);
Expand All @@ -67,7 +81,7 @@ export default class ReviewSubmit extends BasePage {
await expect(this.cost).toBeVisible();
}

async fillCardDetails(name: string, email: string): Promise<void> {
async fillCardDetails(name: string, email: string, postcode: string): Promise<void> {
const today = new Date();
await expect(this.cardDetailsH1).toBeVisible();
await expect(this.cost).toBeVisible();
Expand All @@ -78,7 +92,7 @@ export default class ReviewSubmit extends BasePage {
await this.securityCode.fill('123');
await this.addressLineOne.fill('55 HART READE');
await this.town.fill('POLEGATE');
await this.postcode.fill('BN26 6AL');
await this.postcode.fill(postcode);
await this.appEmail.fill(email);
await this.continueButton.click();
await this.confirmPaymentButton.click();
Expand Down
4 changes: 4 additions & 0 deletions playwright-e2e/pages/taskList.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default class Tasklist {
readonly secondApplicantPersonalDetails: Locator;
readonly secondApplicantContactDetails: Locator;
readonly reviewAndSubmit: Locator;
readonly yourPersonalDetails: Locator;
readonly yourContactDetails: Locator;

constructor(page: Page) {
this.heading = page.getByRole('heading', { name: 'Apply to adopt a child placed in your care' });
Expand All @@ -26,6 +28,8 @@ export default class Tasklist {
this.childsDetails = page.getByRole('link', { name: "Child's details" });
this.adoptionAgency = page.getByRole('link', { name: 'Adoption agency and social' });
this.familyCourtDetails = page.getByRole('link', { name: 'The family court details' });
this.yourPersonalDetails = page.getByRole('link', { name: 'Your personal details' });
this.yourContactDetails = page.getByRole('link', { name: 'Your contact details' });
this.firstApplicantPersonalDetails = page.getByRole('link', { name: 'Your personal details  First' });
this.firstApplicantContactDetails = page.getByRole('link', { name: 'Your contact details  First' });
this.secondApplicantPersonalDetails = page.getByRole('link', { name: 'Your personal details  Second' });
Expand Down
105 changes: 91 additions & 14 deletions playwright-e2e/tests/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,100 @@
import AxeBuilder from '@axe-core/playwright';
import { expect, test } from '@playwright/test';
import { test as base } from '@playwright/test';
import * as dotenv from 'dotenv';

import { urlConfig } from '../utils/urls';
import { runAccessibilityScan } from '../helpers/accessibilityHelper';
import { setupUser, teardownUser } from '../hooks/createDeleteUser.hook';
import App from '../pages/app.page';

test.describe('Adoption', () => {
test('should not have any automatically detectable accessibility issues @accessibility', async ({ page }) => {
await page.goto(`${urlConfig.citizenStartUrl}`);
dotenv.config();

const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22a', 'wcag22aa'])
.analyze();
const test = base.extend<{ makeAxeBuilder: () => AxeBuilder }>({
makeAxeBuilder: async ({ page }, use) => {
await use(() => new AxeBuilder({ page }));
},
});

test.describe('smoke test', () => {
let userEmail: string;
let userPassword: string;
let userId: string;

expect(accessibilityScanResults.violations).toEqual([]);
test.beforeEach(async () => {
const userInfo = await setupUser();
if (userInfo) {
userEmail = userInfo.email;
userPassword = userInfo.password;
userId = userInfo.id;
}
});
});

test('has title @smoke-test', async ({ page }) => {
await page.goto(`${urlConfig.citizenStartUrl}`);
test.afterEach('Status check', async () => {
await teardownUser(userId);
});

const smokeTestTags = { tag: ['@smoke', '@citizen', '@accessibility'] };
async function submitSingleApplicationJourney(
page,
makeAxeBuilder,
testInfo,
applicantNumber,
socialWorkLocation,
familyCourtLocation,
postcode1,
telephone1
) {
const app = new App(page);

const appOneName = await app.applicantOneNameCreate();
const childNames = await app.childNameCreate();

await app.signIn.signIn(userEmail, userPassword);
await app.numberOfApplicants.numberOfApplication(applicantNumber);
await app.basePage.clickSaveAndContinue();

await app.childMoveIn(); // Date child moved in with you

await app.fillChildDetails(
childNames.prevChildFirstName,
childNames.prevChildLastName,
childNames.newChildFirstName,
childNames.newChildLastName
); // Child's details before adoption

await app.fillSocialWorkerLocation1(socialWorkLocation); //fill social worker location
await app.fillFamilyCourtLocation(familyCourtLocation); // The family court details

// Fill personal details
await app.tasklist.yourPersonalDetails.click();
await app.fillPersonalDetails();
await app.tasklist.yourContactDetails.click();
await app.fillContactDetails(postcode1, telephone1);

// Submit
await app.tasklist.reviewAndSubmit.click();
await app.pcq.noPcqAnswers();
await app.reviewSubmit.reviewAnswers(applicantNumber);
await app.basePage.clickSaveAndContinue();
await app.reviewSubmit.statementOfTruthOne(appOneName.appOneFullname);
await app.reviewSubmit.fillCardDetails(appOneName.appOneFullname, userEmail, postcode1);

await runAccessibilityScan(makeAxeBuilder, testInfo); //Axe-core accessibility scan using helper function
}

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Apply for adoption - Apply to adopt a child placed in your care - GOV.UK/);
test(
'smoke test: single person submits an adoption application',
smokeTestTags,
async ({ page, makeAxeBuilder }, testInfo) => {
await submitSingleApplicationJourney(
page,
makeAxeBuilder,
testInfo,
'alone',
'Sandwell Metropolitan Council',
'Leicester County Court',
'BN26 6AL',
'0800800800'
);
}
);
});
8 changes: 4 additions & 4 deletions playwright-e2e/tests/submit-application-journey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test.describe('e2e submit journeys', () => {
const childFirstName = faker.person.firstName();
const childLastName = faker.person.lastName();
await app.signIn.signIn(userEmail, userPassword);
await app.numberOfApplicants.applyWithSpouseOrCivil();
await app.numberOfApplicants.numberOfApplication('spouseOrCivilPartner');
await app.basePage.clickSaveAndContinue();

// Date child moved in with you
Expand Down Expand Up @@ -129,10 +129,10 @@ test.describe('e2e submit journeys', () => {
//submit
await app.tasklist.reviewAndSubmit.click();
await app.pcq.noPcqAnswers();
await app.reviewSubmit.reviewAnswers();
await app.reviewSubmit.reviewAnswers('spouseOrCivilPartner');
await app.basePage.clickSaveAndContinue();
await app.reviewSubmit.statementOfTruth(appOneFullname, appTwoFullname);
await app.reviewSubmit.fillCardDetails(appOneFullname, 'abcdefg@domain.com');
await app.reviewSubmit.statementOfTruthTwo(appOneFullname, appTwoFullname);
await app.reviewSubmit.fillCardDetails(appOneFullname, 'abcdefg@domain.com', 'BN26 6AL');
await runAccessibilityScan(makeAxeBuilder, testInfo);
}
);
Expand Down

0 comments on commit f10db8a

Please sign in to comment.