Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Dpr fixes #1303

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/webdriver-utils/src/metadata/desktopMetaData.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class DesktopMetaData {
}

async screenResolution() {
const data = await this.driver.executeScript({ script: 'return [window.screen.width.toString(), window.screen.height.toString()];', args: [] });
const data = await this.driver.executeScript({ script: 'return [(window.screen.width * window.devicePixelRatio).toString(), (window.screen.height * window.devicePixelRatio).toString()];', args: [] });
const screenInfo = data.value;
return `${screenInfo[0]} x ${screenInfo[1]}`;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/webdriver-utils/src/metadata/mobileMetaData.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export default class MobileMetaData {
return { width, height };
}

async screenResolution() {
Copy link
Contributor

@itsjwala itsjwala Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should move this to parent class ( currently there isn't one present)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we don't have it we can create in upcoming times though.

const data = await this.driver.executeScript({ script: 'return [(window.screen.width * window.devicePixelRatio).toString(), (window.screen.height * window.devicePixelRatio).toString()];', args: [] });
const screenInfo = data.value;
return `${screenInfo[0]} x ${screenInfo[1]}`;
}

async devicePixelRatio() {
const devicePixelRatio = await this.driver.executeScript({ script: 'return window.devicePixelRatio;', args: [] });
return devicePixelRatio.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('DesktopMetaData', () => {
screenInfo = await desktopMetaData.screenResolution();
expect(screenInfo).toEqual('1980 x 1080');
expect(executeScriptSpy)
.toHaveBeenCalledWith({ script: 'return [window.screen.width.toString(), window.screen.height.toString()];', args: [] });
.toHaveBeenCalledWith({ script: 'return [(window.screen.width * window.devicePixelRatio).toString(), (window.screen.height * window.devicePixelRatio).toString()];', args: [] });
});
});
});
15 changes: 15 additions & 0 deletions packages/webdriver-utils/test/metadata/mobileMetaData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,19 @@ describe('MobileMetaData', () => {
.toHaveBeenCalledWith({ script: 'return window.devicePixelRatio;', args: [] });
});
});

describe('screenResolution', () => {
let screenInfo;

beforeEach(() => {
executeScriptSpy.and.returnValue(Promise.resolve({ value: ['1980', '1080'] }));
});

it('calclulates the screen resolution', async () => {
screenInfo = await mobileMetaData.screenResolution();
expect(screenInfo).toEqual('1980 x 1080');
expect(executeScriptSpy)
.toHaveBeenCalledWith({ script: 'return [(window.screen.width * window.devicePixelRatio).toString(), (window.screen.height * window.devicePixelRatio).toString()];', args: [] });
});
});
});
Loading