@percy/appium-app
Advanced tools
Comparing version 1.0.1 to 1.1.0
22
index.js
@@ -21,3 +21,9 @@ const { AppiumDriver } = require('./percy/driver/driverWrapper'); | ||
fullPage, | ||
screenLengths | ||
screenLengths, | ||
ignoreRegionXpaths, | ||
ignoreRegionAccessibilityIds, | ||
ignoreRegionAppiumElements, | ||
customIgnoreRegions, | ||
scrollableXpath, | ||
scrollableId | ||
} = {}) { | ||
@@ -37,2 +43,8 @@ // allow working with or without standalone mode for wdio | ||
screenLengths = name.screenLengths; | ||
ignoreRegionXpaths = name.ignoreRegionXpaths; | ||
ignoreRegionAccessibilityIds = name.ignoreRegionAccessibilityIds; | ||
ignoreRegionAppiumElements = name.ignoreRegionAppiumElements; | ||
customIgnoreRegions = name.customIgnoreRegions; | ||
scrollableXpath = name.scrollableXpath; | ||
scrollableId = name.scrollableId; | ||
} | ||
@@ -67,3 +79,9 @@ try { | ||
fullPage, | ||
screenLengths | ||
screenLengths, | ||
ignoreRegionXpaths, | ||
ignoreRegionAccessibilityIds, | ||
ignoreRegionAppiumElements, | ||
customIgnoreRegions, | ||
scrollableXpath, | ||
scrollableId | ||
}); | ||
@@ -70,0 +88,0 @@ log.debug(`[${name}] -> end`); |
{ | ||
"name": "@percy/appium-app", | ||
"description": "Appium client library for visual testing with Percy", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -36,7 +36,7 @@ "author": "Perceptual Inc.", | ||
"dependencies": { | ||
"@percy/sdk-utils": "^1.21.0", | ||
"@percy/sdk-utils": "^1.23.0", | ||
"tmp": "^0.2.1" | ||
}, | ||
"devDependencies": { | ||
"@percy/cli": "^1.21.0", | ||
"@percy/cli": "^1.23.0", | ||
"cross-env": "^7.0.2", | ||
@@ -43,0 +43,0 @@ "eslint": "^8.27.0", |
@@ -19,3 +19,3 @@ const { Cache } = require('../util/cache'); | ||
driver.constructor.name === 'Object') && // Object check is only added for tests | ||
!Undefined(driver.sessionCapabilities)) { | ||
!Undefined(driver.sessionCapabilities)) { | ||
this.type = 'wd'; | ||
@@ -129,2 +129,18 @@ } | ||
} | ||
async elementByXPath(xpath) { | ||
// element returned by both wd and wdio drivers have same name functions | ||
// for finding element size and location and attributes | ||
if (this.wd) return await this.driver.elementByXPath(xpath); | ||
/* istanbul ignore next */ // not sure why its marking it when its covered | ||
if (this.wdio) return await this.driver.$(xpath); | ||
} | ||
async elementByAccessibilityId(id) { | ||
// element returned by both wd and wdio drivers have same name functions | ||
// for finding element size and location and attributes | ||
if (this.wd) return await this.driver.elementByAccessibilityId(id); | ||
/* istanbul ignore next */ // not sure why its marking it when its covered | ||
if (this.wdio) return await this.driver.$(`~${id}`); | ||
} | ||
} | ||
@@ -131,0 +147,0 @@ |
@@ -23,3 +23,9 @@ const { GenericProvider } = require('./genericProvider'); | ||
fullPage, | ||
screenLengths | ||
screenLengths, | ||
ignoreRegionXpaths, | ||
ignoreRegionAccessibilityIds, | ||
ignoreRegionAppiumElements, | ||
customIgnoreRegions, | ||
scrollableXpath, | ||
scrollableId | ||
} = {}) { | ||
@@ -39,3 +45,9 @@ let response = null; | ||
fullPage, | ||
screenLengths | ||
screenLengths, | ||
ignoreRegionXpaths, | ||
ignoreRegionAccessibilityIds, | ||
ignoreRegionAppiumElements, | ||
customIgnoreRegions, | ||
scrollableXpath, | ||
scrollableId | ||
}); | ||
@@ -86,3 +98,3 @@ } catch (e) { | ||
// Override this for AA specific optimizations | ||
async getTiles(fullscreen, fullPage, screenLengths) { | ||
async getTiles(fullscreen, fullPage, screenLengths, scrollableXpath, scrollableId) { | ||
// Temporarily restrict AA optimizations only for full page | ||
@@ -102,3 +114,5 @@ if (fullPage !== true) { | ||
numOfTiles: screenLengths || 4, | ||
deviceHeight: (await this.metadata.screenSize()).height | ||
deviceHeight: (await this.metadata.screenSize()).height, | ||
scollableXpath: scrollableXpath || null, | ||
scrollableId: scrollableId || null | ||
} | ||
@@ -105,0 +119,0 @@ }); |
@@ -17,7 +17,7 @@ const utils = require('@percy/sdk-utils'); | ||
clientWdPkg = require('wd/package.json'); | ||
} catch {} | ||
} catch { } | ||
try { | ||
clientWdPkg = require('webdriverio/package.json'); | ||
} catch {} | ||
} catch { } | ||
@@ -45,3 +45,9 @@ let ENV_INFO = `(${clientWdPkg?.name}/${clientWdPkg?.version})`; | ||
fullPage, | ||
screenLengths | ||
screenLengths, | ||
ignoreRegionXpaths, | ||
ignoreRegionAccessibilityIds, | ||
ignoreRegionAppiumElements, | ||
customIgnoreRegions, | ||
scrollableXpath, | ||
scrollableId | ||
}) { | ||
@@ -59,3 +65,8 @@ fullscreen = fullscreen || false; | ||
const tag = await this.getTag(); | ||
const tiles = await this.getTiles(fullscreen, fullPage, screenLengths); | ||
const tiles = await this.getTiles(fullscreen, fullPage, screenLengths, scrollableXpath, scrollableId); | ||
const ignoreRegions = await this.findIgnoredRegions( | ||
ignoreRegionXpaths, ignoreRegionAccessibilityIds, ignoreRegionAppiumElements, customIgnoreRegions | ||
); | ||
log.debug(`${name} : Tag ${JSON.stringify(ignoreRegions)}`); | ||
log.debug(`${name} : Tag ${JSON.stringify(tag)}`); | ||
@@ -69,2 +80,3 @@ log.debug(`${name} : Tiles ${JSON.stringify(tiles)}`); | ||
externalDebugUrl: await this.getDebugUrl(), | ||
ignoredElementsData: ignoreRegions, | ||
environmentInfo: ENV_INFO, | ||
@@ -143,2 +155,100 @@ clientInfo: CLIENT_INFO | ||
} | ||
async findIgnoredRegions(ignoreRegionXpaths, ignoreRegionAccessibilityIds, ignoreRegionAppiumElements, customIgnoreRegions) { | ||
const ignoredElementsArray = []; | ||
await this.ignoreRegionsByXpaths(ignoredElementsArray, ignoreRegionXpaths || []); | ||
await this.ignoreRegionsByIds(ignoredElementsArray, ignoreRegionAccessibilityIds || []); | ||
await this.ignoreRegionsByElement(ignoredElementsArray, ignoreRegionAppiumElements || []); | ||
await this.addCustomIgnoreRegions(ignoredElementsArray, customIgnoreRegions || []); | ||
const ignoredElementsLocations = { | ||
ignoreElementsData: ignoredElementsArray | ||
}; | ||
return ignoredElementsLocations; | ||
} | ||
async ignoreElementObject(selector, element) { | ||
const scaleFactor = await this.metadata.scaleFactor(); | ||
const location = await element.getLocation(); | ||
const size = await element.getSize(); | ||
const coOrdinates = { | ||
top: location.y * scaleFactor, | ||
bottom: (location.y + size.height) * scaleFactor, | ||
left: location.x * scaleFactor, | ||
right: (location.x + size.width) * scaleFactor | ||
}; | ||
const jsonObject = { | ||
selector, | ||
coOrdinates | ||
}; | ||
return jsonObject; | ||
} | ||
async ignoreRegionsByXpaths(ignoredElementsArray, xpaths) { | ||
for (const xpath of xpaths) { | ||
try { | ||
const element = await this.driver.elementByXPath(xpath); | ||
const selector = `xpath: ${xpath}`; | ||
const ignoredRegion = await this.ignoreElementObject(selector, element); | ||
ignoredElementsArray.push(ignoredRegion); | ||
} catch (e) { | ||
log.info(`Appium Element with xpath: ${xpath} not found. Ignoring this xpath.`); | ||
log.debug(e.toString()); | ||
} | ||
} | ||
} | ||
async ignoreRegionsByIds(ignoredElementsArray, ids) { | ||
for (const id of ids) { | ||
try { | ||
const element = await this.driver.elementByAccessibilityId(id); | ||
const selector = `id: ${id}`; | ||
const ignoredRegion = await this.ignoreElementObject(selector, element); | ||
ignoredElementsArray.push(ignoredRegion); | ||
} catch (e) { | ||
log.info(`Appium Element with id: ${id} not found. Ignoring this id.`); | ||
log.debug(e.toString()); | ||
} | ||
} | ||
} | ||
async ignoreRegionsByElement(ignoredElementsArray, elements) { | ||
for (let index = 0; index < elements.length; index++) { | ||
try { | ||
const type = await elements[index].getAttribute('class'); | ||
const selector = `element: ${index} ${type}`; | ||
const ignoredRegion = await this.ignoreElementObject(selector, elements[index]); | ||
ignoredElementsArray.push(ignoredRegion); | ||
} catch (e) { | ||
log.info(`Correct Mobile Element not passed at index ${index}.`); | ||
log.debug(e.toString()); | ||
} | ||
} | ||
} | ||
async addCustomIgnoreRegions(ignoredElementsArray, customLocations) { | ||
const { width, height } = await this.metadata.screenSize(); | ||
for (let index = 0; index < customLocations.length; index++) { | ||
const customLocation = customLocations[index]; | ||
if (customLocation.isValid(height, width)) { | ||
const selector = `custom ignore region ${index}`; | ||
const ignoredRegion = { | ||
selector, | ||
coOrdinates: { | ||
top: customLocation.top, | ||
bottom: customLocation.bottom, | ||
left: customLocation.left, | ||
right: customLocation.right | ||
} | ||
}; | ||
ignoredElementsArray.push(ignoredRegion); | ||
} else { | ||
log.info(`Values passed in custom ignored region at index: ${index} is not valid`); | ||
} | ||
} | ||
} | ||
} | ||
@@ -145,0 +255,0 @@ |
@@ -12,3 +12,7 @@ # @percy/appium-app | ||
``` | ||
Note: Minimum required version for `@percy/cli` is `1.15.0` for this package to work correctly. | ||
> Notes: | ||
> | ||
> Minimum required version for `@percy/cli` is `1.15.0` for this package to work correctly. | ||
> | ||
> This is tested on node 14+ and should be compatible with all newer node versions | ||
@@ -79,1 +83,26 @@ ## Usage | ||
- `screenLengths`: int [Experimental] max screen lengths for fullPage [ needs @percy/cli 1.20.2+ ] | ||
- `scrollableXpath` (**optional**) - [Experimental] scrollable element xpath for fullpage [ needs @percy/cli 1.20.2+ ]; string | ||
- `scrollableId` (**optional**) - [Experimental] scrollable element accessibility id for fullpage [ needs @percy/cli 1.20.2+ ]; string | ||
- `ignoreRegionXpaths` (**optional**) - elements xpaths that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string | ||
- `ignoreRegionAccessibilityIds` (**optional**) - elements accessibility_ids that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of string | ||
- `ignoreRegionAppiumElements` (**optional**) - appium elements that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of appium element object | ||
- `customIgnoreRegions` (**optional**) - custom locations that user want to ignore in visual diff [ needs @percy/cli 1.23.0+ ]; list of ignore_region object | ||
- IgnoreRegion:- | ||
- Description: This class represents a rectangular area on a screen that needs to be ignored for visual diff. | ||
- Constructor: | ||
``` | ||
constructor(top, bottom, left, right) | ||
``` | ||
- Parameters: | ||
`top` (int): Top coordinate of the ignore region. | ||
`bottom` (int): Bottom coordinate of the ignore region. | ||
`left` (int): Left coordinate of the ignore region. | ||
`right` (int): Right coordinate of the ignore region. | ||
- Raises:Error: If top, bottom, left, or right is less than 0 or top is greater than or equal to bottom or left is greater than or equal to right. | ||
- valid: Ignore region should be within the boundaries of the screen. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39193
20
1003
107
Updated@percy/sdk-utils@^1.23.0