Skip to content

Commit e51618f

Browse files
authored
fix: harden performance hints page restore checks (#328)
* fix: harden performance hints page restore checks * Update src/support/hooks.ts * remove an unnecessary wait
1 parent f11494e commit e51618f

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/support/hooks.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import { ChromiumBrowser, chromium } from '@playwright/test';
1919
import { Sections } from '../common/sections';
2020
import { selectors as pluginSelectors } from "./../common/selectors";
2121
import { PageUtils } from "../../utils/page-utils";
22-
import { deleteFolder, isWprRelatedError } from "../../utils/helpers";
22+
import { deleteFolder, extractFromStdout, isWprRelatedError } from "../../utils/helpers";
2323
import {WP_SSH_ROOT_DIR,} from "../../config/wp.config";
2424
import { After, AfterAll, Before, BeforeAll, Status, setDefaultTimeout } from "@cucumber/cucumber";
25-
import {rename, exists, rm, testSshConnection, installRemotePlugin, activatePlugin, uninstallPlugin, readFile, isPluginActive, isPluginInstalled} from "../../utils/commands";
25+
import {rename, exists, rm, testSshConnection, installRemotePlugin, activatePlugin, uninstallPlugin, readFile, isPluginActive, isPluginInstalled, getPostDataFromTitle} from "../../utils/commands";
2626
import type { Selectors } from "../../utils/types";
2727
import type { Section } from "../../utils/types";
2828
// import {configurations, getWPDir} from "../../utils/configurations";
@@ -213,6 +213,25 @@ Before({tags: '@vr'}, async function (this: ICustomWorld) {
213213
this.wprOption = option;
214214
});
215215

216+
/**
217+
* Before each test scenario with the @performancehints tag, verifies required pages exist.
218+
*/
219+
Before({tags: '@performancehints'}, async function (this: ICustomWorld) {
220+
const requiredPages = ['atf-lrc-1', 'atf-lrc-2'];
221+
222+
for (const pageName of requiredPages) {
223+
const pageDataStdout = await getPostDataFromTitle(pageName, 'publish', 'ID,post_status');
224+
const pageData = await extractFromStdout(pageDataStdout);
225+
226+
if (!pageData || pageData.length === 0) {
227+
throw new Error(
228+
`Required test page '${pageName}' does not exist. ` +
229+
`Template loader plugin may have failed.`
230+
);
231+
}
232+
}
233+
});
234+
216235
/**
217236
* After each test scenario, performs cleanup tasks and captures screenshots and videos in case of failure.
218237
*/

src/support/steps/performance-hints.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,18 @@ When ('{string} page is deleted', async function (this: ICustomWorld, permalink:
140140
Then ('untrash and republish {string} page', async function (this: ICustomWorld, permalink: string) {
141141
const postDataStdout = await getPostDataFromTitle(permalink, 'trash', 'ID,post_title');
142142
const postData = await extractFromStdout(postDataStdout);
143+
144+
if (!postData || postData.length === 0) {
145+
throw new Error(`Failed to find page '${permalink}' in trash`);
146+
}
147+
143148
await updatePostStatus(parseInt(postData[0].ID, 10), 'publish');
149+
150+
// Verify it actually worked
151+
const verifyStdout = await getPostDataFromTitle(permalink, 'publish', 'ID,post_status');
152+
const verifyData = await extractFromStdout(verifyStdout);
153+
154+
if (!verifyData || verifyData.length === 0 || verifyData[0].post_status !== 'publish') {
155+
throw new Error(`Failed to restore page '${permalink}' to published status`);
156+
}
144157
});

0 commit comments

Comments
 (0)