Sets up the core infrastructure for Playwright-based automated testing, including: - Docker support for consistent environments - Azure Pipelines configuration for CI/CD - Page Object Model structure for maintainable tests - Test data, validation, and rule engine implementation - Test configuration for alerts and other scenarios
69 lines
2.7 KiB
TypeScript
69 lines
2.7 KiB
TypeScript
import { expect, type Locator, type Page } from '@playwright/test';
|
|
import { BasePage } from './BasePage';
|
|
import { IPartQuestion } from '@business-logic/types/CustomerDetails';
|
|
import { step } from '@business-logic/types/Step';
|
|
import { ITestData } from '@business-logic/types/ITestData';
|
|
|
|
export class PartQuestionsPage extends BasePage {
|
|
readonly page: Page;
|
|
url = process.env['BASE_URL']! + '/fmg/?fmgPage=part-questions';
|
|
|
|
constructor(page: Page) {
|
|
super(page);
|
|
this.page = page;
|
|
}
|
|
|
|
async getLocalStorage() {
|
|
// Retrieve local storage entries
|
|
const localStorageData = await this.page.evaluate(() => {
|
|
const data: Record<string, string> = {};
|
|
for (let i = 0; i < localStorage.length; i++) {
|
|
const key = localStorage.key(i);
|
|
if (key) {
|
|
data[key] = localStorage.getItem(key) || '';
|
|
}
|
|
}
|
|
return data;
|
|
});
|
|
|
|
console.log('Local Storage Data:', localStorageData);
|
|
return localStorageData;
|
|
}
|
|
|
|
async saveStorageState(filePath: string) {
|
|
// Save the current browser context's storage state
|
|
await this.page.context().storageState({ path: filePath });
|
|
console.log(`Storage state saved to ${filePath}`);
|
|
}
|
|
|
|
async validatePartQuestions(partQuestions: IPartQuestion[]) {
|
|
for (const pq of partQuestions) {
|
|
const partQuestionOptions = this.page.locator(`fieldset[aria-labelledby="${pq.partQuestionType}"]`);
|
|
if (pq.isOnPage) {
|
|
await expect(partQuestionOptions).toBeAttached();
|
|
} else {
|
|
await expect(partQuestionOptions).not.toBeAttached();
|
|
}
|
|
}
|
|
}
|
|
|
|
async selectPartQuestionResponses(partQuestions: IPartQuestion[]) {
|
|
for (const pq of partQuestions) {
|
|
const parentobject=this.page.locator(`fieldset[aria-labelledby="${pq.partQuestionType}"]`);
|
|
const partQuestionOptionButton = parentobject.locator(`[buttonlabel="${pq.optionToSelect}"]`);
|
|
await partQuestionOptionButton.click();
|
|
if (pq.secondaryQuestionOptionToSelect != null) {
|
|
const secondaryQuestionButton = parentobject.getByText(`${pq.secondaryQuestionOptionToSelect}`);
|
|
await secondaryQuestionButton.click();
|
|
}
|
|
}
|
|
}
|
|
|
|
@step("PartQuestionsPage >> Select Vehicle Part Question Responses")
|
|
async handlePartQuestionsPage(testData: Partial<ITestData>) {
|
|
const { partQuestions } = testData;
|
|
await this.validatePartQuestions(partQuestions!);
|
|
await this.selectPartQuestionResponses(partQuestions!);
|
|
await this.nextPage();
|
|
}
|
|
}
|