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

Responsive snapshot capture + slow scrolling for CS #594

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

chinmay-browserstack
Copy link
Contributor

@chinmay-browserstack chinmay-browserstack commented Dec 16, 2024

  • Expose functionality for slow scrolling for CS
  • In responsive snapshot capture support using minHeight as height.

ENV added

  • PERCY_RESPONSIVE_CAPTURE_RELOAD_PAGE: Reloads page in responsive snapshot capture after each resize
  • PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT : this will use min height passed in .percy.yml file while resizing browser in responsive capture.
  • PERCY_ENABLE_LAZY_LOADING_SCROLL : when this is set we will scroll to bottom after resize in completed and before capturing dom for handling lazy loading.
  • PERCY_LAZY_LOAD_SCROLL_TIME : how much time to sleep after each scroll
  • PERCY_SLEEP_AFTER_LAZY_LOAD_COMPLETE : time to sleep after getting back to top

index.js Outdated
@@ -67,17 +67,29 @@ async function captureResponsiveDOM(driver, options) {
// Setup the resizeCount listener if not present
/* istanbul ignore next: no instrumenting injected code */
await driver.executeScript('PercyDOM.waitForResize()');
let height = currentHeight;
if (process.env.RESPONSIVE_CAPTURE_USE_MIN_HEIGHT) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add prefix of PERCY_

index.js Outdated
lastWindowWidth = width;
}

if (process.env.RESPONSIVE_CAPTURE_SLEEP_TIME) {
await new Promise(resolve => setTimeout(resolve, parseInt(process.env.RESPONSIVE_CAPTURE_SLEEP_TIME) * 1000));
}

if (process.env.RESPONSIVE_CAPTURE_SCROLL_ENABLED) {
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
if (process.env.RESPONSIVE_CAPTURE_SCROLL_ENABLED) {
if (process.env.PERCY_ENABLE_LAZY_LOADING_SCROLL) {

index.js Outdated
lastWindowWidth = width;
}

if (process.env.RESPONSIVE_CAPTURE_SLEEP_TIME) {
await new Promise(resolve => setTimeout(resolve, parseInt(process.env.RESPONSIVE_CAPTURE_SLEEP_TIME) * 1000));
}

if (process.env.RESPONSIVE_CAPTURE_SCROLL_ENABLED) {
let scrollSleep = 0.45;
if (process.env.RESPONSIVE_CAPTURE_SCROLL_TIME) {
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
if (process.env.RESPONSIVE_CAPTURE_SCROLL_TIME) {
if (process.env.PERCY_LAZY_LOAD_SCROLL_TIME) {

index.js Outdated
if (process.env.RESPONSIVE_CAPTURE_SCROLL_ENABLED) {
let scrollSleep = 0.45;
if (process.env.RESPONSIVE_CAPTURE_SCROLL_TIME) {
scrollSleep = parseFloat(process.env.RESPONSIVE_CAPTURE_SCROLL_TIME);
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
scrollSleep = parseFloat(process.env.RESPONSIVE_CAPTURE_SCROLL_TIME);
scrollSleep = parseFloat(process.env. PERCY_LAZY_LOAD_SCROLL_TIME);

index.js Outdated

let page = 1;
// Break the loop if maximum scroll height 25000px is reached
while (scrollHeight > current && current < 25000) {
Copy link
Contributor

Choose a reason for hiding this comment

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

25000 read it from constants

index.js Outdated
// Get back to top
await driver.executeScript('window.scrollTo(0, 0)');
let sleepAfterScroll = 1;
if (process.env.SLEEP_AFTER_SCROLL_DONE) {
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
if (process.env.SLEEP_AFTER_SCROLL_DONE) {
if (process.env.PERCY_SLEEP_AFTER_LAZY_LOAD_COMPLETE) {

index.js Outdated
await driver.executeScript('window.scrollTo(0, 0)');
let sleepAfterScroll = 1;
if (process.env.SLEEP_AFTER_SCROLL_DONE) {
sleepAfterScroll = parseFloat(process.env.SLEEP_AFTER_SCROLL_DONE);
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
sleepAfterScroll = parseFloat(process.env.SLEEP_AFTER_SCROLL_DONE);
sleepAfterScroll = parseFloat(process.env.PERCY_SLEEP_AFTER_LAZY_LOAD_COMPLETE);

index.js Outdated
@@ -67,17 +68,29 @@ async function captureResponsiveDOM(driver, options) {
// Setup the resizeCount listener if not present
/* istanbul ignore next: no instrumenting injected code */
await driver.executeScript('PercyDOM.waitForResize()');
let height = currentHeight;
if (process.env.PERCY_RESPONSIVE_CAPTURE_USE_MIN_HEIGHT) {
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
if (process.env.PERCY_RESPONSIVE_CAPTURE_USE_MIN_HEIGHT) {
if (process.env.PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT) {

index.js Outdated
lastWindowWidth = width;
}

if (process.env.RESPONSIVE_CAPTURE_SLEEP_TIME) {
await new Promise(resolve => setTimeout(resolve, parseInt(process.env.RESPONSIVE_CAPTURE_SLEEP_TIME) * 1000));
}

if (process.env.PERCY_ENABLE_LAZY_LOADING_SCROLL) {
let scrollSleep = 0.45;
Copy link
Contributor

Choose a reason for hiding this comment

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

Constant variable?

index.js Outdated
@@ -252,3 +265,28 @@ module.exports.percyScreenshot = async function percyScreenshot(driver, name, op
module.exports.isPercyEnabled = async function isPercyEnabled() {
return await utils.isPercyEnabled();
};

module.exports.slowScrollToBottom = async (driver, timeInSeconds = 0.45) => {
let scrollHeight = Math.min(await driver.executeScript('return document.documentElement.scrollHeight'), 25000);
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't the constant variable be used here?

}
// Get back to top
await driver.executeScript('window.scrollTo(0, 0)');
let sleepAfterScroll = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

default sleep? variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is sleep after we get back to top

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since we are reseting it based on env variable it is variable(let)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants