Skip to content

Commit 2ac53b8

Browse files
committed
[JS] Add window wrappers getSize and setSize
1 parent 3f70670 commit 2ac53b8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,37 @@ class Window {
21532153
new command.Command(command.Name.FULLSCREEN_WINDOW)
21542154
)
21552155
}
2156+
2157+
/**
2158+
* Gets the width and height of the current window
2159+
* @param windowHandle
2160+
* @returns {Promise<{width: *, height: *}>}
2161+
*/
2162+
async getSize(windowHandle = 'current') {
2163+
if (windowHandle !== 'current') {
2164+
console.warn(`Only 'current' window is supported for W3C compatible browsers.`);
2165+
}
2166+
2167+
const rect = await this.getRect();
2168+
return {height: rect.height, width: rect.width};
2169+
}
2170+
2171+
/**
2172+
* Sets the width and height of the current window. (window.resizeTo)
2173+
* @param x
2174+
* @param y
2175+
* @param width
2176+
* @param height
2177+
* @param windowHandle
2178+
* @returns {Promise<void>}
2179+
*/
2180+
async setSize({x = 0, y = 0, width = 0, height = 0}, windowHandle = 'current') {
2181+
if (windowHandle !== 'current') {
2182+
console.warn(`Only 'current' window is supported for W3C compatible browsers.`);
2183+
}
2184+
2185+
await this.setRect({x, y, width, height});
2186+
}
21562187
}
21572188

21582189
/**

0 commit comments

Comments
 (0)