-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetWindowRect.ts
30 lines (24 loc) · 891 Bytes
/
setWindowRect.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { Rect } from '@appium/types';
import type { Driver } from '../Driver.js';
import { InvalidArgument } from '../errors/InvalidArgument.js';
export function setWindowRect(this: Driver, x?: number, y?: number, width?: number, height?: number): Rect {
const hasX = typeof x === 'number';
const hasY = typeof y === 'number';
const hasWidth = typeof width === 'number';
const hasHeight = typeof height === 'number';
if (hasWidth && width < 0) {
throw InvalidArgument(`width must be a positive number, but got ${width}`);
}
if (hasHeight && height < 0) {
throw InvalidArgument(`height must be a positive number, but got ${height}`);
}
for (let i = 0; i < 3; i++) {
if (hasX && hasY) {
this.topContext.moveTo(x, y);
}
if (hasWidth && hasHeight) {
this.topContext.resizeTo(width, height);
}
}
return this.getWindowRect();
}