Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
prklm10 committed Jan 23, 2024
1 parent f6e6123 commit faea883
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 109 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = async function percyScreenshot(driver, name, options = {}) {
scrollableXpath,
topScrollviewOffset,
bottomScrollviewOffset,
scrollableId
scrollableId,
sync
} = options;
// allow working with or without standalone mode for wdio
if (!driver || typeof driver === 'string') {
Expand All @@ -54,6 +55,7 @@ module.exports = async function percyScreenshot(driver, name, options = {}) {
topScrollviewOffset = name.topScrollviewOffset;
bottomScrollviewOffset = name.bottomScrollviewOffset;
scrollableId = name.scrollableId;
sync = name.sync;
options = name;
}
try {
Expand Down Expand Up @@ -100,7 +102,8 @@ module.exports = async function percyScreenshot(driver, name, options = {}) {
scrollableXpath,
topScrollviewOffset,
bottomScrollviewOffset,
scrollableId
scrollableId,
sync
});
log.debug(`[${name}] -> end`);
return response;
Expand Down
54 changes: 54 additions & 0 deletions ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const percyScreenshot = require('./index');
const wd = require('wd');
let asserters = wd.asserters;

Check failure on line 3 in ios.js

View workflow job for this annotation

GitHub Actions / Lint

'asserters' is assigned a value but never used

// Note: While this example shows how to use percyScreenshot with Browserstack App
// Automate, percyScreenshot method just expects a initialized driver object and does
// not care if its connected to App Automate or any other appium server.
// You are free to create `driver` object anyway you want and can pass it
// to the percyScreenshot function.

const desiredCaps = {
// Set BStack options that would allow App Automate to run
'bstack:options': {
userName: 'pradumkumar_USRpXW',
accessKey: 'x2Eq6HxMrgzNphqsZcsz'
},

// Percy Options (defaults)
percyOptions: {
enabled: true,
ignoreErrors: true
},
// Set URL of the application under test
app: 'bs://8f063eac036c00823c233970e4f14c1a37a8f0d7',

// Specify device and os_version for testing
device: 'Google Pixel 7 Pro',
os_version: '13',

// Set other BrowserStack capabilities
project: 'First Node App Percy Project',
build: 'App Percy wd Android',
name: 'first_visual_test'
};

// Initialize the remote Webdriver using BrowserStack remote URL
// and desired capabilities defined above
const driver = wd.promiseRemote('https://hub-cloud.browserstack.com/wd/hub');

// Test case for the BrowserStack sample Android app.
// If you have uploaded your app, update the test case here.
driver.init(desiredCaps)
.then(function() {
// wait for app to load
return new Promise((resolve) => setTimeout(resolve, 2000));
})
.then(function() {
percyScreenshot(driver, 'Home Screen', { sync: true });
})
.fin(function() {
// Invoke driver.quit() after the test is done to indicate that the test is completed.
return driver.quit();
})
.done();
17 changes: 11 additions & 6 deletions percy/providers/appAutomateProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class AppAutomateProvider extends GenericProvider {
scrollableXpath,
topScrollviewOffset,
bottomScrollviewOffset,
scrollableId
scrollableId,
sync
} = {}) {
let response = null;
let error;
sync = sync || false;
try {
let result = await this.percyScreenshotBegin(name);
this.setDebugUrl(result);
Expand All @@ -60,13 +62,14 @@ class AppAutomateProvider extends GenericProvider {
scrollableXpath,
topScrollviewOffset,
bottomScrollviewOffset,
scrollableId
scrollableId,
sync
});
} catch (e) {
error = e;
throw e;
} finally {
await this.percyScreenshotEnd(name, response?.body?.link, `${error}`);
await this.percyScreenshotEnd(name, response?.body?.link, sync, `${error}`);
}
return response;
}
Expand All @@ -84,19 +87,21 @@ class AppAutomateProvider extends GenericProvider {
return result;
} catch (e) {
log.debug(`[${name}] Could not mark App Automate session as percy`);
log.debug(`[${name}] ${e}`);
return null;
}
});
}

async percyScreenshotEnd(name, percyScreenshotUrl, statusMessage = null) {
async percyScreenshotEnd(name, percyScreenshotUrl, sync, statusMessage = null) {
return await TimeIt.run('percyScreenshotEnd', async () => {
try {
await this.browserstackExecutor('percyScreenshot', {
name,
percyScreenshotUrl,
status: percyScreenshotUrl ? 'success' : 'failure',
statusMessage,
sync,
state: 'end'
});
} catch (e) {
Expand Down Expand Up @@ -155,8 +160,8 @@ class AppAutomateProvider extends GenericProvider {
JSON.parse(response.result).forEach(tileData => {
tiles.push(new Tile({
statusBarHeight: statBarHeight,
navBarHeight: navBarHeight,
fullscreen: fullscreen,
navBarHeight,
fullscreen,
headerHeight: tileData.header_height,
footerHeight: tileData.footer_height,
sha: tileData.sha.split('-')[0] // drop build id
Expand Down
8 changes: 6 additions & 2 deletions percy/providers/genericProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ class GenericProvider {
considerRegionAppiumElements,
customConsiderRegions,
scrollableXpath,
scrollableId
scrollableId,
sync
}) {
fullscreen = fullscreen || false;
sync = sync || false;

this.metadata = await MetadataResolver.resolve(this.driver, {
deviceName,
Expand All @@ -76,6 +78,7 @@ class GenericProvider {
log.debug(`${name} : Tag ${JSON.stringify(tag)}`);
log.debug(`${name} : Tiles ${JSON.stringify(tiles)}`);
log.debug(`${name} : Debug url ${this.debugUrl}`);
log.debug(`${name} : sync ${sync}`);
return await utils.postComparison({
name,
tag,
Expand All @@ -88,7 +91,8 @@ class GenericProvider {
considerElementsData: considerRegions
},
environmentInfo: ENV_INFO,
clientInfo: CLIENT_INFO
clientInfo: CLIENT_INFO,
sync
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/percy/providers/appAutomateProvider.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('AppAutomateProvider', () => {

expect(percyScreenshotBeginSpy).toHaveBeenCalledWith('abc');
expect(superScreenshotSpy).toHaveBeenCalledWith('abc', jasmine.any(Object));
expect(percyScreenshotEndSpy).toHaveBeenCalledWith('abc', 'link to screenshot', 'undefined');
expect(percyScreenshotEndSpy).toHaveBeenCalledWith('abc', 'link to screenshot', false, 'undefined');
});

it('passes exception message to percyScreenshotEnd in case of exception', async () => {
Expand All @@ -47,7 +47,7 @@ describe('AppAutomateProvider', () => {
expect(percyScreenshotBeginSpy).toHaveBeenCalledWith('abc');

expect(percyScreenshotEndSpy).toHaveBeenCalledWith(
'abc', undefined, `Error: ${errorMessage}`);
'abc', undefined, false, `Error: ${errorMessage}`);
});
});

Expand Down
Loading

0 comments on commit faea883

Please sign in to comment.