Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getWindowSize command #3979

Merged
merged 1 commit into from May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/webdriver/protocol/jsonwp.json
Expand Up @@ -273,7 +273,7 @@
},
"/session/:sessionId/window/current/size": {
"GET": {
"command": "getWindowSize",
"command": "_getWindowSize",
"description": "Get the size of the current focused window.",
"ref": "https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#get-sessionsessionidwindowwindowhandlesize",
"parameters": [],
Expand Down
31 changes: 31 additions & 0 deletions packages/webdriverio/src/commands/browser/getWindowSize.js
@@ -0,0 +1,31 @@
/**
*
* Returns browser window size (and position for drivers with W3C support).
*
* <example>
* :getWindowSize.js
it('should return browser window size', function () {
const windowSize = browser.getWindowSize(500, 600);
console.log(windowSize);
// outputs
// Firefox: { x: 4, y: 23, width: 1280, height: 767 }
// Chrome: { width: 1280, height: 767 }
});
* </example>
*
* @alias browser.getWindowSize
* @return {Object} { x, y, width, height } for W3C or { width, height } for non W3C browser
* @type window
*
*/

import { getBrowserObject } from '../../utils'

export default function getWindowSize() {
const browser = getBrowserObject(this)

if (!browser.isW3C) {
return browser._getWindowSize()
}
return browser.getWindowRect()
}
38 changes: 38 additions & 0 deletions packages/webdriverio/tests/commands/browser/getWindowSize.test.js
@@ -0,0 +1,38 @@
import request from 'request'
import { remote } from '../../../src'

describe('getWindowSize', () => {
let browser

beforeAll(async () => {
browser = await remote({
baseUrl: 'http://foobar.com',
capabilities: {
browserName: 'foobar'
}
})
})

it('should get size of W3C browser window', async () => {
await browser.getWindowSize()
expect(request.mock.calls[1][0].method).toBe('GET')
expect(request.mock.calls[1][0].uri.path).toBe('/wd/hub/session/foobar-123/window/rect')
})

it('should get size of NO-W3C browser window', async () => {
browser = await remote({
baseUrl: 'http://foobar.com',
capabilities: {
browserName: 'foobar-noW3C'
}
})

await browser.getWindowSize()
expect(request.mock.calls[1][0].method).toBe('GET')
expect(request.mock.calls[1][0].uri.path).toBe('/wd/hub/session/foobar-123/window/current/size')
})

afterEach(() => {
request.mockClear()
})
})