Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #70 Add scenario for pages without LCP/ATF #76

6 changes: 5 additions & 1 deletion src/features/lcp-beacon-script.feature
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ 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
And I visit the urls for 'desktop'
Then lcp and atf should be as expected for 'desktop'
Khadreal marked this conversation as resolved.
Show resolved Hide resolved

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'
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
Then lcp and atf should be as expected for 'mobile'
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
And plugin 'force-wp-mobile' is deactivated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
And plugin 'force-wp-mobile' is deactivated
Then lcp and atf should be as expected for 'mobile'

Then lcp and atf should be as expected for 'mobile'
7 changes: 7 additions & 0 deletions src/support/results/expectedResultsDesktop.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,12 @@
],
"viewport": [],
"enabled": true
},
"lcp_no_images": {
"lcp": [
"not found"
],
"viewport": [],
"enabled": true
}
}
7 changes: 7 additions & 0 deletions src/support/results/expectedResultsMobile.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,12 @@
],
"viewport": [],
"enabled": true
},
"lcp_no_images": {
"lcp": [
"not found"
],
"viewport": [],
"enabled": true
}
}
19 changes: 17 additions & 2 deletions src/support/steps/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
});
3 changes: 2 additions & 1 deletion src/support/steps/lcp-beacon-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,7 +22,7 @@ let data: string,
truthy: boolean = true,
failMsg: string = "",
jsonData: Record<string, { lcp: string[]; viewport: string[]; enabled: boolean }>;

const actual: LcpData = {};

/**
Expand Down
9 changes: 8 additions & 1 deletion src/support/steps/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
14 changes: 14 additions & 0 deletions utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down