From 1798bbaedff9ed3de9bfaf9b1e39abed48e91ac8 Mon Sep 17 00:00:00 2001 From: Priyanka0613 <95872454+Priyanka0613@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:57:55 +0530 Subject: [PATCH] Add types for `chrome` namespace commands (#3790) * Add types for Chrome namespace commands * added 'setNetwork' type * Fix types and add proper TSDoc. --------- Co-authored-by: Priyansh Garg --- lib/api/_loaders/chrome.js | 1 + types/index.d.ts | 145 +++++++++++++++++++++++++++++++++++-- 2 files changed, 140 insertions(+), 6 deletions(-) diff --git a/lib/api/_loaders/chrome.js b/lib/api/_loaders/chrome.js index 2e8064d279..fdb3a57443 100644 --- a/lib/api/_loaders/chrome.js +++ b/lib/api/_loaders/chrome.js @@ -6,6 +6,7 @@ class ChromeCommandLoader extends BaseLoader { 'launchApp', 'getNetworkConditions', 'setNetworkConditions', + 'deleteNetworkConditions', 'sendDevToolsCommand', 'sendAndGetDevToolsCommand', 'setPermission', diff --git a/types/index.d.ts b/types/index.d.ts index baab012a8c..bf95a5ce60 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -500,6 +500,7 @@ export interface NamespacedApi { logs: LogsNsCommands; window: WindowNsCommands; firefox: FirefoxNsCommands; + chrome: ChromeNsCommands; network: NetworkNsCommands; assert: Assert; @@ -5062,6 +5063,142 @@ export interface FirefoxNsCommands { uninstallAddon(addonId: string | PromiseLike): Awaitable, null>; } +type NetworkConditionsSpec = { + offline: boolean, + latency: number, + download_throughput: number, + upload_throughput: number +}; + +export interface ChromeNsCommands{ + /** + * Launch Chrome App with given ID. + * @param id ID of the App to launch. + */ + launchApp( + id: string + ): Awaitable, null>; + + /** + * Get Chromium network emulation settings. + * + * Network conditions must be set before it can be retrieved. + */ + getNetworkConditions(): Awaitable, NetworkConditionsSpec>; + + /** + * Set Chromium network emulation settings. + * + * @example + * describe('set network conditions', function() { + * it('sets the network conditions', function() { + * browser + * .chrome.setNetworkConditions({ + * offline: false, + * latency: 5, // Additional latency (ms). + * download_throughput: 500 * 1024, // Maximal aggregated download throughput. + * upload_throughput: 500 * 1024 // Maximal aggregated upload throughput. + * }); + * }); + * }); + * + * @param spec Defines the network conditions to set + */ + setNetworkConditions( + spec: NetworkConditionsSpec + ): Awaitable, null>; + + /** + * Delete Chromium network emulation settings. + */ + deleteNetworkConditions(): Awaitable, null>; + + /** + * Sends an arbitrary devtools command to the browser. + * + * @param cmd The name of the command to send. + * @param params The command parameters. + * @see + */ + sendDevToolsCommand( + cmd: string, + params?: {[key: string]: any} + ): Awaitable, null>; + + /** + * Sends an arbitrary devtools command to the browser and get the result. + * + * @param cmd The name of the command to send. + * @param params The command parameters. + * @see + */ + sendAndGetDevToolsCommand( + cmd: string, + params?: {[key: string]: any} + ): Awaitable, unknown>; + + /** + * Set a permission state to the given value. + * + * @param name A name of the permission to update. + * @param state State to set permission to. + * @see for valid names + */ + setPermission( + name: string, + state: 'granted' | 'denied' | 'prompt' + ): Awaitable, null>; + + /** + * Sends a DevTools command to change the browser's download directory. + * + * @param path The desired download directory. + * @see chrome.sendDevToolsCommand + */ + setDownloadPath( + path: string + ): Awaitable, null>; + + /** + * Returns the list of cast sinks (Cast devices) available to the Chrome media router. + * + * @return An array of Strings containing the friendly device names of available cast sink targets. + */ + getCastSinks(): Awaitable, string[]>; + + /** + * Selects a cast sink (Cast device) as the recipient of media router intents (connect or play). + * + * @param deviceName name of the target device. + */ + setCastSinkToUse( + deviceName: string + ): Awaitable, null>; + + /** + * Initiates tab mirroring for the current browser tab on the specified device. + * + * @param deviceName name of the target device. + */ + startCastTabMirroring( + deviceName: string + ): Awaitable, null>; + + /** + * Returns an error message when there is any issue in a Cast session. + */ + getCastIssueMessage(): Awaitable, string>; + + /** + * Stops casting from media router to the specified device, if connected. + * + * @param deviceName name of the target device. + */ + stopCasting( + deviceName: string + ): Awaitable, null>; +} + export interface NetworkNsCommands { /** * Capture outgoing network calls from the browser. @@ -5146,12 +5283,7 @@ export interface NetworkNsCommands { * @see https://nightwatchjs.org/api/setNetworkConditions.html */ setConditions( - spec: { - offline: boolean; - latency: number; - download_throughput: number; - upload_throughput: number; - }, + spec: NetworkConditionsSpec, callback?: ( this: NightwatchAPI, result: NightwatchCallbackResult @@ -7655,6 +7787,7 @@ export const alerts: AlertsNsCommands; export const document: DocumentNsCommands; export const window: WindowNsCommands; export const firefox: FirefoxNsCommands; +export const chrome: ChromeNsCommands; export const assert: Assert; export const verify: Assert;