diff --git a/src/features/lcp-beacon-script.feature b/src/features/lcp-beacon-script.feature index e2716d8..cf4d636 100644 --- a/src/features/lcp-beacon-script.feature +++ b/src/features/lcp-beacon-script.feature @@ -6,6 +6,7 @@ Feature: Beacon script captures the right images. And plugin is installed 'new_release' And plugin is activated And I go to 'wp-admin/options-general.php?page=wprocket#dashboard' + And plugin 'sitepress-multilingual-cms' is deactivated Scenario: Beacon captures expected images in desktop When I log out @@ -13,6 +14,9 @@ Feature: Beacon script captures the right images. Then lcp and atf should be as expected for 'desktop' Scenario: Beacon captures expected images in mobile + Given I install plugin 'https://github.com/wp-media/wp-rocket-e2e-test-helper/blob/main/helper-plugin/force-wp-mobile.zip' + And plugin 'force-wp-mobile' is activated When I log out And I visit the urls for 'mobile' - Then lcp and atf should be as expected for 'mobile' + And plugin 'force-wp-mobile' is deactivated + Then lcp and atf should be as expected for 'mobile' \ No newline at end of file diff --git a/src/support/results/expectedResultsDesktop.json b/src/support/results/expectedResultsDesktop.json index bab6166..69d1f39 100644 --- a/src/support/results/expectedResultsDesktop.json +++ b/src/support/results/expectedResultsDesktop.json @@ -230,5 +230,12 @@ ], "viewport": [], "enabled": true + }, + "lcp_no_images": { + "lcp": [ + "not found" + ], + "viewport": [], + "enabled": true } } \ No newline at end of file diff --git a/src/support/results/expectedResultsMobile.json b/src/support/results/expectedResultsMobile.json index 97e88e0..52fb005 100644 --- a/src/support/results/expectedResultsMobile.json +++ b/src/support/results/expectedResultsMobile.json @@ -232,5 +232,12 @@ ], "viewport": [], "enabled": true + }, + "lcp_no_images": { + "lcp": [ + "not found" + ], + "viewport": [], + "enabled": true } } \ No newline at end of file diff --git a/src/support/steps/general.ts b/src/support/steps/general.ts index e5efa23..fb16b8c 100644 --- a/src/support/steps/general.ts +++ b/src/support/steps/general.ts @@ -18,7 +18,9 @@ import { WP_BASE_URL } from '../../../config/wp.config'; import { createReference, compareReference } from "../../../utils/helpers"; import type { Section } from "../../../utils/types"; import { Page } from '@playwright/test'; - +import { + deactivatePlugin, installRemotePlugin, +} from "../../../utils/commands"; /** * Executes the step to log in. */ @@ -75,7 +77,6 @@ Given('I save settings {string} {string}', async function (this: ICustomWorld, s await this.page.waitForLoadState('load', { timeout: 30000 }); }); -/** /** * Executes the step to activate the WP plugin. */ @@ -326,4 +327,18 @@ Then('page navigated to the new page {string}', async function (this: ICustomWor const url = `${WP_BASE_URL}/${path}`; const regex = new RegExp(url); await expect(this.page).toHaveURL(regex); +}); + +/** + * Executes the step to deactivate a specified WP plugin via CLI. + */ +Given('plugin {word} is deactivated', async function (plugin) { + await deactivatePlugin(plugin) +}); + +/** + * Executes the step to install a WP plugin from a remote url via CLI. + */ +Given('I install plugin {string}', async function (pluginUrl) { + await installRemotePlugin(pluginUrl) }); \ No newline at end of file diff --git a/src/support/steps/lcp-beacon-script.ts b/src/support/steps/lcp-beacon-script.ts index 5fee556..ebe755c 100644 --- a/src/support/steps/lcp-beacon-script.ts +++ b/src/support/steps/lcp-beacon-script.ts @@ -12,6 +12,7 @@ import { ICustomWorld } from "../../common/custom-world"; import { expect } from "@playwright/test"; import { Given, Then } from "@cucumber/cucumber"; import { LcpData, Row } from "../../../utils/types"; + import { dbQuery, getWPTablePrefix } from "../../../utils/commands"; import { extractFromStdout } from "../../../utils/helpers"; import { WP_BASE_URL } from '../../../config/wp.config'; @@ -21,7 +22,7 @@ let data: string, truthy: boolean = true, failMsg: string = "", jsonData: Record<string, { lcp: string[]; viewport: string[]; enabled: boolean }>; - + const actual: LcpData = {}; /** diff --git a/src/support/steps/steps.ts b/src/support/steps/steps.ts index 04f385a..efac15c 100644 --- a/src/support/steps/steps.ts +++ b/src/support/steps/steps.ts @@ -11,7 +11,14 @@ */ import {expect} from "@playwright/test"; import {AfterAll, BeforeAll} from "@cucumber/cucumber"; -import wp, {activatePlugin, cp, generateUsers, resetWP, rm, setTransient} from "../../../utils/commands"; +import wp, { + activatePlugin, + cp, + generateUsers, + resetWP, + rm, + setTransient +} from "../../../utils/commands"; import {configurations, getWPDir} from "../../../utils/configurations"; import {match} from "ts-pattern"; diff --git a/utils/commands.ts b/utils/commands.ts index 4cc0d48..90f1d98 100644 --- a/utils/commands.ts +++ b/utils/commands.ts @@ -223,6 +223,20 @@ export async function activatePlugin(name: string): Promise<void> { await wp(`plugin activate ${name}`) } +/** + * Install a WordPress plugin from a remote zip file using the WP-CLI command. + * + * @function + * @name installRemotePlugin + * @async + * @param {string} url - The remote zip url of the plugin to be installed. + * @returns {Promise<void>} - A Promise that resolves when the installation is completed. + */ +export async function installRemotePlugin(url: string): Promise<void> { + await wp(`plugin install ${url}`) +} + + /** * Executes a SQL query on the WordPress database using WP-CLI. *