Skip to content

Commit

Permalink
move sleep time to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmay-browserstack committed Dec 16, 2024
1 parent c048f3c commit cd9c875
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const utils = require('@percy/sdk-utils');
const { DriverMetadata } = require('./driverMetadata');
const log = utils.logger('selenium-webdriver');
const CS_MAX_SCREENSHOT_LIMIT = 25000;
const SCROLL_DEFAULT_SLEEP_TIME = 0.45; // 450ms

const getWidthsForMultiDOM = (userPassedWidths, eligibleWidths) => {
// Deep copy of eligible mobile widths
Expand Down Expand Up @@ -69,7 +70,7 @@ async function captureResponsiveDOM(driver, options) {
/* istanbul ignore next: no instrumenting injected code */
await driver.executeScript('PercyDOM.waitForResize()');
let height = currentHeight;
if (process.env.PERCY_RESPONSIVE_CAPTURE_USE_MIN_HEIGHT) {
if (process.env.PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT) {
height = await driver.executeScript(`return window.outerHeight - window.innerHeight + ${utils.percy?.config?.snapshot?.minHeight}`);
}
for (let width of widths) {
Expand All @@ -84,7 +85,7 @@ async function captureResponsiveDOM(driver, options) {
}

if (process.env.PERCY_ENABLE_LAZY_LOADING_SCROLL) {
let scrollSleep = 0.45;
let scrollSleep = SCROLL_DEFAULT_SLEEP_TIME;
if (process.env.PERCY_LAZY_LOAD_SCROLL_TIME) {
scrollSleep = parseFloat(process.env.PERCY_LAZY_LOAD_SCROLL_TIME);
}
Expand Down Expand Up @@ -266,7 +267,7 @@ module.exports.isPercyEnabled = async function isPercyEnabled() {
return await utils.isPercyEnabled();
};

module.exports.slowScrollToBottom = async (driver, timeInSeconds = 0.45) => {
module.exports.slowScrollToBottom = async (driver, timeInSeconds = SCROLL_DEFAULT_SLEEP_TIME) => {
let scrollHeight = Math.min(await driver.executeScript('return document.documentElement.scrollHeight'), 25000);
const clientHeight = await driver.executeScript('return document.documentElement.clientHeight');
let current = 0;
Expand Down

0 comments on commit cd9c875

Please sign in to comment.