Skip to content

Commit

Permalink
adding support for scrollSpeed and androidScrollAreaPercentage (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
prklm10 authored Sep 3, 2024
1 parent 535982d commit 3de2a7c
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 106 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ await percyScreenshotFlutter(driver, name[, {
- `bottom` (int): Bottom coordinate of the consider region.
- `left` (int): Left coordinate of the consider region.
- `right` (int): Right coordinate of the consider region.
- `androidScrollAreaPercentage` - Percentage Area to scroll for android devices. (should be between 0 and 100)
- `scrollSpeed` - Scroll speed in pixel/second. (Should be between 0 and 5000)

### Creating Percy on automate build
Note: Automate Percy Token starts with `auto` keyword. The command can be triggered using `exec` keyword.
```sh-session
Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ module.exports = async function percyScreenshot(driver, name, options = {}) {
bottomScrollviewOffset,
scrollableId,
sync,
testCase
testCase,
androidScrollAreaPercentage,
scrollSpeed
} = options;
// allow working with or without standalone mode for wdio
if (!driver || typeof driver === 'string') {
Expand Down Expand Up @@ -58,6 +60,8 @@ module.exports = async function percyScreenshot(driver, name, options = {}) {
scrollableId = name.scrollableId;
sync = name.sync;
testCase = name.testCase;
androidScrollAreaPercentage = name.androidScrollAreaPercentage;
scrollSpeed = name.scrollSpeed;
options = name;
}
try {
Expand Down Expand Up @@ -111,7 +115,9 @@ module.exports = async function percyScreenshot(driver, name, options = {}) {
scrollableId,
sync,
testCase,
thTestCaseExecutionId
thTestCaseExecutionId,
androidScrollAreaPercentage,
scrollSpeed
});
log.debug(`[${name}] -> end`);
return response?.body?.data;
Expand Down
164 changes: 104 additions & 60 deletions percy/providers/appAutomateProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,40 @@ class AppAutomateProvider extends GenericProvider {
}

static supports(driver) {
return driver.remoteHostname.includes(process.env.AA_DOMAIN || 'browserstack');
return driver.remoteHostname.includes(
process.env.AA_DOMAIN || 'browserstack'
);
}

async screenshot(name, {
fullscreen,
deviceName,
orientation,
statusBarHeight,
navigationBarHeight,
fullPage,
screenLengths,
ignoreRegionXpaths,
ignoreRegionAccessibilityIds,
ignoreRegionAppiumElements,
customIgnoreRegions,
considerRegionXpaths,
considerRegionAccessibilityIds,
considerRegionAppiumElements,
customConsiderRegions,
scrollableXpath,
topScrollviewOffset,
bottomScrollviewOffset,
scrollableId,
sync,
testCase,
thTestCaseExecutionId
} = {}) {
async screenshot(
name,
{
fullscreen,
deviceName,
orientation,
statusBarHeight,
navigationBarHeight,
fullPage,
screenLengths,
ignoreRegionXpaths,
ignoreRegionAccessibilityIds,
ignoreRegionAppiumElements,
customIgnoreRegions,
considerRegionXpaths,
considerRegionAccessibilityIds,
considerRegionAppiumElements,
customConsiderRegions,
scrollableXpath,
topScrollviewOffset,
bottomScrollviewOffset,
scrollableId,
sync,
testCase,
thTestCaseExecutionId,
androidScrollAreaPercentage,
scrollSpeed
} = {}
) {
let response = null;
let error;
sync = sync || null;
Expand Down Expand Up @@ -67,13 +74,20 @@ class AppAutomateProvider extends GenericProvider {
scrollableId,
sync,
testCase,
thTestCaseExecutionId
thTestCaseExecutionId,
androidScrollAreaPercentage,
scrollSpeed
});
} catch (e) {
error = e;
throw e;
} finally {
await this.percyScreenshotEnd(name, response?.body?.link, sync, `${error}`);
await this.percyScreenshotEnd(
name,
response?.body?.link,
sync,
`${error}`
);
}
return response;
}
Expand All @@ -97,7 +111,12 @@ class AppAutomateProvider extends GenericProvider {
});
}

async percyScreenshotEnd(name, percyScreenshotUrl, sync, statusMessage = null) {
async percyScreenshotEnd(
name,
percyScreenshotUrl,
sync,
statusMessage = null
) {
return await TimeIt.run('percyScreenshotEnd', async () => {
try {
await this.browserstackExecutor('percyScreenshot', {
Expand All @@ -115,11 +134,23 @@ class AppAutomateProvider extends GenericProvider {
}

// Override this for AA specific optimizations
async getTiles(fullscreen, fullPage, screenLengths, scrollableXpath, topScrollviewOffset, bottomScrollviewOffset, scrollableId) {
async getTiles(
fullscreen,
fullPage,
screenLengths,
scrollableXpath,
topScrollviewOffset,
bottomScrollviewOffset,
scrollableId,
androidScrollAreaPercentage,
scrollSpeed
) {
// Override AA optimizations
if (this.isDisableRemoteUpload()) {
if (fullPage === true) {
log.warn('Full page screenshots are only supported when "PERCY_DISABLE_REMOTE_UPLOADS" is not set');
log.warn(
'Full page screenshots are only supported when "PERCY_DISABLE_REMOTE_UPLOADS" is not set'
);
}
return await super.getTiles(fullscreen, fullPage, screenLengths);
}
Expand All @@ -133,51 +164,64 @@ class AppAutomateProvider extends GenericProvider {
projectId = 'percy-dev';
}
// Take screenshots via browserstack executor
const response = await TimeIt.run('percyScreenshot:screenshot', async () => {
return await this.browserstackExecutor('percyScreenshot', {
state: 'screenshot',
percyBuildId: utils.percy?.build?.id,
screenshotType,
projectId,
scaleFactor: await this.metadata.scaleFactor(),
options: {
numOfTiles: screenLengths || 4,
deviceHeight: (await this.metadata.screenSize()).height,
scollableXpath: scrollableXpath || null,
topScrollviewOffset: topScrollviewOffset || 0,
bottomScrollviewOffset: bottomScrollviewOffset || 0,
scrollableId: scrollableId || null,
FORCE_FULL_PAGE: process.env.FORCE_FULL_PAGE === 'true'
}
});
});
const response = await TimeIt.run(
'percyScreenshot:screenshot',
async () => {
return await this.browserstackExecutor('percyScreenshot', {
state: 'screenshot',
percyBuildId: utils.percy?.build?.id,
screenshotType,
projectId,
scaleFactor: await this.metadata.scaleFactor(),
options: {
numOfTiles: screenLengths || 4,
deviceHeight: (await this.metadata.screenSize()).height,
scollableXpath: scrollableXpath || null,
topScrollviewOffset: topScrollviewOffset || 0,
bottomScrollviewOffset: bottomScrollviewOffset || 0,
scrollableId: scrollableId || null,
FORCE_FULL_PAGE: process.env.FORCE_FULL_PAGE === 'true',
androidScrollAreaPercentage: androidScrollAreaPercentage || null,
scrollSpeed: scrollSpeed || null
}
});
}
);

if (!response.success) {
throw new Error('Failed to get screenshots from App Automate.' +
' Check dashboard for error.');
throw new Error(
'Failed to get screenshots from App Automate.' +
' Check dashboard for error.'
);
}

const tiles = [];
const statBarHeight = await this.metadata.statusBarHeight();
const navBarHeight = await this.metadata.navigationBarHeight();

JSON.parse(response.result).forEach(tileData => {
tiles.push(new Tile({
statusBarHeight: statBarHeight,
navBarHeight,
fullscreen,
headerHeight: tileData.header_height,
footerHeight: tileData.footer_height,
sha: tileData.sha.split('-')[0] // drop build id
}));
JSON.parse(response.result).forEach((tileData) => {
tiles.push(
new Tile({
statusBarHeight: statBarHeight,
navBarHeight,
fullscreen,
headerHeight: tileData.header_height,
footerHeight: tileData.footer_height,
sha: tileData.sha.split('-')[0] // drop build id
})
);
});

return tiles;
}

async browserstackExecutor(action, args) {
let options = args ? { action, arguments: args } : { action };
return JSON.parse(await this.driver.execute(`browserstack_executor: ${JSON.stringify(options)}`));
return JSON.parse(
await this.driver.execute(
`browserstack_executor: ${JSON.stringify(options)}`
)
);
}

setDebugUrl(result) {
Expand Down
Loading

0 comments on commit 3de2a7c

Please sign in to comment.