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

[@types/selenium-webdriver]: split Chromium into a new file #69487

Merged
merged 12 commits into from
May 31, 2024
3 changes: 2 additions & 1 deletion types/selenium-webdriver/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"@definitelytyped/no-unnecessary-generics": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/naming-convention": "off"
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/array-type": "off"
sangcnguyen marked this conversation as resolved.
Show resolved Hide resolved
}
}
276 changes: 15 additions & 261 deletions types/selenium-webdriver/chrome.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as remote from "./remote";
/**
* Creates a new WebDriver client for Chrome.
*/
export class Driver extends webdriver.ChromiumWebDriver {
export class Driver extends webdriver.chromium.Driver {
sangcnguyen marked this conversation as resolved.
Show resolved Hide resolved
/**
* Creates a new session with the ChromeDriver.
*
Expand All @@ -18,9 +18,15 @@ export class Driver extends webdriver.ChromiumWebDriver {
* @return {!Driver} A new driver instance.
*/
static createSession(
opt_config?: Options | webdriver.CreateSessionCapabilities,
opt_service?: remote.DriverService | http.Executor,
opt_config?: Options | webdriver.Capabilities,
opt_serviceExecutor?: remote.DriverService | http.Executor,
): Driver;

/**
* returns new instance chrome driver service
* @returns {remote.DriverService}
*/
static getDefaultService(): remote.DriverService;
}

export interface IOptionsValues {
Expand All @@ -44,67 +50,7 @@ export interface IPerfLoggingPrefs {
/**
* Class for managing ChromeDriver specific options.
*/
export class Options extends webdriver.Capabilities {
/** */
constructor();

/**
* Extracts the ChromeDriver specific options from the given capabilities
* object.
* @param {!webdriver.Capabilities} capabilities The capabilities object.
* @return {!Options} The ChromeDriver options.
*/
static fromCapabilities(capabilities: webdriver.Capabilities): Options;

/**
* Add additional command line arguments to use when launching the Chrome
* browser. Each argument may be specified with or without the '--' prefix
* (e.g. '--foo' and 'foo'). Arguments with an associated value should be
* delimited by an '=': 'foo=bar'.
* @param {...(string|!Array.<string>)} var_args The arguments to add.
* @return {!Options} A self reference.
*/
addArguments(...var_args: string[]): Options;

/**
* Sets the address of a Chromium remote debugging server to connect to.
* Address should be of the form "{hostname|IP address}:port"
* (e.g. "localhost:9222").
*
* @param {string} address The address to connect to.
* @return {!Options} A self reference.
*/
debuggerAddress(address: string): Options;

/**
* Sets the initial window size.
*
* @param {{width: number, height: number}} size The desired window size.
* @return {!Options} A self reference.
* @throws {TypeError} if width or height is unspecified, not a number, or
* less than or equal to 0.
*/
windowSize(size: { width: number; height: number }): Options;

/**
* List of Chrome command line switches to exclude that ChromeDriver by
* default passes when starting Chrome. Do not prefix switches with '--'.
*
* @param {...(string|!Array<string>)} var_args The switches to exclude.
* @return {!Options} A self reference.
*/
excludeSwitches(...var_args: string[]): Options;

/**
* Add additional extensions to install when launching Chrome. Each extension
* should be specified as the path to the packed CRX file, or a Buffer for an
* extension.
* @param {...(string|!Buffer|!Array.<(string|!Buffer)>)} var_args The
* extensions to add.
* @return {!Options} A self reference.
*/
addExtensions(...var_args: any[]): Options;

export class Options extends webdriver.chromium.Options {
/**
* Sets the path to the Chrome binary to use. On Mac OS X, this path should
* reference the actual Chrome executable, not just the application binary
Expand All @@ -118,78 +64,6 @@ export class Options extends webdriver.Capabilities {
*/
setChromeBinaryPath(path: string): Options;

/**
* Sets whether to leave the started Chrome browser running if the controlling
* ChromeDriver service is killed before {@link webdriver.WebDriver#quit()} is
* called.
* @param {boolean} detach Whether to leave the browser running if the
* chromedriver service is killed before the session.
* @return {!Options} A self reference.
*/
detachDriver(detach: boolean): Options;

/**
* Sets the user preferences for Chrome's user profile. See the 'Preferences'
* file in Chrome's user data directory for examples.
* @param {!Object} prefs Dictionary of user preferences to use.
* @return {!Options} A self reference.
*/
setUserPreferences(prefs: any): Options;

/**
* Sets the performance logging preferences. Options include:
*
* - `enableNetwork`: Whether or not to collect events from Network domain.
* - `enablePage`: Whether or not to collect events from Page domain.
* - `enableTimeline`: Whether or not to collect events from Timeline domain.
* Note: when tracing is enabled, Timeline domain is implicitly disabled,
* unless `enableTimeline` is explicitly set to true.
* - `tracingCategories`: A comma-separated string of Chrome tracing
* categories for which trace events should be collected. An unspecified or
* empty string disables tracing.
* - `bufferUsageReportingInterval`: The requested number of milliseconds
* between DevTools trace buffer usage events. For example, if 1000, then
* once per second, DevTools will report how full the trace buffer is. If
* a report indicates the buffer usage is 100%, a warning will be issued.
*
* @param {{enableNetwork: boolean,
* enablePage: boolean,
* enableTimeline: boolean,
* tracingCategories: string,
* bufferUsageReportingInterval: number}} prefs The performance
* logging preferences.
* @return {!Options} A self reference.
*/
setPerfLoggingPrefs(prefs: IPerfLoggingPrefs): Options;

/**
* Sets preferences for the 'Local State' file in Chrome's user data
* directory.
* @param {!Object} state Dictionary of local state preferences.
* @return {!Options} A self reference.
*/
setLocalState(state: any): Options;

/**
* Sets the name of the activity hosting a Chrome-based Android WebView. This
* option must be set to connect to an [Android WebView](
* https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started---android)
*
* @param {string} name The activity name.
* @return {!Options} A self reference.
*/
androidActivity(name: string): Options;

/**
* Sets the device serial number to connect to via ADB. If not specified, the
* ChromeDriver will select an unused device at random. An error will be
* returned if all devices already have active sessions.
*
* @param {string} serial The device serial number to connect to.
* @return {!Options} A self reference.
*/
androidDeviceSerial(serial: string): Options;

/**
* Configures the ChromeDriver to launch Chrome on Android via adb. This
* function is shorthand for
Expand All @@ -198,35 +72,6 @@ export class Options extends webdriver.Capabilities {
*/
androidChrome(): Options;

/**
* Sets the package name of the Chrome or WebView app.
*
* @param {?string} pkg The package to connect to, or `null` to disable
* Android and switch back to using desktop Chrome.
* @return {!Options} A self reference.
*/
androidPackage(pkg: string): Options;

/**
* Sets the process name of the Activity hosting the WebView (as given by
* `ps`). If not specified, the process name is assumed to be the same as
* {@link #androidPackage}.
*
* @param {string} processName The main activity name.
* @return {!Options} A self reference.
*/
androidProcess(processName: string): Options;

/**
* Sets whether to connect to an already-running instead of the specified
* {@linkplain #androidProcess app} instead of launching the app with a clean
* data directory.
*
* @param {boolean} useRunning Whether to connect to a running instance.
* @return {!Options} A self reference.
*/
androidUseRunningApp(useRunning: boolean): Options;

/**
* Sets the path to Chrome's log file. This path should exist on the machine
* that will launch Chrome.
Expand All @@ -242,50 +87,14 @@ export class Options extends webdriver.Capabilities {
* @return {!Options} A self reference.
*/
setChromeMinidumpPath(path: string): Options;

/**
* Configures Chrome to emulate a mobile device. For more information, refer
* to the ChromeDriver project page on [mobile emulation][em]. Configuration
* options include:
*
* - `deviceName`: The name of a pre-configured [emulated device][devem]
* - `width`: screen width, in pixels
* - `height`: screen height, in pixels
* - `pixelRatio`: screen pixel ratio
*
* __Example 1: Using a Pre-configured Device__
*
* let options = new chrome.Options().setMobileEmulation(
* {deviceName: 'Google Nexus 5'});
*
* let driver = new chrome.Driver(options);
*
* __Example 2: Using Custom Screen Configuration__
*
* let options = new chrome.Options().setMobileEmulation({
* width: 360,
* height: 640,
* pixelRatio: 3.0
* });
*
* let driver = new chrome.Driver(options);
*
* [em]: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation
* [devem]: https://developer.chrome.com/devtools/docs/device-mode
*
* @param {?({deviceName: string}|
* {width: number, height: number, pixelRatio: number})} config The
* mobile emulation configuration, or `null` to disable emulation.
* @return {!Options} A self reference.
*/
setMobileEmulation(config: any): Options;
}

/**
* Creates {@link remote.DriverService} instances that manage a ChromeDriver
* server.
* Creates {@link selenium-webdriver/remote.DriverService} instances that manage
* a [ChromeDriver](https://chromedriver.chromium.org/)
* server in a child process.
*/
export class ServiceBuilder extends remote.DriverService.Builder {
export class ServiceBuilder extends webdriver.chromium.ServiceBuilder {
/**
* @param {string=} opt_exe Path to the server executable to use. If omitted,
* the builder will attempt to locate the chromedriver on the current
Expand All @@ -294,59 +103,4 @@ export class ServiceBuilder extends remote.DriverService.Builder {
* cannot be found on the PATH.
*/
constructor(opt_exe?: string);

/**
* Sets which port adb is listening to. _The ChromeDriver will connect to adb
* if an {@linkplain Options#androidPackage Android session} is requested, but
* adb **must** be started beforehand._
*
* @param {number} port Which port adb is running on.
* @return {!ServiceBuilder} A self reference.
*/
setAdbPort(port: number): this;

/**
* Sets the path of the log file the driver should log to. If a log file is
* not specified, the driver will log to stderr.
* @param {string} path Path of the log file to use.
* @return {!ServiceBuilder} A self reference.
*/
loggingTo(path: string): this;

/**
* Enables verbose logging.
* @return {!ServiceBuilder} A self reference.
*/
enableVerboseLogging(): this;

/**
* Sets the number of threads the driver should use to manage HTTP requests.
* By default, the driver will use 4 threads.
* @param {number} n The number of threads to use.
* @return {!ServiceBuilder} A self reference.
*/
setNumHttpThreads(n: number): this;
}

/**
* Returns the default ChromeDriver service. If such a service has not been
* configured, one will be constructed using the default configuration for
* a ChromeDriver executable found on the system PATH.
* @return {!remote.DriverService} The default ChromeDriver service.
*/
export function getDefaultService(): remote.DriverService;

/**
* Sets the default service to use for new ChromeDriver instances.
* @param {!remote.DriverService} service The service to use.
* @throws {Error} If the default service is currently running.
*/
export function setDefaultService(service: remote.DriverService): void;

/**
* _Synchronously_ attempts to locate the chromedriver executable on the current
* system.
*
* @return {?string} the located executable, or `null`.
*/
export function locateSynchronously(): string | null;
}