Skip to content

Commit

Permalink
[node] Adding support for opening a new window. Referencing existing …
Browse files Browse the repository at this point in the history
…implementations.

Signed-off-by: Alexei Barantsev <barancev@gmail.com>
  • Loading branch information
corevo authored and barancev committed Apr 13, 2019
1 parent 2528532 commit 59e5bf2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions javascript/node/selenium-webdriver/lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const Name = {
FULLSCREEN_WINDOW: 'fullscreenWindow',

SWITCH_TO_WINDOW: 'switchToWindow',
SWITCH_TO_NEW_WINDOW: 'newWindow',
SWITCH_TO_FRAME: 'switchToFrame',
SWITCH_TO_FRAME_PARENT: 'switchToFrameParent',
GET_PAGE_SOURCE: 'getPageSource',
Expand Down
1 change: 1 addition & 0 deletions javascript/node/selenium-webdriver/lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ const W3C_COMMAND_MAP = new Map([
[cmd.Name.GET_CURRENT_WINDOW_HANDLE, get('/session/:sessionId/window')],
[cmd.Name.CLOSE, del('/session/:sessionId/window')],
[cmd.Name.SWITCH_TO_WINDOW, post('/session/:sessionId/window')],
[cmd.Name.SWITCH_TO_NEW_WINDOW, post('/session/:sessionId/window/new')],
[cmd.Name.GET_WINDOW_HANDLES, get('/session/:sessionId/window/handles')],
[cmd.Name.GET_WINDOW_RECT, get('/session/:sessionId/window/rect')],
[cmd.Name.SET_WINDOW_RECT, post('/session/:sessionId/window/rect')],
Expand Down
20 changes: 20 additions & 0 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,26 @@ class TargetLocator {
setParameter('handle', nameOrHandle));
}

/**
* Creates a new browser window and switches the focus for future
* commands of this driver to the new window.
*
* @param {string} typeHint 'window' or 'tab'. The created window is not
* guaranteed to be of the requested type; if the driver does not support
* the requested type, a new browser window will be created of whatever type
* the driver does support.
* @return {!Promise<void>} A promise that will be resolved
* when the driver has changed focus to the new window.
*/
newWindow(typeHint) {
var driver = this.driver_
return this.driver_.execute(
new command.Command(command.Name.SWITCH_TO_NEW_WINDOW).
setParameter('type', typeHint)).then(function(response) {
return driver.switchTo().window(response.handle);
});
}

/**
* Changes focus to the active modal dialog, such as those opened by
* `window.alert()`, `window.confirm()`, and `window.prompt()`. The returned
Expand Down
8 changes: 8 additions & 0 deletions javascript/node/selenium-webdriver/test/window_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ test.suite(function(env) {
return driver.wait(forPositionToBe(x, y), 1000);
});

it('can open a new window', async function() {
const originalHandle = await driver.getWindowHandle()
await driver.switchTo().newWindow()

assert.equal((await driver.getAllWindowHandles()).length, 2)
assert.notEqual(originalHandles, await driver.getWindowHandle())
})

async function changeSizeBy(dx, dy) {
let {width, height} = await driver.manage().window().getRect();
width += dx;
Expand Down

0 comments on commit 59e5bf2

Please sign in to comment.