Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@percy/webdriver-utils

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@percy/webdriver-utils - npm Package Compare versions

Comparing version 1.27.6-beta.0 to 1.27.6-beta.1

22

dist/providers/automateProvider.js

@@ -103,7 +103,8 @@ import utils from '@percy/sdk-utils';

}
async getTiles(headerHeight, footerHeight, fullscreen) {
var _responseValue$metada;
async getTiles(fullscreen) {
var _this$options;
if (!this.driver) throw new Error('Driver is null, please initialize driver with createDriver().');
log.debug('Starting actual screenshotting phase');
const dpr = await this.metaData.devicePixelRatio();
const screenshotType = (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.fullPage ? 'fullpage' : 'singlepage';
const response = await TimeIt.run('percyScreenshot:screenshot', async () => {

@@ -113,3 +114,3 @@ return await this.browserstackExecutor('percyScreenshot', {

percyBuildId: this.buildInfo.id,
screenshotType: 'singlepage',
screenshotType: screenshotType,
scaleFactor: dpr,

@@ -126,11 +127,10 @@ options: this.options

log.debug('Tiles captured successfully');
const windowHeight = (responseValue === null || responseValue === void 0 ? void 0 : (_responseValue$metada = responseValue.metadata) === null || _responseValue$metada === void 0 ? void 0 : _responseValue$metada.window_height) || 0;
for (let tileData of tileResponse.sha) {
for (let tileData of tileResponse.tiles) {
tiles.push(new Tile({
statusBarHeight: tileResponse.header_height || 0,
navBarHeight: tileResponse.footer_height || 0,
headerHeight,
footerHeight,
statusBarHeight: tileData.status_bar || 0,
navBarHeight: tileData.nav_bar || 0,
headerHeight: tileData.header_height || 0,
footerHeight: tileData.footer_height || 0,
fullscreen,
sha: tileData.split('-')[0] // drop build id
sha: tileData.sha.split('-')[0] // drop build id
}));

@@ -140,3 +140,3 @@ }

const metadata = {
windowHeight: Math.ceil(windowHeight * dpr)
screenshotType: screenshotType
};

@@ -143,0 +143,0 @@ return {

@@ -29,5 +29,3 @@ import utils from '@percy/sdk-utils';

this.removeElementShiftFactor = 50000;
this.initialScrollFactor = {
value: [0, 0]
};
this.initialScrollLocation = null;
}

@@ -57,18 +55,25 @@ addDefaultOptions() {

}
async getInitialPosition() {
if (this.currentTag.osName === 'iOS') {
this.initialScrollFactor = await this.driver.executeScript({
script: 'return [parseInt(window.scrollX), parseInt(window.scrollY)];',
args: []
});
}
isIOS() {
var _this$currentTag;
return ((_this$currentTag = this.currentTag) === null || _this$currentTag === void 0 ? void 0 : _this$currentTag.osName) === 'iOS';
}
async scrollToInitialPosition(x, y) {
if (this.currentTag.osName === 'iOS') {
await this.driver.executeScript({
script: `window.scrollTo(${x}, ${y})`,
args: []
});
async getScrollDetails() {
return await this.driver.executeScript({
script: 'return [parseInt(window.scrollX), parseInt(window.scrollY)];',
args: []
});
}
async getInitialScrollLocation() {
if (this.initialScrollLocation) {
return this.initialScrollLocation;
}
this.initialScrollLocation = await this.getScrollDetails();
return this.initialScrollLocation;
}
async scrollToPosition(x, y) {
await this.driver.executeScript({
script: `window.scrollTo(${x}, ${y})`,
args: []
});
}
async screenshot(name, {

@@ -90,3 +95,3 @@ ignoreRegionXpaths = [],

log.debug(`[${name}] : Tag ${JSON.stringify(tag)}`);
const tiles = await this.getTiles(this.header, this.footer, fullscreen);
const tiles = await this.getTiles(fullscreen);
log.debug(`[${name}] : Tiles ${JSON.stringify(tiles)}`);

@@ -131,3 +136,3 @@ this.currentTag = tag;

}
async getTiles(headerHeight, footerHeight, fullscreen) {
async getTiles(fullscreen) {
if (!this.driver) throw new Error('Driver is null, please initialize driver with createDriver().');

@@ -141,4 +146,4 @@ const base64content = await this.driver.takeScreenshot();

navBarHeight: 0,
headerHeight,
footerHeight,
headerHeight: this.header,
footerHeight: this.footer,
fullscreen

@@ -179,2 +184,3 @@ })],

async doTransformations() {
var _this$options;
const hideScrollbarStyle = `

@@ -200,2 +206,5 @@ /* Hide scrollbar for Chrome, Safari and Opera */

});
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.fullPage || this.isIOS()) {
await this.getInitialScrollLocation();
}
}

@@ -226,12 +235,19 @@ async undoTransformations(data) {

async getRegionObjectFromBoundingBox(selector, element) {
var _this$options2;
const scaleFactor = await this.metaData.devicePixelRatio();
let scrollX = 0,
scrollY = 0;
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.fullPage) {
scrollX = this.initialScrollLocation.value[0];
scrollY = this.initialScrollLocation.value[1];
}
let headerAdjustment = 0;
if (this.currentTag.osName === 'iOS') {
if (this.isIOS()) {
headerAdjustment = this.statusBarHeight;
}
const coOrdinates = {
top: Math.floor(element.y * scaleFactor) + Math.floor(headerAdjustment),
bottom: Math.ceil((element.y + element.height) * scaleFactor) + Math.ceil(headerAdjustment),
left: Math.floor(element.x * scaleFactor),
right: Math.ceil((element.x + element.width) * scaleFactor)
top: Math.floor((element.y + scrollY) * scaleFactor) + Math.floor(headerAdjustment),
bottom: Math.ceil((element.y + element.height + scrollY) * scaleFactor) + Math.ceil(headerAdjustment),
left: Math.floor((element.x + scrollX) * scaleFactor),
right: Math.ceil((element.x + element.width + scrollX) * scaleFactor)
};

@@ -259,8 +275,5 @@ const jsonObject = {

}
async updatePageShiftFactor(location, scaleFactor) {
const scrollFactors = await this.driver.executeScript({
script: 'return [parseInt(window.scrollX), parseInt(window.scrollY)];',
args: []
});
if (this.currentTag.osName === 'iOS' || this.currentTag.osName === 'OS X' && parseInt(this.currentTag.browserVersion) > 13 && this.currentTag.browserName.toLowerCase() === 'safari') {
async updatePageShiftFactor(location, scaleFactor, scrollFactors) {
var _this$options3;
if (this.isIOS() || this.currentTag.osName === 'OS X' && parseInt(this.currentTag.browserVersion) > 13 && this.currentTag.browserName.toLowerCase() === 'safari') {
this.pageYShiftFactor = this.statusBarHeight;

@@ -270,5 +283,5 @@ } else {

}
this.pageXShiftFactor = this.currentTag.osName === 'iOS' ? 0 : -(scrollFactors.value[0] * scaleFactor);
if (this.currentTag.osName === 'iOS') {
if (scrollFactors.value[0] !== this.initialScrollFactor.value[0] || scrollFactors.value[1] !== this.initialScrollFactor.value[1]) {
this.pageXShiftFactor = this.isIOS() ? 0 : -(scrollFactors.value[0] * scaleFactor);
if (this.isIOS() && !((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.fullPage)) {
if (scrollFactors.value[0] !== this.initialScrollLocation.value[0] || scrollFactors.value[1] !== this.initialScrollLocation.value[1]) {
this.pageXShiftFactor = -1 * this.removeElementShiftFactor;

@@ -282,2 +295,3 @@ this.pageYShiftFactor = -1 * this.removeElementShiftFactor;

async getRegionObject(selector, elementId) {
var _this$options4;
const scaleFactor = await this.metaData.devicePixelRatio();

@@ -293,2 +307,10 @@ const rect = await this.driver.rect(elementId);

};
let scrollX = 0,
scrollY = 0;
const scrollFactors = await this.getScrollDetails();
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.fullPage) {
scrollX = scrollFactors.value[0];
scrollY = scrollFactors.value[1];
}
// Update pageShiftFactor Element is not visible in viewport

@@ -298,8 +320,8 @@ // In case of iOS if the element is not visible in viewport it gives 0 for x-y coordinate.

// Subtracting ScrollY/ScrollX ensures if the element is visible in viewport or not.
await this.updatePageShiftFactor(location, scaleFactor);
await this.updatePageShiftFactor(location, scaleFactor, scrollFactors);
const coOrdinates = {
top: Math.floor(location.y * scaleFactor) + Math.floor(this.pageYShiftFactor),
bottom: Math.ceil((location.y + size.height) * scaleFactor) + Math.ceil(this.pageYShiftFactor),
left: Math.floor(location.x * scaleFactor) + Math.floor(this.pageXShiftFactor),
right: Math.ceil((location.x + size.width) * scaleFactor) + Math.ceil(this.pageXShiftFactor)
top: Math.floor((location.y + scrollY) * scaleFactor) + Math.floor(this.pageYShiftFactor),
bottom: Math.ceil((location.y + size.height + scrollY) * scaleFactor) + Math.ceil(this.pageYShiftFactor),
left: Math.floor((location.x + scrollX) * scaleFactor) + Math.floor(this.pageXShiftFactor),
right: Math.ceil((location.x + size.width + scrollX) * scaleFactor) + Math.ceil(this.pageXShiftFactor)
};

@@ -314,3 +336,2 @@ const jsonObject = {

const regionsArray = [];
await this.getInitialPosition();
for (let index = 0; index < elements.length; index++) {

@@ -326,3 +347,5 @@ try {

}
await this.scrollToInitialPosition(this.initialScrollFactor.value[0], this.initialScrollFactor.value[1]);
if (this.isIOS()) {
await this.scrollToPosition(this.initialScrollLocation.value[0], this.initialScrollLocation.value[1]);
}
return regionsArray;

@@ -329,0 +352,0 @@ }

{
"name": "@percy/webdriver-utils",
"version": "1.27.6-beta.0",
"version": "1.27.6-beta.1",
"license": "MIT",

@@ -32,6 +32,6 @@ "repository": {

"dependencies": {
"@percy/config": "1.27.6-beta.0",
"@percy/sdk-utils": "1.27.6-beta.0"
"@percy/config": "1.27.6-beta.1",
"@percy/sdk-utils": "1.27.6-beta.1"
},
"gitHead": "264fe038aa6a6ef6ed4d94b53f4f8905218c266e"
"gitHead": "1a3bf9e775769215ef590faa40502ce0ee0a6f78"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc