From ba89b35f67e7e38c9c13b8870974534bd2dc3bcd Mon Sep 17 00:00:00 2001 From: Pettedson John Date: Mon, 29 Apr 2024 16:45:58 +0100 Subject: [PATCH] chore: add refactored files for updated reference --- functional-test/fixtures/steps/note.ts | 11 +++++--- functional-test/helpers/dataSetUpHelper.ts | 13 ++++----- functional-test/lib/webActions.ts | 20 +++++++++++--- functional-test/pages/addNotePage.ts | 32 +++++++++++++--------- functional-test/pages/homePage.ts | 16 +++++------ 5 files changed, 54 insertions(+), 38 deletions(-) diff --git a/functional-test/fixtures/steps/note.ts b/functional-test/fixtures/steps/note.ts index 514c6485b6..80587bc5a9 100644 --- a/functional-test/fixtures/steps/note.ts +++ b/functional-test/fixtures/steps/note.ts @@ -2,7 +2,7 @@ import { expect, Locator, Page } from '@playwright/test'; import { HomePage } from '../../pages/homePage'; import { AddNotePage } from '../../pages/addNotePage'; import { LoginPage } from '../../pages/loginPage'; -import setUpData from "../../helpers/dataSetUpHelper"; +import createCaseBasedOnCaseType from "../../helpers/dataSetUpHelper"; const addNoteTestConfig = require('../../data/uiJsonTestData/add-note.json'); const eventTestConfig = require('../../data/uiJsonTestData/event-name.json'); @@ -21,17 +21,20 @@ export class Note { let homePage = new HomePage(this.page); let addNotePage = new AddNotePage(this.page); - var pipCaseId = await setUpData("PIP"); + var pipCaseId = await createCaseBasedOnCaseType("PIP"); await loginPage.goToLoginPage(); await loginPage.verifySuccessfulLoginForCaseworker('Case list'); await homePage.goToHomePage(pipCaseId); await homePage.chooseEvent(eventTestConfig.addNoteEvent); - await addNotePage.submitNote(addNoteTestConfig.noteSummaryValue); + + await addNotePage.verifyPageContent(); + await addNotePage.inputData(addNoteTestConfig.noteSummaryValue); + await addNotePage.confirmSubmission(); await addNotePage.confirmSubmission(); await homePage.verifyTabContent(addNoteTestConfig.noteFieldValue, addNoteTestConfig.noteSummaryValue); } -} \ No newline at end of file +} diff --git a/functional-test/helpers/dataSetUpHelper.ts b/functional-test/helpers/dataSetUpHelper.ts index 92bd3f1f82..47d71e0618 100644 --- a/functional-test/helpers/dataSetUpHelper.ts +++ b/functional-test/helpers/dataSetUpHelper.ts @@ -15,17 +15,16 @@ import piprepFtoFSandLPayload from '../data/apiJsonTestData/pip_sandl_rep_ftof.j import piprepSandLPayload from '../data/apiJsonTestData/pip_sandl_rep.json'; -async function setUpData(caseType: string) { +async function createCaseBasedOnCaseType(caseType: string) { let apiContext; let dataPayload; - // create new test data + + //Formulate API Context For Request,wrapping the Request Endpoint apiContext = await request.newContext({ - // All requests we send go to this API endpoint. + // All requests we send go to this API Endpoint. baseURL: urls.tribunalsApiUri, }); - console.log('creating new test data...'); - dataPayload = caseType == "PIP" ? pipPayload @@ -57,8 +56,6 @@ async function setUpData(caseType: string) { let caseId = locationUrl.substring(locationUrl.lastIndexOf('/') + 1); console.log(`Case id is ${caseId}`); return caseId; - - } -export default setUpData; +export default createCaseBasedOnCaseType; diff --git a/functional-test/lib/webActions.ts b/functional-test/lib/webActions.ts index f5629989cc..ae551f5e4e 100644 --- a/functional-test/lib/webActions.ts +++ b/functional-test/lib/webActions.ts @@ -8,11 +8,23 @@ export class WebActions { this.page = page; } - async chooseOptionByLabel(elementId: string, labelText: string) { - this.page.locator(elementId).selectOption({label: labelText}); + async chooseOptionByLabel(elementLocator: string, labelText: string) { + await this.page.locator(elementLocator).selectOption({label: labelText}); + } + + async verifyPageLabel(elementLocator: string, labelText: string) { + await expect(this.page.locator(elementLocator)).toHaveText(labelText); + } + + async inputField (elementLocator: string, inputValue: string) { + await this.page.fill(elementLocator, inputValue); + } + + async clickButton(elementLocator: string): Promise { + await this.page.click(elementLocator); } async clickNextStepButton(elementId: string): Promise { - this.page.click(elementId); + await this.page.click(elementId); } -} \ No newline at end of file +} diff --git a/functional-test/pages/addNotePage.ts b/functional-test/pages/addNotePage.ts index 587be4e710..b838338e37 100644 --- a/functional-test/pages/addNotePage.ts +++ b/functional-test/pages/addNotePage.ts @@ -1,5 +1,5 @@ -import { expect, Locator, Page } from '@playwright/test'; -import { WebActions } from '../lib/webActions' +import {expect, Locator, Page} from '@playwright/test'; +import {WebActions} from '../lib/webActions' let webActions: WebActions; @@ -8,24 +8,30 @@ export class AddNotePage { readonly page: Page; readonly textDetailsField: Locator; readonly submitButton: Locator; - - + + constructor(page: Page) { this.page = page; - this.textDetailsField = page.locator('#tempNoteDetail'); - this.submitButton = page.getByRole('button', {name: 'Submit'}); - + /*this.textDetailsField = page.locator('#tempNoteDetail'); + this.submitButton = page.getByRole('button', {name: 'Submit'});*/ + webActions = new WebActions(this.page); } - async submitNote(noteSummary: string): Promise { - await this.textDetailsField.fill(noteSummary); - await this.submitButton.click(); + async verifyPageContent() { + await webActions.verifyPageLabel('.govuk-caption-l', 'Add a note'); //Captor Text + await webActions.verifyPageLabel('.govuk-heading-l', 'Add a case note'); //Heading Text + await webActions.verifyPageLabel('.form-label', 'Enter note'); //Field Label + } + +x + async inputData(elementData: string): Promise { + await webActions.inputField('#tempNoteDetail', elementData); } async confirmSubmission(): Promise { - await this.submitButton.click(); + await webActions.clickButton('[type=\'submit\']'); } - -} \ No newline at end of file + +} diff --git a/functional-test/pages/homePage.ts b/functional-test/pages/homePage.ts index 93c91557e6..4de85fc855 100644 --- a/functional-test/pages/homePage.ts +++ b/functional-test/pages/homePage.ts @@ -1,5 +1,5 @@ -import { expect, Locator, Page } from '@playwright/test'; -import { WebActions } from '../lib/webActions' +import {expect, Locator, Page} from '@playwright/test'; +import {WebActions} from '../lib/webActions' let webActions: WebActions; @@ -11,8 +11,8 @@ export class HomePage { readonly submitNextStepButton: string; readonly nextStepDropDown: string; readonly eventTitle: Locator; - - + + constructor(page: Page) { this.page = page; this.summaryTab = page.locator('//div[contains(text(), "Summary")]'); @@ -40,10 +40,8 @@ export class HomePage { async verifyTabContent(fieldLabel: string, fieldValue: string): Promise { await expect(this.notePadTab).toBeVisible(); await this.notePadTab.click(); - let noteSummaryField = await this.page - .locator(`//*[normalize-space()="${fieldLabel}"]/../..//td[normalize-space()="${fieldValue}"]`); + await expect(this.page + .locator(`//*[normalize-space()="${fieldLabel}"]/../..//td[normalize-space()="${fieldValue}"]`)).toBeVisible(); - await expect(noteSummaryField).toBeVisible(); } - -} \ No newline at end of file +}