Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // @ts-check
const { expect } = require('@playwright/test');
const { BasePage } = require('./BasePage');
const { HeaderComponent } = require('./components/HeaderComponent');
const { environment } = require('../config/environment');
const { HEADINGS, PAGE_TITLES } = require('../utils/constants');
/**
* TestCasesPage represents the /test_cases page and provides
* robust interactions with all 26 practice scenario accordions.
*/
class TestCasesPage extends BasePage {
/**
* @param {import('@playwright/test').Page} page
*/
constructor(page) {
super(page);
this.header = new HeaderComponent(page);
// Primary Page Locators
this.pageHeading = page.locator('h2.title.text-center');
this.subtitle = page.locator('.panel-group h5 span');
// Filter to only the 26 practice test case panels (href begins with #collapse)
this.testCasePanels = page.locator('.panel-group .panel.panel-default:has(a[href^="#collapse"])');
this.testCaseTitleLinks = page.locator('.panel-heading .panel-title a[href^="#collapse"]');
// Feedback accordion panel at the bottom
this.feedbackPanel = page.locator('.panel-group .panel.panel-default:has(a[href="#feedback"])');
this.feedbackLink = page.locator('.panel-heading .panel-title a[href="#feedback"]');
this.feedbackContent = page.locator('#feedback');
}
/**
* Navigates directly to the Test Cases page.
*/
async navigate() {
await this.goto(environment.routes.testCases);
await this.verifyTestCasesPageLoaded();
}
/**
* Verifies the user is navigated to the Test Cases page successfully.
*/
async verifyTestCasesPageLoaded() {
await expect(this.page).toHaveURL(new RegExp(`${environment.routes.testCases}$`));
await expect(this.pageHeading).toBeVisible();
await expect(this.pageHeading).toContainText(HEADINGS.TEST_CASES, { ignoreCase: true });
}
/**
* Verifies page title matches the official document title.
*/
async verifyTitle() {
await expect(this.page).toHaveTitle(PAGE_TITLES.TEST_CASES);
}
/**
* Returns total count of practice test cases (expected 26).
* @returns {Promise<number>}
*/
async getTestCasesCount() {
return this.testCasePanels.count();
}
/**
* Asserts the number of practice test cases matches expected count.
* @param {number} expectedCount
*/
async verifyTestCasesCount(expectedCount = 26) {
await expect(this.testCasePanels).toHaveCount(expectedCount);
}
/**
* Retrieves all test case scenario titles displayed in the accordions.
* @returns {Promise<string[]>}
*/
async getAllTestCaseTitles() {
const titles = await this.testCaseTitleLinks.allInnerTexts();
return titles.map((t) => t.trim());
}
/**
* Resolves a test case panel locator given a number (1-26) or title string.
* @param {number | string} identifier
* @returns {import('@playwright/test').Locator}
*/
getTestCasePanel(identifier) {
if (typeof identifier === 'number') {
return this.page.locator(`.panel.panel-default:has(a[href="#collapse${identifier}"])`);
}
return this.page.locator('.panel.panel-default:has(a[href^="#collapse"])', { hasText: identifier });
}
/**
* Returns the collapse container for a given test case.
* @param {number | string} identifier
* @returns {import('@playwright/test').Locator}
*/
getCollapseContainer(identifier) {
if (typeof identifier === 'number') {
return this.page.locator(`#collapse${identifier}`);
}
const panel = this.getTestCasePanel(identifier);
return panel.locator('.panel-collapse');
}
/**
* Waits for any Bootstrap accordion animation to settle.
* @param {import('@playwright/test').Locator} collapseDiv
*/
async waitForAnimation(collapseDiv) {
await expect(collapseDiv).not.toHaveClass(/collapsing/, { timeout: 7000 });
}
/**
* Checks whether a specific test case accordion is expanded.
* @param {number | string} identifier
* @returns {Promise<boolean>}
*/
async isTestCaseExpanded(identifier) {
const collapseDiv = this.getCollapseContainer(identifier);
const classes = (await collapseDiv.getAttribute('class')) || '';
return classes.includes('in') && !classes.includes('collapsing');
}
/**
* Expands an accordion scenario if it is currently collapsed.
* @param {number | string} identifier
*/
async expandTestCase(identifier) {
const panel = this.getTestCasePanel(identifier);
const link = panel.locator('.panel-heading .panel-title a');
const collapseDiv = this.getCollapseContainer(identifier);
// Ensure not in middle of transition
await this.waitForAnimation(collapseDiv);
const isExpanded = await this.isTestCaseExpanded(identifier);
if (!isExpanded) {
await link.scrollIntoViewIfNeeded();
await link.click();
await expect(collapseDiv).toHaveClass(/in/, { timeout: 7000 });
await this.waitForAnimation(collapseDiv);
}
}
/**
* Collapses an accordion scenario if it is currently open.
* @param {number | string} identifier
*/
async collapseTestCase(identifier) {
const panel = this.getTestCasePanel(identifier);
const link = panel.locator('.panel-heading .panel-title a');
const collapseDiv = this.getCollapseContainer(identifier);
// Ensure not in middle of transition
await this.waitForAnimation(collapseDiv);
const isExpanded = await this.isTestCaseExpanded(identifier);
if (isExpanded) {
await link.scrollIntoViewIfNeeded();
await link.click();
await expect(collapseDiv).not.toHaveClass(/in/, { timeout: 7000 });
await this.waitForAnimation(collapseDiv);
}
}
/**
* Extracts the step instruction lines for a given test case.
* @param {number | string} identifier
* @returns {Promise<string[]>}
*/
async getTestCaseSteps(identifier) {
await this.expandTestCase(identifier);
const collapseDiv = this.getCollapseContainer(identifier);
const stepItems = collapseDiv.locator('ul.list-group li.list-group-item');
const count = await stepItems.count();
const steps = [];
for (let i = 0; i < count; i++) {
const stepText = await stepItems.nth(i).innerText();
steps.push(stepText.trim());
}
return steps;
}
/**
* Verifies test case steps match expected list.
* @param {number | string} identifier
* @param {string[]} expectedSteps
*/
async verifyTestCaseSteps(identifier, expectedSteps) {
const actualSteps = await this.getTestCaseSteps(identifier);
expect(actualSteps).toEqual(expectedSteps);
}
/**
* Verifies the Feedback section is visible at the bottom of the page.
*/
async verifyFeedbackSectionVisible() {
await expect(this.feedbackPanel).toBeVisible();
await expect(this.feedbackLink).toContainText('Feedback for Us');
await expect(this.feedbackContent).toBeVisible();
}
}
module.exports = { TestCasesPage };
|