UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

1,299 lines (1,110 loc) 219 kB
// Type definitions for Selenium WebDriverJS 2.44.0 // Project: https://code.google.com/p/selenium/ // Definitions by: Bill Armstrong <https://github.com/BillArmstrong>, Yuki Kokubun <https://github.com/Kuniwak> // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module chrome { /** * Creates a new WebDriver client for Chrome. * * @extends {webdriver.WebDriver} */ class Driver extends webdriver.WebDriver { /** * @param {(webdriver.Capabilities|Options)=} opt_config The configuration * options. * @param {remote.DriverService=} opt_service The session to use; will use * the {@link getDefaultService default service} by default. * @param {webdriver.promise.ControlFlow=} opt_flow The control flow to use, or * {@code null} to use the currently active flow. * @constructor */ constructor(opt_config?: webdriver.Capabilities, opt_service?: any, opt_flow?: webdriver.promise.ControlFlow); constructor(opt_config?: Options, opt_service?: any, opt_flow?: webdriver.promise.ControlFlow); } interface IOptionsValues { args: string[]; binary?: string; detach: boolean; extensions: string[]; localState?: any; logFile?: string; prefs?: any; } interface IPerfLoggingPrefs { enableNetwork: boolean; enablePage: boolean; enableTimeline: boolean; tracingCategories: string; bufferUsageReportingInterval: number; } /** * Class for managing ChromeDriver specific options. */ class Options { /** * @constructor */ 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; /** * 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; /** * 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 * (e.g. "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"). * * The binary path be absolute or relative to the chromedriver server * executable, but it must exist on the machine that will launch Chrome. * * @param {string} path The path to the Chrome binary to use. * @return {!Options} A self reference. */ 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 logging preferences for the new session. * @param {!webdriver.logging.Preferences} prefs The logging preferences. * @return {!Options} A self reference. */ setLoggingPrefs(prefs: webdriver.logging.Preferences): 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 * {@link #androidPackage options.androidPackage('com.android.chrome')}. * @return {!Options} A self reference. */ 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. * @param {string} path Path to the log file to use. * @return {!Options} A self reference. */ setChromeLogFile(path: string): Options; /** * Sets the proxy settings for the new session. * @param {webdriver.ProxyConfig} proxy The proxy configuration to use. * @return {!Options} A self reference. */ setProxy(proxy: webdriver.ProxyConfig): Options; /** * Converts this options instance to a {@link webdriver.Capabilities} object. * @param {webdriver.Capabilities=} opt_capabilities The capabilities to merge * these options into, if any. * @return {!webdriver.Capabilities} The capabilities. */ toCapabilities(opt_capabilities?: webdriver.Capabilities): webdriver.Capabilities; /** * Converts this instance to its JSON wire protocol representation. Note this * function is an implementation not intended for general use. * @return {{args: !Array.<string>, * binary: (string|undefined), * detach: boolean, * extensions: !Array.<string>, * localState: (Object|undefined), * logFile: (string|undefined), * prefs: (Object|undefined)}} The JSON wire protocol representation * of this instance. */ toJSON(): IOptionsValues; } /** * Creates {@link remote.DriverService} instances that manage a ChromeDriver * server. */ class 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 * PATH. * @throws {Error} If provided executable does not exist, or the chromedriver * cannot be found on the PATH. * @constructor */ constructor(opt_exe?: string); /** * Sets the port to start the ChromeDriver on. * @param {number} port The port to use, or 0 for any free port. * @return {!ServiceBuilder} A self reference. * @throws {Error} If the port is invalid. */ usingPort(port: number): ServiceBuilder; /** * 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): ServiceBuilder; /** * 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): ServiceBuilder; /** * Enables verbose logging. * @return {!ServiceBuilder} A self reference. */ enableVerboseLogging(): ServiceBuilder; /** * 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): ServiceBuilder; /** * Sets the base path for WebDriver REST commands (e.g. "/wd/hub"). * By default, the driver will accept commands relative to "/". * @param {string} path The base path to use. * @return {!ServiceBuilder} A self reference. */ setUrlBasePath(path: string): ServiceBuilder; /** * Defines the stdio configuration for the driver service. See * {@code child_process.spawn} for more information. * @param {(string|!Array.<string|number|!Stream|null|undefined>)} config The * configuration to use. * @return {!ServiceBuilder} A self reference. */ setStdio(config: string): ServiceBuilder; setStdio(config: any[]): ServiceBuilder; /** * Defines the environment to start the server under. This settings will be * inherited by every browser session started by the server. * @param {!Object.<string, string>} env The environment to use. * @return {!ServiceBuilder} A self reference. */ withEnvironment(env: { [key: string]: string }): ServiceBuilder; /** * Creates a new DriverService using this instance's current configuration. * @return {remote.DriverService} A new driver service using this instance's * current configuration. * @throws {Error} If the driver exectuable was not specified and a default * could not be found on the current PATH. */ build(): any; } /** * 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. */ function getDefaultService(): any; /** * 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. */ function setDefaultService(service: any): void; } declare module firefox { /** * Manages a Firefox subprocess configured for use with WebDriver. */ class Binary { /** * @param {string=} opt_exe Path to the Firefox binary to use. If not * specified, will attempt to locate Firefox on the current system. * @constructor */ constructor(opt_exe?: string); /** * Add arguments to the command line used to start Firefox. * @param {...(string|!Array.<string>)} var_args Either the arguments to add as * varargs, or the arguments as an array. */ addArguments(...var_args: string[]): void; /** * Launches Firefox and eturns a promise that will be fulfilled when the process * terminates. * @param {string} profile Path to the profile directory to use. * @return {!promise.Promise.<!exec.Result>} A promise for the process result. * @throws {Error} If this instance has already been started. */ launch(profile: string): webdriver.promise.Promise<any>; /** * Kills the managed Firefox process. * @return {!promise.Promise} A promise for when the process has terminated. */ kill(): webdriver.promise.Promise<void>; } /** * A WebDriver client for Firefox. * * @extends {webdriver.WebDriver} */ class Driver extends webdriver.WebDriver { /** * @param {(Options|webdriver.Capabilities|Object)=} opt_config The * configuration options for this driver, specified as either an * {@link Options} or {@link webdriver.Capabilities}, or as a raw hash * object. * @param {webdriver.promise.ControlFlow=} opt_flow The flow to * schedule commands through. Defaults to the active flow object. * @constructor */ constructor(opt_config?: webdriver.Capabilities, opt_flow?: webdriver.promise.ControlFlow); constructor(opt_config?: any, opt_flow?: webdriver.promise.ControlFlow); } /** * Configuration options for the FirefoxDriver. */ class Options { /** * @constructor */ constructor(); /** * Sets the profile to use. The profile may be specified as a * {@link Profile} object or as the path to an existing Firefox profile to use * as a template. * * @param {(string|!Profile)} profile The profile to use. * @return {!Options} A self reference. */ setProfile(profile: string): Options; setProfile(profile: Profile): Options; /** * Sets the binary to use. The binary may be specified as the path to a Firefox * executable, or as a {@link Binary} object. * * @param {(string|!Binary)} binary The binary to use. * @return {!Options} A self reference. */ setBinary(binary: string): Options; setBinary(binary: Binary): Options; /** * Sets the logging preferences for the new session. * @param {webdriver.logging.Preferences} prefs The logging preferences. * @return {!Options} A self reference. */ setLoggingPreferences(prefs: webdriver.logging.Preferences): Options; /** * Sets the proxy to use. * * @param {webdriver.ProxyConfig} proxy The proxy configuration to use. * @return {!Options} A self reference. */ setProxy(proxy: webdriver.ProxyConfig): Options; /** * Converts these options to a {@link webdriver.Capabilities} instance. * * @return {!webdriver.Capabilities} A new capabilities object. */ toCapabilities(opt_remote?: any): webdriver.Capabilities; } /** * Models a Firefox proifle directory for use with the FirefoxDriver. The * {@code Proifle} directory uses an in-memory model until {@link #writeToDisk} * is called. */ class Profile { /** * @param {string=} opt_dir Path to an existing Firefox profile directory to * use a template for this profile. If not specified, a blank profile will * be used. * @constructor */ constructor(opt_dir?: string); /** * Registers an extension to be included with this profile. * @param {string} extension Path to the extension to include, as either an * unpacked extension directory or the path to a xpi file. */ addExtension(extension: string): void; /** * Sets a desired preference for this profile. * @param {string} key The preference key. * @param {(string|number|boolean)} value The preference value. * @throws {Error} If attempting to set a frozen preference. */ setPreference(key: string, value: string): void; setPreference(key: string, value: number): void; setPreference(key: string, value: boolean): void; /** * Returns the currently configured value of a profile preference. This does * not include any defaults defined in the profile's template directory user.js * file (if a template were specified on construction). * @param {string} key The desired preference. * @return {(string|number|boolean|undefined)} The current value of the * requested preference. */ getPreference(key: string): any; /** * @return {number} The port this profile is currently configured to use, or * 0 if the port will be selected at random when the profile is written * to disk. */ getPort(): number; /** * Sets the port to use for the WebDriver extension loaded by this profile. * @param {number} port The desired port, or 0 to use any free port. */ setPort(port: number): void; /** * @return {boolean} Whether the FirefoxDriver is configured to automatically * accept untrusted SSL certificates. */ acceptUntrustedCerts(): boolean; /** * Sets whether the FirefoxDriver should automatically accept untrusted SSL * certificates. * @param {boolean} value . */ setAcceptUntrustedCerts(value: boolean): void; /** * Sets whether to assume untrusted certificates come from untrusted issuers. * @param {boolean} value . */ setAssumeUntrustedCertIssuer(value: boolean): void; /** * @return {boolean} Whether to assume untrusted certs come from untrusted * issuers. */ assumeUntrustedCertIssuer(): boolean; /** * Sets whether to use native events with this profile. * @param {boolean} enabled . */ setNativeEventsEnabled(enabled: boolean): void; /** * Returns whether native events are enabled in this profile. * @return {boolean} . */ nativeEventsEnabled(): boolean; /** * Writes this profile to disk. * @param {boolean=} opt_excludeWebDriverExt Whether to exclude the WebDriver * extension from the generated profile. Used to reduce the size of an * {@link #encode() encoded profile} since the server will always install * the extension itself. * @return {!promise.Promise.<string>} A promise for the path to the new * profile directory. */ writeToDisk(opt_excludeWebDriverExt?: boolean): webdriver.promise.Promise<string>; /** * Encodes this profile as a zipped, base64 encoded directory. * @return {!promise.Promise.<string>} A promise for the encoded profile. */ encode(): webdriver.promise.Promise<string>; } } declare module executors { /** * Creates a command executor that uses WebDriver's JSON wire protocol. * @param url The server's URL, or a promise that will resolve to that URL. * @returns {!webdriver.CommandExecutor} The new command executor. */ function createExecutor(url: string): webdriver.CommandExecutor; function createExecutor(url: webdriver.promise.Promise<string>): webdriver.CommandExecutor; } declare module webdriver { module error { interface IErrorCode { SUCCESS: number; NO_SUCH_ELEMENT: number; NO_SUCH_FRAME: number; UNKNOWN_COMMAND: number; UNSUPPORTED_OPERATION: number; // Alias for UNKNOWN_COMMAND. STALE_ELEMENT_REFERENCE: number; ELEMENT_NOT_VISIBLE: number; INVALID_ELEMENT_STATE: number; UNKNOWN_ERROR: number; ELEMENT_NOT_SELECTABLE: number; JAVASCRIPT_ERROR: number; XPATH_LOOKUP_ERROR: number; TIMEOUT: number; NO_SUCH_WINDOW: number; INVALID_COOKIE_DOMAIN: number; UNABLE_TO_SET_COOKIE: number; MODAL_DIALOG_OPENED: number; UNEXPECTED_ALERT_OPEN: number; NO_SUCH_ALERT: number; NO_MODAL_DIALOG_OPEN: number; SCRIPT_TIMEOUT: number; INVALID_ELEMENT_COORDINATES: number; IME_NOT_AVAILABLE: number; IME_ENGINE_ACTIVATION_FAILED: number; INVALID_SELECTOR_ERROR: number; SESSION_NOT_CREATED: number; MOVE_TARGET_OUT_OF_BOUNDS: number; SQL_DATABASE_ERROR: number; INVALID_XPATH_SELECTOR: number; INVALID_XPATH_SELECTOR_RETURN_TYPE: number; // The following error codes are derived straight from HTTP return codes. METHOD_NOT_ALLOWED: number; } var ErrorCode: IErrorCode; /** * Error extension that includes error status codes from the WebDriver wire * protocol: * http://code.google.com/p/selenium/wiki/JsonWireProtocol#Response_Status_Codes * * @extends {Error} */ class Error { //region Constructors /** * @param {!bot.ErrorCode} code The error's status code. * @param {string=} opt_message Optional error message. * @constructor */ constructor(code: number, opt_message?: string); //endregion //region Static Properties /** * Status strings enumerated in the W3C WebDriver working draft. * @enum {string} * @see http://www.w3.org/TR/webdriver/#status-codes */ static State: { ELEMENT_NOT_SELECTABLE: string; ELEMENT_NOT_VISIBLE: string; IME_ENGINE_ACTIVATION_FAILED: string; IME_NOT_AVAILABLE: string; INVALID_COOKIE_DOMAIN: string; INVALID_ELEMENT_COORDINATES: string; INVALID_ELEMENT_STATE: string; INVALID_SELECTOR: string; JAVASCRIPT_ERROR: string; MOVE_TARGET_OUT_OF_BOUNDS: string; NO_SUCH_ALERT: string; NO_SUCH_DOM: string; NO_SUCH_ELEMENT: string; NO_SUCH_FRAME: string; NO_SUCH_WINDOW: string; SCRIPT_TIMEOUT: string; SESSION_NOT_CREATED: string; STALE_ELEMENT_REFERENCE: string; SUCCESS: string; TIMEOUT: string; UNABLE_TO_SET_COOKIE: string; UNEXPECTED_ALERT_OPEN: string; UNKNOWN_COMMAND: string; UNKNOWN_ERROR: string; UNSUPPORTED_OPERATION: string; }; //endregion //region Properties /** * This error's status code. * @type {!bot.ErrorCode} */ code: number; /** @type {string} */ state: string; /** @override */ message: string; /** @override */ name: string; /** @override */ stack: string; /** * Flag used for duck-typing when this code is embedded in a Firefox extension. * This is required since an Error thrown in one component and then reported * to another will fail instanceof checks in the second component. * @type {boolean} */ isAutomationError: boolean; //endregion //region Methods /** @return {string} The string representation of this error. */ toString(): string; //endregion } } module logging { /** * A hash describing log preferences. * @typedef {Object.<webdriver.logging.Type, webdriver.logging.LevelName>} */ class Preferences { setLevel(type: string, level: ILevel): void; toJSON(): { [key: string]: string }; } interface IType { /** Logs originating from the browser. */ BROWSER: string; /** Logs from a WebDriver client. */ CLIENT: string; /** Logs from a WebDriver implementation. */ DRIVER: string; /** Logs related to performance. */ PERFORMANCE: string; /** Logs from the remote server. */ SERVER: string; } /** * Common log types. * @enum {string} */ var Type: IType; /** * Logging levels. * @enum {{value: number, name: webdriver.logging.LevelName}} */ interface ILevel { value: number; name: string; } interface ILevelValues { ALL: ILevel; DEBUG: ILevel; INFO: ILevel; WARNING: ILevel; SEVERE: ILevel; OFF: ILevel; } var Level: ILevelValues; /** * Converts a level name or value to a {@link webdriver.logging.Level} value. * If the name/value is not recognized, {@link webdriver.logging.Level.ALL} * will be returned. * @param {(number|string)} nameOrValue The log level name, or value, to * convert . * @return {!webdriver.logging.Level} The converted level. */ function getLevel(nameOrValue: string): ILevel; function getLevel(nameOrValue: number): ILevel; interface IEntryJSON { level: string; message: string; timestamp: number; type: string; } /** * A single log entry. */ class Entry { //region Constructors /** * @param {(!webdriver.logging.Level|string)} level The entry level. * @param {string} message The log message. * @param {number=} opt_timestamp The time this entry was generated, in * milliseconds since 0:00:00, January 1, 1970 UTC. If omitted, the * current time will be used. * @param {string=} opt_type The log type, if known. * @constructor */ constructor(level: ILevel, message: string, opt_timestamp?:number, opt_type?:string); constructor(level: string, message: string, opt_timestamp?:number, opt_type?:string); //endregion //region Public Properties /** @type {!webdriver.logging.Level} */ level: ILevel; /** @type {string} */ message: string; /** @type {number} */ timestamp: number; /** @type {string} */ type: string; //endregion //region Static Methods /** * Converts a {@link goog.debug.LogRecord} into a * {@link webdriver.logging.Entry}. * @param {!goog.debug.LogRecord} logRecord The record to convert. * @param {string=} opt_type The log type. * @return {!webdriver.logging.Entry} The converted entry. */ static fromClosureLogRecord(logRecord: any, opt_type?:string): Entry; //endregion //region Methods /** * @return {{level: string, message: string, timestamp: number, * type: string}} The JSON representation of this entry. */ toJSON(): IEntryJSON; //endregion } } module promise { //region Functions /** * Given an array of promises, will return a promise that will be fulfilled * with the fulfillment values of the input array's values. If any of the * input array's promises are rejected, the returned promise will be rejected * with the same reason. * * @param {!Array.<(T|!webdriver.promise.Promise.<T>)>} arr An array of * promises to wait on. * @return {!webdriver.promise.Promise.<!Array.<T>>} A promise that is * fulfilled with an array containing the fulfilled values of the * input array, or rejected with the same reason as the first * rejected value. * @template T */ function all(arr: Promise<any>[]): Promise<any[]>; /** * Invokes the appropriate callback function as soon as a promised * {@code value} is resolved. This function is similar to * {@link webdriver.promise.when}, except it does not return a new promise. * @param {*} value The value to observe. * @param {Function} callback The function to call when the value is * resolved successfully. * @param {Function=} opt_errback The function to call when the value is * rejected. */ function asap(value: any, callback: Function, opt_errback?: Function): void; /** * @return {!webdriver.promise.ControlFlow} The currently active control flow. */ function controlFlow(): ControlFlow; /** * Creates a new control flow. The provided callback will be invoked as the * first task within the new flow, with the flow as its sole argument. Returns * a promise that resolves to the callback result. * @param {function(!webdriver.promise.ControlFlow)} callback The entry point * to the newly created flow. * @return {!webdriver.promise.Promise} A promise that resolves to the callback * result. */ function createFlow<R>(callback: (flow: ControlFlow) => R): Promise<R>; /** * Determines whether a {@code value} should be treated as a promise. * Any object whose "then" property is a function will be considered a promise. * * @param {*} value The value to test. * @return {boolean} Whether the value is a promise. */ function isPromise(value: any): boolean; /** * Tests is a function is a generator. * @param {!Function} fn The function to test. * @return {boolean} Whether the function is a generator. */ function isGenerator(fn: Function): boolean; /** * Creates a promise that will be resolved at a set time in the future. * @param {number} ms The amount of time, in milliseconds, to wait before * resolving the promise. * @return {!webdriver.promise.Promise} The promise. */ function delayed(ms: number): Promise<void>; /** * Calls a function for each element in an array, and if the function returns * true adds the element to a new array. * * <p>If the return value of the filter function is a promise, this function * will wait for it to be fulfilled before determining whether to insert the * element into the new array. * * <p>If the filter function throws or returns a rejected promise, the promise * returned by this function will be rejected with the same reason. Only the * first failure will be reported; all subsequent errors will be silently * ignored. * * @param {!(Array.<TYPE>|webdriver.promise.Promise.<!Array.<TYPE>>)} arr The * array to iterator over, or a promise that will resolve to said array. * @param {function(this: SELF, TYPE, number, !Array.<TYPE>): ( * boolean|webdriver.promise.Promise.<boolean>)} fn The function * to call for each element in the array. * @param {SELF=} opt_self The object to be used as the value of 'this' within * {@code fn}. * @template TYPE, SELF */ function filter<T>(arr: T[], fn: (element: T, index: number, array: T[]) => any, opt_self?: any): Promise<T[]>; function filter<T>(arr: Promise<T[]>, fn: (element: T, index: number, array: T[]) => any, opt_self?: any): Promise<T[]> /** * Creates a new deferred object. * @return {!webdriver.promise.Deferred} The new deferred object. */ function defer<T>(): Deferred<T>; /** * Creates a promise that has been resolved with the given value. * @param {*=} opt_value The resolved value. * @return {!webdriver.promise.Promise} The resolved promise. */ function fulfilled<T>(opt_value?: T): Promise<T>; /** * Calls a function for each element in an array and inserts the result into a * new array, which is used as the fulfillment value of the promise returned * by this function. * * <p>If the return value of the mapping function is a promise, this function * will wait for it to be fulfilled before inserting it into the new array. * * <p>If the mapping function throws or returns a rejected promise, the * promise returned by this function will be rejected with the same reason. * Only the first failure will be reported; all subsequent errors will be * silently ignored. * * @param {!(Array.<TYPE>|webdriver.promise.Promise.<!Array.<TYPE>>)} arr The * array to iterator over, or a promise that will resolve to said array. * @param {function(this: SELF, TYPE, number, !Array.<TYPE>): ?} fn The * function to call for each element in the array. This function should * expect three arguments (the element, the index, and the array itself. * @param {SELF=} opt_self The object to be used as the value of 'this' within * {@code fn}. * @template TYPE, SELF */ function map<T>(arr: T[], fn: (element: T, index: number, array: T[]) => any, opt_self?: any): Promise<T[]> function map<T>(arr: Promise<T[]>, fn: (element: T, index: number, array: T[]) => any, opt_self?: any): Promise<T[]> /** * Creates a promise that has been rejected with the given reason. * @param {*=} opt_reason The rejection reason; may be any value, but is * usually an Error or a string. * @return {!webdriver.promise.Promise} The rejected promise. */ function rejected(opt_reason?: any): Promise<void>; /** * Wraps a function that is assumed to be a node-style callback as its final * argument. This callback takes two arguments: an error value (which will be * null if the call succeeded), and the success value as the second argument. * If the call fails, the returned promise will be rejected, otherwise it will * be resolved with the result. * @param {!Function} fn The function to wrap. * @return {!webdriver.promise.Promise} A promise that will be resolved with the * result of the provided function's callback. */ function checkedNodeCall<T>(fn: Function, ...var_args: any[]): Promise<T>; /** * Consumes a {@code GeneratorFunction}. Each time the generator yields a * promise, this function will wait for it to be fulfilled before feeding the * fulfilled value back into {@code next}. Likewise, if a yielded promise is * rejected, the rejection error will be passed to {@code throw}. * * <p>Example 1: the Fibonacci Sequence. * <pre><code> * webdriver.promise.consume(function* fibonacci() { * var n1 = 1, n2 = 1; * for (var i = 0; i < 4; ++i) { * var tmp = yield n1 + n2; * n1 = n2; * n2 = tmp; * } * return n1 + n2; * }).then(function(result) { * console.log(result); // 13 * }); * </code></pre> * * <p>Example 2: a generator that throws. * <pre><code> * webdriver.promise.consume(function* () { * yield webdriver.promise.delayed(250).then(function() { * throw Error('boom'); * }); * }).thenCatch(function(e) { * console.log(e.toString()); // Error: boom * }); * </code></pre> * * @param {!Function} generatorFn The generator function to execute. * @param {Object=} opt_self The object to use as "this" when invoking the * initial generator. * @param {...*} var_args Any arguments to pass to the initial generator. * @return {!webdriver.promise.Promise.<?>} A promise that will resolve to the * generator's final result. * @throws {TypeError} If the given function is not a generator. */ function consume<T>(generatorFn: Function, opt_self?: any, ...var_args: any[]): Promise<T>; /** * Registers an observer on a promised {@code value}, returning a new promise * that will be resolved when the value is. If {@code value} is not a promise, * then the return promise will be immediately resolved. * @param {*} value The value to observe. * @param {Function=} opt_callback The function to call when the value is * resolved successfully. * @param {Function=} opt_errback The function to call when the value is * rejected. * @return {!webdriver.promise.Promise} A new promise. */ function when<T,R>(value: T, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise<R>; function when<T,R>(value: Promise<T>, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise<R>; /** * Returns a promise that will be resolved with the input value in a * fully-resolved state. If the value is an array, each element will be fully * resolved. Likewise, if the value is an object, all keys will be fully * resolved. In both cases, all nested arrays and objects will also be * fully resolved. All fields are resolved in place; the returned promise will * resolve on {@code value} and not a copy. * * Warning: This function makes no checks against objects that contain * cyclical references: * * var value = {}; * value['self'] = value; * webdriver.promise.fullyResolved(value); // Stack overflow. * * @param {*} value The value to fully resolve. * @return {!webdriver.promise.Promise} A promise for a fully resolved version * of the input value. */ function fullyResolved<T>(value: any): Promise<T>; /** * Changes the default flow to use when no others are active. * @param {!webdriver.promise.ControlFlow} flow The new default flow. * @throws {Error} If the default flow is not currently active. */ function setDefaultFlow(flow: ControlFlow): void; //endregion /** * Error used when the computation of a promise is cancelled. * * @extends {goog.debug.Error} * @final */ class CancellationError { /** * @param {string=} opt_msg The cancellation message. * @constructor */ constructor(opt_msg?: string); name: string; message: string; } interface IThenable<T> { /** * Cancels the computation of this promise's value, rejecting the promise in the * process. This method is a no-op if the promise has alreayd been resolved. * * @param {string=} opt_reason The reason this promise is being cancelled. */ cancel(opt_reason?: string): void; /** @return {boolean} Whether this promise's value is still being computed. */ isPending(): boolean; /** * Registers listeners for when this instance is resolved. * * @param opt_callback The * function to call if this promise is successfully resolved. The function * should expect a single argument: the promise's resolved value. * @param opt_errback The * function to call if this promise is rejected. The function should expect * a single argument: the rejection reason. * @return A new promise which will be * resolved with the result of the invoked callback. */ then<R>(opt_callback?: (value: T) => Promise<R>, opt_errback?: (error: any) => any): Promise<R>; /** * Registers listeners for when this instance is resolved. * * @param opt_callback The * function to call if this promise is successfully resolved. The function * should expect a single argument: the promise's resolved value. * @param opt_errback The * function to call if this promise is rejected. The function should expect * a single argument: the rejection reason. * @return A new promise which will be * resolved with the result of the invoked callback. */ then<R>(opt_callback?: (value: T) => R, opt_errback?: (error: any) => any): Promise<R>; /** * Registers a listener for when this promise is rejected. This is synonymous * with the {@code catch} clause in a synchronous API: * <pre><code> * // Synchronous API: * try { * doSynchronousWork(); * } catch (ex) { * console.error(ex); * } * * // Asynchronous promise API: * doAsynchronousWork().thenCatch(function(ex) { * console.error(ex); * }); * </code></pre> * * @param {function(*): (R|webdriver.promise.Promise.<R>)} errback The function * to call if this promise is rejected. The function should expect a single * argument: the rejection reason. * @return {!webdriver.promise.Promise.<R>} A new promise which will be * resolved with the result of the invoked callback. * @template R */ thenCatch<R>(errback: (error: any) => any): Promise<R>; /** * Registers a listener to invoke when this promise is resolved, regardless * of whether the promise's value was successfully computed. This function * is synonymous with the {@code finally} clause in a synchronous API: * <pre><code> * // Synchronous API: * try { * doSynchronousWork(); * } finally { * cleanUp(); * } * * // Asynchronous promise API: * doAsynchronousWork().thenFinally(cleanUp); * </code></pre> * * <b>Note:</b> similar to the {@code finally} clause, if the registered * callback returns a rejected promise or throws an error, it will silently * replace the rejection error (if any) from this promise: * <pre><code> * try { * throw Error('one'); * } finally { * throw Error('two'); // Hides Error: one * } * * webdriver.promise.rejected(Error('one')) * .thenFinally(function() { * throw Error('two'); // Hides Error: one * }); * </code></pre> * * * @param {function(): (R|webdriver.promise.Promise.<R>)} callback The function * to call when this promise is resolved. * @return {!webdriver.promise.Promise.<R>} A promise that will be fulfilled * with the callback result. * @template R */ thenFinally<R>(callback: () => any): Promise<R>; } /** * Thenable is a promise-like object with a {@code then} method which may be * used to schedule callbacks on a promised value. * * @interface * @template T */ class Thenable<T> implements IThenable<T> { /** * Cancels the computation of this promise's value, rejecting the promise in the * process. This method is a no-op if the promise has alreayd been resolved. * * @param {string=} opt_reason The reason this promise is being cancelled. */ cancel(opt_reason?: string): void; /** @return {boolean} Whether this promise's value is still being computed. */ isPending(): boolean; /** * Registers listeners for when this instance is resolved. * * @param opt_callback The * function to call if this promise is successfully resolved. The function * should expect a single argument: the promise's resolved value. * @param opt_errback The * funct