Skip to content

Commit

Permalink
Adding coverage for specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit3200 committed Sep 30, 2024
1 parent 3b8363f commit 42aa3b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function changeWindowDimensionAndWait(driver, width, height, resizeCount)
}

// Captures responsive DOM snapshots across different widths
async function captureResponsiveDOM(driver, options = {}) {
async function captureResponsiveDOM(driver, options) {
const widths = getWidthsForMultiDOM(options.widths || [], utils.percy?.widths);
const domSnapshots = [];
const windowSize = await driver.manage().window().getRect();
Expand Down
22 changes: 18 additions & 4 deletions test/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,21 @@ describe('percySnapshot', () => {
expect(error).toEqual('Invalid function call - percySnapshot(). Please use percyScreenshot() function while using Percy with Automate. For more information on usage of percyScreenshot, refer https://www.browserstack.com/docs/percy/integrate/functional-and-visual');
});

it('posts snapshots to percy server with responsiveSnapshotCapture', async () => {
await percySnapshot(driver, 'Snapshot 1', { responsiveSnapshotCapture: true, widths: [375, 1280] });
it('posts snapshots to percy server with responsiveSnapshotCapture true', async () => {
await driver.manage().window().setRect({ width: 1380, height: 1024 });
await percySnapshot(driver, 'Snapshot 1', { responsiveSnapshotCapture: true, widths: [1380] });

expect(await helpers.get('logs')).toEqual(jasmine.arrayContaining([
'Snapshot found: Snapshot 1',
`- url: ${helpers.testSnapshotURL}`,
jasmine.stringMatching(/clientInfo: @percy\/selenium-webdriver\/.+/),
jasmine.stringMatching(/environmentInfo: selenium-webdriver\/.+/)
]));
});

it('posts snapshots to percy server with responsiveSnapshotCapture false', async () => {
await percySnapshot(driver, 'Snapshot 1', { responsiveSnapshotCapture: false, widths: [1380] });

expect(await helpers.get('logs')).toEqual(jasmine.arrayContaining([
'Snapshot found: Snapshot 1',
`- url: ${helpers.testSnapshotURL}`,
Expand All @@ -110,8 +123,9 @@ describe('percySnapshot', () => {

it('posts snapshots to percy server with responsiveSnapshotCapture with mobile', async () => {
spyOn(percySnapshot, 'isPercyEnabled').and.returnValue(Promise.resolve(true));
utils.percy.widths = { mobile: [1125], widths: [375, 1280] };
utils.percy.widths = { mobile: [1125], widths: [1280] };

await driver.manage().window().setRect({ width: 1280, height: 1024 });
await percySnapshot(driver, 'Snapshot 1', { responsiveSnapshotCapture: true });

expect(await helpers.get('logs')).toEqual(jasmine.arrayContaining([
Expand All @@ -125,7 +139,7 @@ describe('percySnapshot', () => {
it('should call executeCdpCommand for chrome and not setRect', async () => {
spyOn(mockedDriver, 'executeCdpCommand').and.callThrough();
spyOn(mockedDriver.manage().window(), 'setRect').and.callThrough();
utils.percy.widths = { mobile: [1125], widths: [375, 1280] };
utils.percy.widths = { mobile: [], widths: [1280] };

await percySnapshot(mockedDriver, 'Test Snapshot', { responsiveSnapshotCapture: true });

Expand Down

0 comments on commit 42aa3b4

Please sign in to comment.