Skip to content

Commit

Permalink
Closes #70 Add scenario for pages without LCP/ATF (#76)
Browse files Browse the repository at this point in the history
* Add scenario for no lcp/atf, add plugin deactivation function #70 :closes:

* fixed lint

* minor fix

* Add step to activate and deactivate mobile plugin

* update gitignore file

* PR modifications

* Add new command function, pr modifications --#70

* minor modifications

* Add beacon check for lcp pages

* deactivate plugin, modify json

* Add missing step

* change steps
  • Loading branch information
Khadreal authored May 16, 2024
1 parent e91b6d2 commit 18509cf
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/features/lcp-beacon-script.feature
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'

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'
7 changes: 7 additions & 0 deletions src/support/results/expectedResultsDesktop.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,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

0 comments on commit 18509cf

Please sign in to comment.