Skip to content

Commit

Permalink
New API to Resize window (#1793)
Browse files Browse the repository at this point in the history
* Resize browser window


Signed-off-by: saikrishna321 <[email protected]>
  • Loading branch information
saikrishna321 authored Jan 15, 2021
1 parent 58994f8 commit 2af5fb3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/handlers/browserHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ const overridePermissions = async (origin, permissions) => {
}
};

const setWindowBounds = async (targetId, height, width) => {
const { windowId } = await _browser.getWindowForTarget({ targetId });
await _browser.setWindowBounds({
bounds: { height, width },
windowId,
});
};

const clearPermissionOverrides = async () => {
await _browser.resetPermissions();
};

module.exports = { clearPermissionOverrides, overridePermissions };
module.exports = { clearPermissionOverrides, overridePermissions, setWindowBounds };
18 changes: 18 additions & 0 deletions lib/taiko.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,23 @@ module.exports.deleteCookies = async (cookieName, options = {}) => {
}
};

/**
* Resize the browser window
*
* @example
* await resizeWindow({width:600, height:800})
*
* @returns {Promise<void>}
*/
module.exports.resizeWindow = async (options = {}) => {
validate();
if (options.height === undefined || options.width === undefined) {
throw new Error('Please specify the window height and width');
}
const [{ targetId }] = await targetHandler.getFirstAvailablePageTarget();
await browserHandler.setWindowBounds(targetId, options.height, options.width);
descEvent.emit('success', `Window resized to height ${ options.height } and width ${ options.width }`);
};
/**
* Get browser cookies
*
Expand Down Expand Up @@ -2616,6 +2633,7 @@ module.exports.metadata = {
'emulateNetwork',
'emulateDevice',
'setViewPort',
'resizeWindow',
'openTab',
'closeTab',
'openIncognitoWindow',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package",
"name": "taiko",
"version": "1.1.2",
"version": "1.1.3",
"description": "Taiko is a Node.js library for automating Chromium based browsers",
"main": "bin/taiko.js",
"bin": {
Expand Down
6 changes: 6 additions & 0 deletions types/taiko/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export interface CookieOptions {
path?: string;
}

export interface ResizeWindowOptions {
height?: string;
width?: string;
}

export interface CookieDetailOptions extends CookieOptions {
secure?: boolean;
httpOnly?: boolean;
Expand Down Expand Up @@ -389,6 +394,7 @@ export function emulateNetwork(
export function emulateDevice(deviceModel: string): Promise<void>;
// https://docs.taiko.dev/api/setviewport
export function setViewPort(options: ViewPortOptions): Promise<void>;
export function resizeWindow(options: ResizeWindowOptions): Promise<void>;
// https://docs.taiko.dev/api/emulateTimezone
export function emulateTimezone(timezoneId: string): Promise<void>;
// https://docs.taiko.dev/api/opentab
Expand Down

0 comments on commit 2af5fb3

Please sign in to comment.