Skip to content

Commit 61fc837

Browse files
committed
fix(screenshot): make screenshot DPI aware
1 parent 560eb87 commit 61fc837

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/commands/app.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ const GET_PAGE_SOURCE_COMMAND = pwsh$ /* ps1 */ `
3636
`;
3737

3838
const GET_SCREENSHOT_COMMAND = pwsh /* ps1 */ `
39+
if (-not ([System.Management.Automation.PSTypeName]'DpiAwareness').Type) {
40+
Add-Type @"
41+
using System.Runtime.InteropServices;
42+
public class DpiAwareness {
43+
[DllImport("user32.dll")] public static extern bool SetProcessDPIAware();
44+
}
45+
"@
46+
}
47+
[DpiAwareness]::SetProcessDPIAware() | Out-Null
48+
3949
if ($rootElement -eq $null) {
4050
$bitmap = New-Object Drawing.Bitmap 1,1
4151
$stream = New-Object IO.MemoryStream

test/e2e/window.e2e.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,28 @@ describe('Window and app management commands', () => {
103103
expect(buffer[3]).toBe(0x47); // G
104104
});
105105
});
106+
107+
describe('DPI scaling consistency', () => {
108+
it('screenshot pixel dimensions match getWindowRect width and height', async () => {
109+
const rect = await calc.getWindowRect();
110+
const screenshot = await calc.takeScreenshot();
111+
const buffer = Buffer.from(screenshot, 'base64');
112+
113+
// PNG IHDR chunk: width at bytes 16-19, height at 20-23 (big-endian uint32)
114+
const pngWidth = buffer.readUInt32BE(16);
115+
const pngHeight = buffer.readUInt32BE(20);
116+
117+
expect(pngWidth).toBe(rect.width);
118+
expect(pngHeight).toBe(rect.height);
119+
});
120+
121+
it('element rect fits within window bounds', async () => {
122+
const windowRect = await calc.getWindowRect();
123+
const btn = await calc.$('~num1Button');
124+
const btnSize = await btn.getSize();
125+
126+
expect(btnSize.width).toBeLessThanOrEqual(windowRect.width);
127+
expect(btnSize.height).toBeLessThanOrEqual(windowRect.height);
128+
});
129+
});
106130
});

0 commit comments

Comments
 (0)