Skip to content

Commit

Permalink
[JS][bidi] Impelments functionality to retrieve all top-level browsin…
Browse files Browse the repository at this point in the history
…g contexts
  • Loading branch information
harsha509 committed Apr 2, 2024
1 parent ef3d9e8 commit a169d90
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
26 changes: 26 additions & 0 deletions javascript/node/selenium-webdriver/bidi/browsingContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ class BrowsingContext {
return new BrowsingContextInfo(result['context'], result['url'], result['children'], result['parent'])
}

/**
* @returns {Promise<Array<BrowsingContextInfo>>} A Promise that resolves to an array of BrowsingContextInfo objects representing the top-level browsing contexts.
*/
async getTopLevelContexts() {
const params = {
method: 'browsingContext.getTree',
params: {},
}

let result = await this.bidi.send(params)
if ('error' in result) {
throw Error(result['error'])
}

const contexts = result['result']['contexts'];
const browsingContexts = contexts.map(context => {
return new BrowsingContextInfo(
context['id'],
context['url'],
context['children'],
context['parent']
);
});
return browsingContexts;
}

/**
* Closes the browsing context
* @returns {Promise<void>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,18 @@ suite(

const devicePixelRatio = await driver.executeScript('return window.devicePixelRatio;')
assert.equal(devicePixelRatio, 5)
})
});

it('Get All Top level browsing contexts', async ()=> {
const id = await driver.getWindowHandle()
const window1 = await BrowsingContext(driver, {
browsingContextId: id,
});
const window2 = await BrowsingContext(driver, {type: 'window'});

const res = await window1.getTopLevelContexts();
assert.equal(res.length, 2);
});
})
},
{ browsers: [Browser.FIREFOX] },
Expand Down

0 comments on commit a169d90

Please sign in to comment.