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

:chore: Add steps, functions to test lazyload images -- #56 #61

Merged
merged 16 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/features/lazy-load.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@llcssbg @setup
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
Feature: Check if content are lazyloaded while scrolling
Background:
Given I am logged in
And plugin is installed 'new_release'
And plugin is activated
When I go to 'wp-admin/options-general.php?page=wprocket#dashboard'
And I save settings 'media' 'lazyloadCssBgImg'
And clear wpr cache

Scenario: Open Lazy load css background images page
When I log out
And I go to 'lazyload_css_background_images' check initial image loaded
Then I must see other 'lazyload_css_background_images' images

Scenario: Open single colon template
When I log out
And I go to 'll_bg_css_single_colon' check initial image loaded
Then Check 'll_bg_css_single_colon' input for background images

Scenario: Open double colon template
When I log out
And I go to 'll_bg_css_double_colon' check initial image loaded
Then Check 'll_bg_css_double_colon' input for background images
8 changes: 8 additions & 0 deletions src/support/steps/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ When('I go to {string}', async function (this: ICustomWorld, page) {
await this.page.waitForLoadState('load', { timeout: 100000 });
});

/**
* Clear wpr cache
*/
Given('clear wpr cache', async function (this: ICustomWorld) {
await this.utils.clearWPRCache();
});


/**
* Executes the step to click on a specific button.
*/
Expand Down
111 changes: 110 additions & 1 deletion src/support/steps/ll-css-bg-image.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Then } from '@cucumber/cucumber';
import { When, Then } from '@cucumber/cucumber';
import { ICustomWorld } from "../../common/custom-world";
import { expect } from "@playwright/test";

Expand Down Expand Up @@ -58,4 +58,113 @@ Then('I must see the correct style in the head', async function (this: ICustomWo
console.log(failMessage);

expect(isMatch, failMessage).toBeTruthy();
});

const LL_BACKGROUND_IMAGES = {
// eslint-disable-next-line @typescript-eslint/naming-convention
lazyload_css_background_images: {
initialImages: [
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test.png',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/image-insidescript.jpeg',
Copy link
Contributor

Choose a reason for hiding this comment

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

For images with e2e domain, can we read this from env variable so it can run on any e2e env? what do you think?

'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/paper.jpeg',
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test_inline1.jpeg',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test_inline2.jpeg',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test_internal0.webp'
],
lazyLoadedImages: [
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/image/test3.webp',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/image/file_example_JPG_100kB.jpg',
'https://rocketlabsqa.ovh/wp-content/rocket-test-data/images/Spain.PNG',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/paper.jpeg',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test_internal4.jpg',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/testnotExist.png',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/wp-rocket.svg',
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/butterfly.avif',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/file_example_TIFF_1MB.tiff',
'https://fastly.picsum.photos/id/976/200/300.jpg?hmac=s1Uz9fgJv32r8elfaIYn7pLpQXps7X9oYNwC5XirhO8',
'https://rocketlabsqa.ovh/wp-content/rocket-test-data/images/fixtheissue.jpg',
'https://mega.wp-rocket.me/avada/wp-content/rocket-test-data/prague-conference-center-1056491.jpg',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/butterfly%202.avif',
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/paper%C3%A9quipesTest.jpeg',
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test_internal2.jpg',
'https://e2e.rocketlabsqa.ovh/wp-content/plugins/revslidertest1/public/assets/assets/test_internal3.jpg',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test.png',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/image/test3.gif',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test_external1.jpeg',
'https://e2e.rocketlabsqa.ovh/test.png',
'https://upload.wikimedia.org/wikipedia/commons/1/11/Test-Logo.svg',
'https://e2e.rocketlabsqa.ovh/kot%C5%82.png',
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/styles/assets/images/relative1.jpeg',
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/styles/assets/images/relative2.jpg',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/lcp/testsvg.svg',
'https://new.rocketlabsqa.ovh//wp-content/rocket-test-data/images/wp-rocket.svg',
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/wp-rocket2.svg',
'https://e2e.rocketlabsqa.ovh/new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/test_internal2.jpg',
'https://new.rocketlabsqa.ovh/wp-content/rocket-test-data/images/nature.jpeg'
]
},
// eslint-disable-next-line @typescript-eslint/naming-convention
ll_bg_css_single_colon: {
initialImages: [
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/fabio-sasso-UgpCjt4XLTY-unsplash.jpg',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/underline.png',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
lazyLoadedImages: [
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/miguel-luis-6wxFtwSuXHQ-unsplash.jpg'
]
},
// eslint-disable-next-line @typescript-eslint/naming-convention
ll_bg_css_double_colon:{
initialImages: [
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/fabio-sasso-UgpCjt4XLTY-unsplash.jpg',
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/underline.png',
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/maxime-lebrun-6g3Akg708E0-unsplash.jpg'
],
lazyLoadedImages: [
'https://e2e.rocketlabsqa.ovh/wp-content/rocket-test-data/images/miguel-luis-6wxFtwSuXHQ-unsplash.jpg',
]
}
};

When('I go to {string} check initial image loaded', async function (this: ICustomWorld, page) {
const images = [];

this.page.on('request', request => {
if (request.resourceType() === 'image') {
images.push(request.url());
}
});
await this.utils.visitPage(page);
await this.page.waitForLoadState('load', { timeout: 100000 });
const template = LL_BACKGROUND_IMAGES[page].initialImages

expect(images).toEqual(template)
});

Then('I must see other {string} images', async function (this: ICustomWorld, page) {
const images = [];
this.page.on('request', request => {
if (request.resourceType() === 'image') {
images.push(request.url());
}
});
await this.utils.scrollDownBottomOfAPage();

expect(images).toEqual(LL_BACKGROUND_IMAGES[page].lazyLoadedImages)
});

Then('Check {string} input for background images', async function (this: ICustomWorld, page) {
const images = [];
this.page.on('request', request => {
if (request.resourceType() === 'image') {
images.push(request.url());
}
});

await this.page.locator('input[name="lastName"]').nth(1).fill('Random text')

await this.utils.scrollDownBottomOfAPage();

expect(images).toEqual(LL_BACKGROUND_IMAGES[page].lazyLoadedImages)
});
42 changes: 42 additions & 0 deletions utils/page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,21 @@ export class PageUtils {
await this.sections.massToggle();
}

/**
* Performs to clear all cache action on WP Rocket.
*
* @return {Promise<void>}
*/
public clearWPRCache = async(): Promise<void> => {
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
await this.gotoWpr();
await this.page.waitForLoadState('load', { timeout: 30000 });

const clearCacheURL = await this.page.locator('.wpr-button.wpr-button--icon.wpr-icon-trash').first().getAttribute('href');

await this.page.goto(clearCacheURL);
await this.page.waitForLoadState('load', { timeout: 30000 });
}

/**
* Performs the enable all options action on WP Rocket.
*
Expand Down Expand Up @@ -571,4 +586,31 @@ export class PageUtils {

await activate.click();
}

/**
* Scroll down to the bottom of a page
*
* @return {Promise<void>}
*/
public scrollDownBottomOfAPage = async (): Promise<void> => {
Khadreal marked this conversation as resolved.
Show resolved Hide resolved
await this.page.evaluate(async () => {
const scrollPage: Promise<void> = new Promise((resolve) => {

let totalHeight = 0;
const distance = 150;
const timer = setInterval(() => {
const scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;

if (totalHeight >= scrollHeight) {
clearInterval(timer);
resolve();
}
}, 700);
});

await scrollPage;
});
}
}
Loading