Recently, I came across the need to utilize the setNetworkConditions
method from the Driver
instance in selenium-webdriver
. This method can be found in the source code here.
Surprisingly, when checking DefinitelyTyped for TypeScript types, I discovered that the types for this particular function are missing. The existing definition is limited to:
export class Driver extends webdriver.WebDriver {
/**
* Creates a new session with the ChromeDriver.
*
* @param {(Capabilities|Options)=} opt_config The configuration options.
* @param {(remote.DriverService|http.Executor)=} opt_serviceExecutor Either
* a DriverService to use for the remote end, or a preconfigured executor
* for an externally managed endpoint. If neither is provided, the
* {@linkplain ##getDefaultService default service} will be used by
* default.
* @return {!Driver} A new driver instance.
*/
static createSession(
opt_config?: Options|webdriver.CreateSessionCapabilities,
opt_service?: remote.DriverService|http.Executor): Driver;
}
My plan is to enhance this definition within my ambient.d.ts
file, a tactic that has worked well for projects lacking TypeScript definitions altogether.
However, figuring out the correct approach has been challenging. I attempted to add the following snippet:
declare module 'selenium-webdriver/chrome' {
class Driver {
setNetworkConditions(spec: {});
}
}
Unfortunately, upon incorporating this, all other function type definitions inherited by the Driver
class from webdriver.WebDriver
started showing as missing.
While exploring potential solutions, I stumbled upon this question, but it didn't quite align with my scenario of extending existing definitions.
I'm now pondering on how to effectively merge or extend these definitions without resorting to duplicating the DefinitelyTyped definitions for webdriver.WebDriver
. Any insights would be greatly appreciated!