@@ -39,22 +39,12 @@ const commands = {
39
39
/**
40
40
* Get the window size
41
41
* @this {XCUITestDriver}
42
- * @deprecated Use { @linkcode XCUITestDriver.getWindowRect} instead.
42
+ * @returns { Promise<import('@appium/types').Size> }
43
43
*/
44
- async getWindowSize ( windowHandle = 'current' ) {
45
- if ( windowHandle !== 'current' ) {
46
- throw new errors . NotYetImplementedError (
47
- 'Currently only getting current window size is supported.' ,
48
- ) ;
49
- }
50
-
51
- if ( ! this . isWebContext ( ) ) {
52
- return await this . getWindowSizeNative ( ) ;
53
- } else {
54
- return await this . getWindowSizeWeb ( ) ;
55
- }
44
+ async getWindowSize ( ) {
45
+ const { width, height} = await this . getWindowRect ( ) ;
46
+ return { width, height} ;
56
47
} ,
57
-
58
48
/**
59
49
* Retrieves the actual device time.
60
50
*
@@ -116,15 +106,22 @@ const commands = {
116
106
/**
117
107
* For W3C
118
108
* @this {XCUITestDriver}
109
+ * @return {Promise<import('@appium/types').Rect> }
119
110
*/
120
111
async getWindowRect ( ) {
121
- const { width, height} = await this . getWindowSize ( ) ;
122
- return {
123
- width,
124
- height,
125
- x : 0 ,
126
- y : 0 ,
127
- } ;
112
+ if ( this . isWebContext ( ) ) {
113
+ const script = 'return {' +
114
+ 'x: window.screenX || 0,' +
115
+ 'y: window.screenY || 0,' +
116
+ 'width: window.innerWidth,' +
117
+ 'height: window.innerHeight' +
118
+ '}' ;
119
+ return await this . executeAtom ( 'execute_script' , [ script ] ) ;
120
+ }
121
+
122
+ return /** @type {import('@appium/types').Rect } */ (
123
+ await this . proxyCommand ( '/window/rect' , 'GET' )
124
+ ) ;
128
125
} ,
129
126
/**
130
127
* @this {XCUITestDriver}
@@ -181,7 +178,7 @@ const commands = {
181
178
const scale = await this . getDevicePixelRatio ( ) ;
182
179
// status bar height comes in unscaled, so scale it
183
180
const statusBarHeight = Math . round ( ( await this . getStatusBarHeight ( ) ) * scale ) ;
184
- const windowSize = await this . getWindowSize ( ) ;
181
+ const windowSize = await this . getWindowRect ( ) ;
185
182
186
183
// ios returns coordinates/dimensions in logical pixels, not device pixels,
187
184
// so scale up to device pixels. status bar height is already scaled.
@@ -260,23 +257,7 @@ const commands = {
260
257
} ,
261
258
} ;
262
259
263
- const helpers = {
264
- /**
265
- * @this {XCUITestDriver}
266
- */
267
- async getWindowSizeWeb ( ) {
268
- const script = 'return {width: window.innerWidth, height: window.innerHeight}' ;
269
- return await this . executeAtom ( 'execute_script' , [ script ] ) ;
270
- } ,
271
- /**
272
- * @this {XCUITestDriver}
273
- */
274
- async getWindowSizeNative ( ) {
275
- return await this . proxyCommand ( `/window/size` , 'GET' ) ;
276
- } ,
277
- } ;
278
-
279
- export default { ...helpers , ...commands } ;
260
+ export default commands ;
280
261
281
262
/**
282
263
* @typedef {Object } PressButtonOptions
0 commit comments