@christian-bromann/webdriverio
Version:
A nodejs bindings implementation for selenium 2.0/webdriver
64 lines (53 loc) • 2.02 kB
JavaScript
/**
*
* Protocol bindings to receive or change the position of the browser window.
* If the `windowHandle` URL parameter is falsy, the currently active window will be considered.
* (Not part of the official Webdriver specification).
*
* <example>
:windowHandlePosition.js
// get the position of
// a specified window
client.windowHandlePosition('{dc30381e-e2f3-9444-8bf3-12cc44e8372a}').then(function(res) { ... });
// the current window
client.windowHandlePosition().then(function(res) { ... });
// change the position of
// a specified window
client.windowHandlePosition('{dc30381e-e2f3-9444-8bf3-12cc44e8372a}', {x: 100, y: 200});
// the current window
client.windowHandlePosition({x: 100, y: 200});
* </example>
*
* @param {String=} windowHandle the window to receive/change the position
* @param {Object=} position the X and Y coordinates to position the window at, relative to the upper left corner of the screen
*
* @returns {Object} the X and Y coordinates for the window, relative to the upper left corner of the screen (`{x: number, y: number}`)
*
* @see https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidwindowwindowhandleposition
* @type protocol
*
*/
let windowHandlePosition = function (windowHandle, position) {
let data = {}
let requestOptions = {
method: 'POST'
}
if (typeof windowHandle !== 'string') {
position = windowHandle
windowHandle = 'current'
}
requestOptions.path = `/session/:sessionId/window/${windowHandle}/position`
/**
* check if arguments provide proper position parameter
*/
if (typeof position === 'object' && typeof position.x === 'number' && typeof position.y === 'number') {
data = position
/**
* otherwise fall back to get operation
*/
} else {
requestOptions.method = 'GET'
}
return this.requestHandler.create(requestOptions, data)
}
export default windowHandlePosition