diff --git a/index.js b/index.js index e0b0296..a65431a 100644 --- a/index.js +++ b/index.js @@ -80,7 +80,8 @@ module.exports = async function percyScreenshot(driver, name, options = {}) { return TimeIt.run('percyScreenshot', async () => { try { if (utils.percy?.type === 'automate') { - return await percyOnAutomate(driver, name, options); + const percyOnAutomateResponse = await percyOnAutomate(driver, name, options); + return percyOnAutomateResponse.data; } const provider = ProviderResolver.resolve(driver); const response = await provider.screenshot(name, { @@ -106,7 +107,7 @@ module.exports = async function percyScreenshot(driver, name, options = {}) { sync }); log.debug(`[${name}] -> end`); - return response; + return response.data; } catch (e) { log.error(`[${name}] failed to take screenshot`); log.debug(`[${name}] ${e}, \n ${e.stack}`); diff --git a/percy/percyOnAutomate.js b/percy/percyOnAutomate.js index f7dbeb6..d44a559 100644 --- a/percy/percyOnAutomate.js +++ b/percy/percyOnAutomate.js @@ -58,7 +58,7 @@ module.exports = async function percyOnAutomate(driver, name, options) { } // Post the driver details to the automate screenshot endpoint with snapshot options and other info - await module.exports.request({ + return await module.exports.request({ environmentInfo: ENV_INFO, clientInfo: CLIENT_INFO, sessionId, @@ -78,5 +78,5 @@ module.exports = async function percyOnAutomate(driver, name, options) { /* istanbul ignore next */ // since can't test this function module.exports.request = async function request(data) { - await utils.captureAutomateScreenshot(data); + return await utils.captureAutomateScreenshot(data); }; // To mock in test case diff --git a/percy/providers/appAutomateProvider.js b/percy/providers/appAutomateProvider.js index 7b36771..68f61fb 100644 --- a/percy/providers/appAutomateProvider.js +++ b/percy/providers/appAutomateProvider.js @@ -38,7 +38,7 @@ class AppAutomateProvider extends GenericProvider { } = {}) { let response = null; let error; - sync = sync || false; + sync = sync || null; try { let result = await this.percyScreenshotBegin(name); this.setDebugUrl(result); diff --git a/percy/providers/genericProvider.js b/percy/providers/genericProvider.js index 721b6e6..86ffe02 100644 --- a/percy/providers/genericProvider.js +++ b/percy/providers/genericProvider.js @@ -55,7 +55,7 @@ class GenericProvider { sync }) { fullscreen = fullscreen || false; - sync = sync || false; + sync = sync || null; this.metadata = await MetadataResolver.resolve(this.driver, { deviceName, diff --git a/test/index.test.mjs b/test/index.test.mjs index 8cb966d..e120f88 100644 --- a/test/index.test.mjs +++ b/test/index.test.mjs @@ -244,36 +244,44 @@ describe('percyScreenshot', () => { const driver = driverFunc({ enabled: true }); spyOn(percyScreenshot, 'isPercyEnabled').and.returnValue(Promise.resolve(true)) utils.percy.type = 'automate'; - spyOn(percyOnAutomate, 'request').and.callFake(() => {}); + const mockresponse = {}; + spyOn(percyOnAutomate, 'request').and.callFake(() => mockresponse); - await percyScreenshot(driver, 'Screenshot 1'); + const response = await percyScreenshot(driver, 'Screenshot 1'); expect(percyOnAutomate.request).toHaveBeenCalledWith(jasmine.objectContaining({ sessionId: 'sessionID', commandExecutorUrl: 'https://localhost/wd/hub', snapshotName: 'Screenshot 1' })); + + expect(response).toEqual(undefined); }); - it('should call POA percyScreenshot with ignoreRegion and considerRegion', async () => { + it('should call POA percyScreenshot with ignoreRegion and considerRegion and sync', async () => { const element = { value: '123', elementId: '123' }; const element2 = { value: '456', elementId: '456' }; const driver = driverFunc({ enabled: true }); spyOn(percyScreenshot, 'isPercyEnabled').and.returnValue(Promise.resolve(true)) utils.percy.type = 'automate'; - spyOn(percyOnAutomate, 'request').and.callFake(() => {}); + const mockresponse = { + success: 'true', + data: 'sync_data' + }; + const mockedPostCall = spyOn(percyOnAutomate, 'request').and.callFake(() => mockresponse); await percyScreenshot(driver, 'Screenshot 2', { - ignore_region_appium_elements: [element], consider_region_appium_elements: [element] + ignore_region_appium_elements: [element], consider_region_appium_elements: [element], sync: true }); - expect(percyOnAutomate.request).toHaveBeenCalledWith(jasmine.objectContaining({ + expect(mockedPostCall).toHaveBeenCalledWith(jasmine.objectContaining({ sessionId: 'sessionID', commandExecutorUrl: 'https://localhost/wd/hub', snapshotName: 'Screenshot 2', options: { ignore_region_elements: ['123'], - consider_region_elements: ['123'] + consider_region_elements: ['123'], + sync: true } })); - await percyScreenshot(driver, 'Screenshot 3', { + const data = await percyScreenshot(driver, 'Screenshot 3', { ignoreRegionAppiumElements: [element2], considerRegionAppiumElements: [element2] }); expect(percyOnAutomate.request).toHaveBeenCalledWith(jasmine.objectContaining({ @@ -285,6 +293,8 @@ describe('percyScreenshot', () => { consider_region_elements: ['456'] } })); + + expect(data).toEqual(mockresponse.data); }); it('should handle error POA', async () => { diff --git a/test/percy/providers/appAutomateProvider.test.mjs b/test/percy/providers/appAutomateProvider.test.mjs index 99ed02a..84f216a 100644 --- a/test/percy/providers/appAutomateProvider.test.mjs +++ b/test/percy/providers/appAutomateProvider.test.mjs @@ -33,7 +33,7 @@ describe('AppAutomateProvider', () => { expect(percyScreenshotBeginSpy).toHaveBeenCalledWith('abc'); expect(superScreenshotSpy).toHaveBeenCalledWith('abc', jasmine.any(Object)); - expect(percyScreenshotEndSpy).toHaveBeenCalledWith('abc', 'link to screenshot', false, 'undefined'); + expect(percyScreenshotEndSpy).toHaveBeenCalledWith('abc', 'link to screenshot', null, 'undefined'); }); it('passes exception message to percyScreenshotEnd in case of exception', async () => { @@ -47,7 +47,7 @@ describe('AppAutomateProvider', () => { expect(percyScreenshotBeginSpy).toHaveBeenCalledWith('abc'); expect(percyScreenshotEndSpy).toHaveBeenCalledWith( - 'abc', undefined, false, `Error: ${errorMessage}`); + 'abc', undefined, null, `Error: ${errorMessage}`); }); });