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

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/config/wp.config.ts
/node_modules
/artifacts
/plugin/wp_mobile.zip
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
/plugin/new_release.zip
/plugin/previous_stable.zip
/plugin/wp-rocket_3.10.9.zip
Expand Down
74 changes: 43 additions & 31 deletions src/features/lcp-beacon-script.feature
Khadreal marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/support/steps/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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 All @@ -84,6 +83,14 @@ Given('activate {string} plugin', async function (this: ICustomWorld, plugin) {
await this.utils.togglePluginActivation(plugin);
});

/**
* Executes the step to deactivate the WP plugin.
*/
Given('deactivate {string} plugin', async function (this: ICustomWorld, plugin) {
await this.utils.gotoPlugin();
await this.utils.deactivatePlugin(plugin);
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
});

/**
* Executes the step to log in.
*/
Expand Down
41 changes: 40 additions & 1 deletion src/support/steps/lcp-beacon-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,43 @@ Then('lcp and atf should be as expected in {string}', async function (this: ICus
}

expect(truthy, failMsg).toBeTruthy();
});
});

/**
*
*/
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
Given('I go to {string} in {string}', async function (this: ICustomWorld, page, formFactor: string) {
let viewPortWidth: number = 1600,
viewPortHeight: number = 700;

// Set page to be visited in mobile.
if ( formFactor === 'mobile' ) {
viewPortWidth = 393;
viewPortHeight = 830;
}


await this.page.waitForLoadState('load', { timeout: 100000 });

await this.page.setViewportSize({
width: viewPortWidth,
height: viewPortHeight
});

const tablePrefix: string = await getWPTablePrefix();

await this.utils.visitPage(page);

// Wait for 6 seconds before fetching from DB.
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
await this.page.waitForTimeout(6000);

// Get the LCP/ATF from the DB
const sql = `SELECT lcp, viewport FROM ${tablePrefix}wpr_above_the_fold WHERE url LIKE "%${page}%"`;
const result = await dbQuery(sql);
const resultFromStdout = await extractFromStdout(result);

Khadreal marked this conversation as resolved.
Show resolved Hide resolved
const lcp = resultFromStdout[0].lcp, viewport = resultFromStdout[0].viewport

expect(lcp).toBe('not found');
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
expect(viewport).toBe('[]');
})
17 changes: 16 additions & 1 deletion src/support/steps/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
*/
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,
deactivatePlugin,
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
generateUsers,
resetWP,
rm,
setTransient
} from "../../../utils/commands";
import {configurations, getWPDir} from "../../../utils/configurations";
import {match} from "ts-pattern";

Expand Down Expand Up @@ -59,6 +67,13 @@ Given('plugin {word} is activated', async function (plugin) {
await activatePlugin(plugin)
});

/**
* Executes the step to deactivate a specified WP plugin via CLI.
*/
Given('plugin {word} is deactivated', async function (plugin) {
await deactivatePlugin(plugin)
});

Khadreal marked this conversation as resolved.
Show resolved Hide resolved
/**
* Executes the step to assert the visibility of a banner with specific text.
*/
Expand Down
13 changes: 13 additions & 0 deletions utils/page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ export class PageUtils {
}
}

/**
* Switch plugin activation state.
*
* @param pluginSlug Plugin slug.
*
* @return {Promise<void>}
*/
public deactivatePlugin = async (pluginSlug: string): Promise<void> => {
if (await this.page.locator('#deactivate-' + pluginSlug).isVisible()) {
await this.page.locator('#deactivate-' + pluginSlug).click();
}
}

Khadreal marked this conversation as resolved.
Show resolved Hide resolved
/**
* Navigates to Wordpress themes page.
*
Expand Down
Loading