diff --git a/selenium-webdriver/chrome.d.ts b/selenium-webdriver/chrome.d.ts new file mode 100644 index 0000000000..1eef996eef --- /dev/null +++ b/selenium-webdriver/chrome.d.ts @@ -0,0 +1,269 @@ +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; + } + + /** + * 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.)} var_args The arguments to add. + * @return {!Options} A self reference. + */ + addArguments(...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): 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 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 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., + * binary: (string|undefined), + * detach: boolean, + * extensions: !Array., + * 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 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.)} 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.} 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); +} + +declare module 'selenium-webdriver/chrome' { + export = chrome; +} diff --git a/selenium-webdriver/executors.d.ts b/selenium-webdriver/executors.d.ts new file mode 100644 index 0000000000..c8fc80d08d --- /dev/null +++ b/selenium-webdriver/executors.d.ts @@ -0,0 +1,13 @@ +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): webdriver.CommandExecutor; +} + +declare module 'selenium-webdriver/executors' { + export = executors; +} diff --git a/selenium-webdriver/firefox.d.ts b/selenium-webdriver/firefox.d.ts new file mode 100644 index 0000000000..18d509dc9c --- /dev/null +++ b/selenium-webdriver/firefox.d.ts @@ -0,0 +1,238 @@ +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.)} var_args Either the arguments to add as + * varargs, or the arguments as an array. + */ + addArguments(...var_args: string[]); + + + /** + * 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.} A promise for the process result. + * @throws {Error} If this instance has already been started. + */ + launch(profile: string): webdriver.promise.Promise; + + + /** + * Kills the managed Firefox process. + * @return {!promise.Promise} A promise for when the process has terminated. + */ + kill(): webdriver.promise.Promise; + } + + /** + * 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); + + + /** + * 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); + setPreference(key: string, value: number); + setPreference(key: string, value: boolean); + + + /** + * 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); + + + /** + * @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); + + + /** + * Sets whether to assume untrusted certificates come from untrusted issuers. + * @param {boolean} value . + */ + setAssumeUntrustedCertIssuer(value: boolean); + + + /** + * @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); + + + /** + * 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.} A promise for the path to the new + * profile directory. + */ + writeToDisk(opt_excludeWebDriverExt?: boolean): webdriver.promise.Promise; + + + /** + * Encodes this profile as a zipped, base64 encoded directory. + * @return {!promise.Promise.} A promise for the encoded profile. + */ + encode(): webdriver.promise.Promise; + } +} + +declare module 'selenium-webdriver/firefox' { + export = firefox; +} \ No newline at end of file diff --git a/selenium-webdriver/selenium-webdriver-tests.ts b/selenium-webdriver/selenium-webdriver-tests.ts index 52b317d961..be359b886d 100644 --- a/selenium-webdriver/selenium-webdriver-tests.ts +++ b/selenium-webdriver/selenium-webdriver-tests.ts @@ -1,28 +1,29 @@ /// - -function TestAbstractBuilder() { - var builder: webdriver.AbstractBuilder = new webdriver.AbstractBuilder(); - var driver: webdriver.WebDriver = builder.build(); - var capabilities: webdriver.Capabilities = builder.getCapabilities(); - url = builder.getServerUrl(); - var otherBuilder: webdriver.AbstractBuilder = builder.usingServer(url); - otherBuilder = builder.withCapabilities(webdriver.Capabilities.android()); - var objCapabilities: { [index: string]: string; } = {}; - objCapabilities[webdriver.Capability.BROWSER_NAME] = webdriver.Browser.PHANTOM_JS; - otherBuilder = builder.withCapabilities(objCapabilities); - var url: string = webdriver.AbstractBuilder.DEFAULT_SERVER_URL; - var env: string = webdriver.AbstractBuilder.SERVER_URL_ENV; -} +/// function TestBuilder() { var builder: webdriver.Builder = new webdriver.Builder(); - var abstractBuilder: webdriver.AbstractBuilder = builder; var driver: webdriver.WebDriver = builder.build(); - var session: string = builder.getSession(); - abstractBuilder = builder.usingSession("ID"); + builder = builder.forBrowser('name'); + builder = builder.forBrowser('name', 'version'); + builder = builder.forBrowser('name', 'version', 'platform'); - var env: string = webdriver.Builder.SESSION_ID_ENV; + var cap: webdriver.Capabilities = builder.getCapabilities(); + var str:string = builder.getServerUrl(); + + builder = builder.setAlertBehavior('behavior'); + builder = builder.setChromeOptions(new chrome.Options()); + builder = builder.setControlFlow(new webdriver.promise.ControlFlow()); + builder = builder.setEnableNativeEvents(true); + builder = builder.setFirefoxOptions(new firefox.Options()); + builder = builder.setLoggingPrefs(new webdriver.logging.Preferences()); + builder = builder.setLoggingPrefs({ "key": "value" }); + builder = builder.setProxy({ proxyType: 'type' }); + builder = builder.setScrollBehavior(1); + builder = builder.usingServer('http://someserver'); + builder = builder.withCapabilities(new webdriver.Capabilities()); + builder = builder.withCapabilities({ something: true }); } function TestActionSequence() { @@ -31,7 +32,7 @@ function TestActionSequence() { build(); var sequence: webdriver.ActionSequence = new webdriver.ActionSequence(driver); - var element: webdriver.WebElement = new webdriver.WebElement(driver, 'id'); + var element: webdriver.WebElement = new webdriver.WebElement(driver, { ELEMENT: 'id' }); // Click sequence = sequence.click(); @@ -76,23 +77,20 @@ function TestActionSequence() { sequence = sequence.sendKeys("A", "B", "C"); sequence = sequence.sendKeys(["A", "B", "C"]); - var promise: webdriver.promise.Promise = sequence.perform(); + sequence.perform().then(function () { }); } function TestAlert() { var driver: webdriver.WebDriver = new webdriver.Builder(). withCapabilities(webdriver.Capabilities.chrome()). build(); - var promise: webdriver.promise.Promise = new webdriver.promise.Promise(); - var alert: webdriver.Alert = new webdriver.Alert(driver, 'ABC'); - alert = new webdriver.Alert(driver, promise); - var deferred: webdriver.promise.Deferred = alert; + var alert: webdriver.Alert = driver.switchTo().alert(); - promise = alert.accept(); - promise = alert.dismiss(); - promise = alert.getText(); - promise = alert.sendKeys("ABC"); + alert.accept().then(function () { }); + alert.dismiss().then(function () { }); + alert.getText().then(function (text: string) { }); + alert.sendKeys("ABC").then(function () { }); } function TestBrowser() { @@ -131,6 +129,12 @@ function TestCapabilities() { capabilities = capabilities.merge(objCapabilities); capabilities = capabilities.set(webdriver.Capability.VERSION, { abc: 'def' }); capabilities = capabilities.set(webdriver.Capability.VERSION, null); + capabilities = capabilities.setLoggingPrefs(new webdriver.logging.Preferences()); + capabilities = capabilities.setLoggingPrefs({ "key": "value" }); + capabilities = capabilities.setProxy({ proxyType: 'Type' }); + capabilities = capabilities.setEnableNativeEvents(true); + capabilities = capabilities.setScrollBehavior(1); + capabilities = capabilities.setAlertBehavior('accept'); anything = capabilities.toJSON(); @@ -152,14 +156,15 @@ function TestCapability() { capability = webdriver.Capability.ACCEPT_SSL_CERTS; capability = webdriver.Capability.BROWSER_NAME; + capability = webdriver.Capability.ELEMENT_SCROLL_BEHAVIOR; capability = webdriver.Capability.HANDLES_ALERTS; capability = webdriver.Capability.LOGGING_PREFS; + capability = webdriver.Capability.NATIVE_EVENTS; capability = webdriver.Capability.PLATFORM; capability = webdriver.Capability.PROXY; capability = webdriver.Capability.ROTATABLE; capability = webdriver.Capability.SECURE_SSL; capability = webdriver.Capability.SUPPORTS_APPLICATION_CACHE; - capability = webdriver.Capability.SUPPORTS_BROWSER_CONNECTION; capability = webdriver.Capability.SUPPORTS_CSS_SELECTORS; capability = webdriver.Capability.SUPPORTS_JAVASCRIPT; capability = webdriver.Capability.SUPPORTS_LOCATION_CONTEXT; @@ -181,7 +186,8 @@ function TestCommand() { } function TestCommandExecutor() { - var c: webdriver.CommandExecutor = { execute: function(command: webdriver.Command, callback: (error: Error, obj: any) => any) {} }; + var c: webdriver.CommandExecutor = { execute: function (command: webdriver.Command, callback: (error: Error, obj: any) => any) { } }; + c.execute(new webdriver.Command('name'), function (error: Error, response: any) { }); } function TestCommandName() { @@ -291,10 +297,14 @@ function TestEventEmitter() { var callback = function (a: number, b: number, c: number) {}; emitter = emitter.addListener('ABC', callback); + emitter = emitter.addListener('ABC', callback, this); emitter.emit('ABC', 1, 2, 3); var listeners = emitter.listeners('ABC'); + if (listeners[0].oneshot) { + listeners[0].fn.apply(listeners[0].scope); + } var length: number = listeners.length; var listenerInfo = listeners[0]; if (listenerInfo.oneshot) { @@ -302,8 +312,10 @@ function TestEventEmitter() { } emitter = emitter.on('ABC', callback); + emitter = emitter.on('ABC', callback, this); emitter = emitter.once('ABC', callback); + emitter = emitter.once('ABC', callback, this); emitter = emitter.removeListener('ABC', callback); @@ -311,14 +323,6 @@ function TestEventEmitter() { emitter.removeAllListeners(); } -function TestFirefoxDomExecutor() { - if (webdriver.FirefoxDomExecutor.isAvailable()) { - var executor: webdriver.CommandExecutor = new webdriver.FirefoxDomExecutor(); - var callback = function(error: Error, responseObject: any) {}; - executor.execute(new webdriver.Command(webdriver.CommandName.CLICK), callback); - } -} - function TestKey() { var key: string; @@ -387,21 +391,28 @@ function TestKey() { } function TestLocator() { - var locator: webdriver.Locator = new webdriver.Locator('id', 'ABC'); + var driver: webdriver.WebDriver = new webdriver.Builder(). + withCapabilities(webdriver.Capabilities.chrome()). + build(); + + var locator: webdriver.Locator = webdriver.By.className('class'); var locatorStr: string = locator.toString(); var using: string = locator.using; var value: string = locator.value; - locator = webdriver.Locator.checkLocator(webdriver.Locator.Strategy.id('ABC')); - locator = webdriver.Locator.checkLocator({id: 'ABC'}); + var str: string = locator.toString(); - locator = webdriver.Locator.createFromObj({id: 'ABC'}); + locator = webdriver.By.css('css'); + locator = webdriver.By.id('id'); + locator = webdriver.By.linkText('link'); + locator = webdriver.By.name('name'); + locator = webdriver.By.partialLinkText('text'); + locator = webdriver.By.tagName('tag'); + locator = webdriver.By.xpath('xpath'); - locator = webdriver.Locator.Strategy.id('ABC'); - - locator = webdriver.By.id('ABC'); + webdriver.By.js('script', 1, 2, 3)(driver).then(function (abc: number) { }); } function TestSession() { @@ -418,16 +429,13 @@ function TestSession() { } function TestUnhandledAlertError() { - var driver: webdriver.WebDriver = new webdriver.Builder(). - withCapabilities(webdriver.Capabilities.chrome()). - build(); - var promise: webdriver.promise.Promise = new webdriver.promise.Promise(); + var someFunc = function (error: webdriver.UnhandledAlertError) { + var baseError: webdriver.error.Error = error; - var alert: webdriver.Alert = new webdriver.Alert(driver, 'ABC'); - var error = new webdriver.UnhandledAlertError('An error', alert); - var baseError: webdriver.error.Error = error; - - alert = error.getAlert(); + var alert: webdriver.Alert = error.getAlert(); + var str: string = error.getAlertText(); + str = error.toString(); + } } function TestWebDriverLogs() { @@ -435,11 +443,10 @@ function TestWebDriverLogs() { withCapabilities(webdriver.Capabilities.chrome()). build(); - var logs: webdriver.WebDriverLogs = webdriver.WebDriver.Logs; - var promise: webdriver.promise.Promise; + var logs: webdriver.WebDriverLogs = new webdriver.WebDriver.Logs(driver); - promise = logs.get(webdriver.logging.Type.BROWSER); - promise = logs.getAvailableLogTypes(); + logs.get(webdriver.logging.Type.BROWSER).then(function (entries: webdriver.logging.Entry[]) { });; + logs.getAvailableLogTypes().then(function (types: string[]) { }); } function TestWebDriverNavigation() { @@ -447,13 +454,12 @@ function TestWebDriverNavigation() { withCapabilities(webdriver.Capabilities.chrome()). build(); - var navigation: webdriver.WebDriverNavigation = webdriver.WebDriver.Navigation; - var promise: webdriver.promise.Promise; + var navigation: webdriver.WebDriverNavigation = new webdriver.WebDriver.Navigation(driver); - promise = navigation.back(); - promise = navigation.forward(); - promise = navigation.refresh(); - promise = navigation.to('http://google.com'); + navigation.back().then(function () { }); + navigation.forward().then(function () { }); + navigation.refresh().then(function () { }); + navigation.to('http://google.com').then(function () { }); } function TestWebDriverOptions() { @@ -461,8 +467,8 @@ function TestWebDriverOptions() { withCapabilities(webdriver.Capabilities.chrome()). build(); - var options: webdriver.WebDriverOptions = webdriver.WebDriver.Options; - var promise: webdriver.promise.Promise; + var options: webdriver.WebDriverOptions = new webdriver.WebDriver.Options(driver); + var promise: webdriver.promise.Promise; // Add Cookie promise = options.addCookie('name', 'value'); @@ -474,8 +480,8 @@ function TestWebDriverOptions() { promise = options.deleteAllCookies(); promise = options.deleteCookie('name'); - promise = options.getCookie('name'); - promise = options.getCookies(); + options.getCookie('name').then(function (cookies: webdriver.IWebDriverOptionsCookie) { }); + options.getCookies().then(function (cookies: webdriver.IWebDriverOptionsCookie[]) { }); var logs: webdriver.WebDriverLogs = options.logs(); var timeouts: webdriver.WebDriverTimeouts = options.timeouts(); @@ -487,8 +493,8 @@ function TestWebDriverTargetLocator() { withCapabilities(webdriver.Capabilities.chrome()). build(); - var locator: webdriver.WebDriverTargetLocator = webdriver.WebDriver.TargetLocator; - var promise: webdriver.promise.Promise; + var locator: webdriver.WebDriverTargetLocator = new webdriver.WebDriver.TargetLocator(driver); + var promise: webdriver.promise.Promise; var element: webdriver.WebElement = locator.activeElement(); var alert: webdriver.Alert = locator.alert(); @@ -503,8 +509,8 @@ function TestWebDriverTimeouts() { withCapabilities(webdriver.Capabilities.chrome()). build(); - var timeouts: webdriver.WebDriverTimeouts = webdriver.WebDriver.Timeouts; - var promise: webdriver.promise.Promise; + var timeouts: webdriver.WebDriverTimeouts = new webdriver.WebDriver.Timeouts(driver); + var promise: webdriver.promise.Promise; promise = timeouts.implicitlyWait(123); promise = timeouts.pageLoadTimeout(123); @@ -516,46 +522,52 @@ function TestWebDriverWindow() { withCapabilities(webdriver.Capabilities.chrome()). build(); - var window: webdriver.WebDriverWindow = webdriver.WebDriver.Window; - var promise: webdriver.promise.Promise; + var window: webdriver.WebDriverWindow = new webdriver.WebDriver.Window(driver); + var locationPromise: webdriver.promise.Promise; + var sizePromise: webdriver.promise.Promise; + var voidPromise: webdriver.promise.Promise; - promise = window.getPosition(); - promise = window.getSize(); - promise = window.maximize(); - promise = window.setPosition(12, 34); - promise = window.setSize(12, 34); + locationPromise = window.getPosition(); + sizePromise = window.getSize(); + voidPromise = window.maximize(); + voidPromise = window.setPosition(12, 34); + voidPromise = window.setSize(12, 34); } function TestWebDriver() { var session: webdriver.Session = new webdriver.Session('ABC', webdriver.Capabilities.android()); - var promise: webdriver.promise.Promise = new webdriver.promise.Promise(); - var executor: webdriver.CommandExecutor = new webdriver.FirefoxDomExecutor(); + var sessionPromise: webdriver.promise.Promise = new webdriver.promise.Promise(); + var executor: webdriver.CommandExecutor = executors.createExecutor("http://someserver"); var flow: webdriver.promise.ControlFlow = new webdriver.promise.ControlFlow(); var driver: webdriver.WebDriver = new webdriver.WebDriver(session, executor); driver = new webdriver.WebDriver(session, executor, flow); - driver = new webdriver.WebDriver(promise, executor); - driver = new webdriver.WebDriver(promise, executor, flow); + driver = new webdriver.WebDriver(sessionPromise, executor); + driver = new webdriver.WebDriver(sessionPromise, executor, flow); + + var voidPromise: webdriver.promise.Promise; + var stringPromise: webdriver.promise.Promise; + var booleanPromise: webdriver.promise.Promise; // Call var actions: webdriver.ActionSequence = driver.actions(); - promise = driver.call(function(){}); - promise = driver.call(function(){ var d: any = this;}, driver); - promise = driver.call(function(a: number){}, driver, 1); + stringPromise = driver.call(function(){}); + stringPromise = driver.call(function(){ var d: any = this;}, driver); + stringPromise = driver.call(function(a: number){}, driver, 1); - promise = driver.close(); + voidPromise = driver.close(); flow = driver.controlFlow(); // ExecuteAsyncScript - promise = driver.executeAsyncScript('function(){}'); - promise = driver.executeAsyncScript('function(){}', 1, 2, 3); - promise = driver.executeAsyncScript(function(){}); - promise = driver.executeAsyncScript(function(a: number){}, 1); + stringPromise = driver.executeAsyncScript('function(){}'); + stringPromise = driver.executeAsyncScript('function(){}', 1, 2, 3); + stringPromise = driver.executeAsyncScript(function(){}); + stringPromise = driver.executeAsyncScript(function(a: number){}, 1); // ExecuteScript - promise = driver.executeScript('function(){}'); - promise = driver.executeScript('function(){}', 1, 2, 3); - promise = driver.executeScript(function(){}); - promise = driver.executeScript(function(a: number){}, 1); + stringPromise = driver.executeScript('function(){}'); + stringPromise = driver.executeScript('function(){}', 1, 2, 3); + stringPromise = driver.executeScript(function(){}); + stringPromise = driver.executeScript(function(a: number){}, 1); var element: webdriver.WebElement; element = driver.findElement(webdriver.By.id('ABC')); @@ -563,38 +575,36 @@ function TestWebDriver() { element = driver.findElement(webdriver.By.js('function(){}'), 1, 2, 3); element = driver.findElement({js: 'function(){}'}, 1, 2, 3); - promise = driver.findElements(webdriver.By.className('ABC')); - promise = driver.findElements({className: 'ABC'}); - promise = driver.findElements(webdriver.By.js('function(){}'), 1, 2, 3); - promise = driver.findElements({js: 'function(){}'}, 1, 2, 3); + driver.findElements(webdriver.By.className('ABC')).then(function (elements: webdriver.WebElement[]) { }); + driver.findElements({ className: 'ABC' }).then(function (elements: webdriver.WebElement[]) { }); + driver.findElements(webdriver.By.js('function(){}'), 1, 2, 3).then(function (elements: webdriver.WebElement[]) { }); + driver.findElements({ js: 'function(){}' }, 1, 2, 3).then(function (elements: webdriver.WebElement[]) { }); - promise = driver.get('http://www.google.com'); - promise = driver.getAllWindowHandles(); - promise = driver.getCapabilities(); - promise = driver.getCurrentUrl(); - promise = driver.getPageSource() - promise = driver.getSession(); - promise = driver.getTitle(); - promise = driver.getWindowHandle(); + voidPromise = driver.get('http://www.google.com'); + driver.getAllWindowHandles().then(function (handles: string[]) { }); + driver.getCapabilities().then(function (caps: webdriver.Capabilities) { }); + stringPromise = driver.getCurrentUrl(); + stringPromise = driver.getPageSource() + driver.getSession().then(function (session: webdriver.Session) { });; + stringPromise = driver.getTitle(); + stringPromise = driver.getWindowHandle(); - promise = driver.isElementPresent(webdriver.By.className('ABC')); - promise = driver.isElementPresent({className: 'ABC'}); - promise = driver.isElementPresent(webdriver.By.js('function(){}'), 1, 2, 3); - promise = driver.isElementPresent({js: 'function(){}'}, 1, 2, 3); + booleanPromise = driver.isElementPresent(webdriver.By.className('ABC')); + booleanPromise = driver.isElementPresent({className: 'ABC'}); + booleanPromise = driver.isElementPresent(webdriver.By.js('function(){}'), 1, 2, 3); + booleanPromise = driver.isElementPresent({js: 'function(){}'}, 1, 2, 3); var options: webdriver.WebDriverOptions = driver.manage(); var navigation: webdriver.WebDriverNavigation = driver.navigate(); var locator: webdriver.WebDriverTargetLocator = driver.switchTo(); - promise = driver.quit(); - promise = driver.schedule(new webdriver.Command(webdriver.CommandName.CLICK), 'ABC'); - promise = driver.sleep(123); - promise = driver.takeScreenshot(); + voidPromise = driver.quit(); + voidPromise = driver.schedule(new webdriver.Command(webdriver.CommandName.CLICK), 'ABC'); + voidPromise = driver.sleep(123); + stringPromise = driver.takeScreenshot(); - promise = driver.wait(function() { return true; }, 123); - promise = driver.wait(function() { return true; }, 123, 'Message'); - promise = driver.wait(function() { return promise; }, 123); - promise = driver.wait(function() { return promise; }, 123, 'Message'); + booleanPromise = driver.wait(function() { return true; }, 123); + booleanPromise = driver.wait(function() { return true; }, 123, 'Message'); driver = webdriver.WebDriver.attachToSession(executor, 'ABC'); driver = webdriver.WebDriver.createSession(executor, webdriver.Capabilities.android()); @@ -606,55 +616,50 @@ function TestWebElement() { build(); var element: webdriver.WebElement; - var promise: webdriver.promise.Promise = new webdriver.promise.Promise(); - element = new webdriver.WebElement(driver, 'ID'); - element = new webdriver.WebElement(driver, promise); + element = new webdriver.WebElement(driver, { ELEMENT: 'ID' }); + element = new webdriver.WebElement(driver, new webdriver.promise.Promise()); - var deferred: webdriver.promise.Deferred = element; + var voidPromise: webdriver.promise.Promise; + var stringPromise: webdriver.promise.Promise; + var booleanPromise: webdriver.promise.Promise; - promise = element.clear(); - promise = element.click(); + voidPromise = element.clear(); + voidPromise = element.click(); element = element.findElement(webdriver.By.id('ABC')); element = element.findElement({id: 'ABC'}); - element = element.findElement(webdriver.By.js('function(){}'), 1, 2, 3); - element = element.findElement({js: 'function(){}'}, 1, 2, 3); - promise = element.findElements(webdriver.By.className('ABC')); - promise = element.findElements({className: 'ABC'}); - promise = element.findElements(webdriver.By.js('function(){}'), 1, 2, 3); - promise = element.findElements({js: 'function(){}'}, 1, 2, 3); + element.findElements(webdriver.By.className('ABC')).then(function (elements: webdriver.WebElement[]) { }); + element.findElements({ className: 'ABC' }).then(function (elements: webdriver.WebElement[]) { }); - promise = element.isElementPresent(webdriver.By.className('ABC')); - promise = element.isElementPresent({className: 'ABC'}); - promise = element.isElementPresent(webdriver.By.js('function(){}'), 1, 2, 3); - promise = element.isElementPresent({js: 'function(){}'}, 1, 2, 3); + booleanPromise = element.isElementPresent(webdriver.By.className('ABC')); + booleanPromise = element.isElementPresent({className: 'ABC'}); - promise = element.getAttribute('class'); - promise = element.getCssValue('display'); + stringPromise = element.getAttribute('class'); + stringPromise = element.getCssValue('display'); driver = element.getDriver(); - promise = element.getInnerHtml(); - promise = element.getLocation(); - promise = element.getOuterHtml(); - promise = element.getSize(); - promise = element.getTagName(); - promise = element.getText(); - promise = element.isDisplayed(); - promise = element.isEnabled(); - promise = element.isSelected(); - promise = element.sendKeys('A', 'B', 'C'); - promise = element.submit(); - promise = element.toWireValue(); + stringPromise = element.getInnerHtml(); + element.getLocation().then(function (location: webdriver.ILocation) { }); + stringPromise = element.getOuterHtml(); + element.getSize().then(function (size: webdriver.ISize) { }); + stringPromise = element.getTagName(); + stringPromise = element.getText(); + booleanPromise = element.isDisplayed(); + booleanPromise = element.isEnabled(); + booleanPromise = element.isSelected(); + voidPromise = element.sendKeys('A', 'B', 'C'); + voidPromise = element.submit(); + element.getId().then(function (id: webdriver.IWebElementId) { }); - promise = webdriver.WebElement.equals(element, new webdriver.WebElement(driver, 'ID2')); + booleanPromise = webdriver.WebElement.equals(element, new webdriver.WebElement(driver, { ELEMENT: 'ID2' })); var key: string = webdriver.WebElement.ELEMENT_KEY; } function TestLogging() { webdriver.logging.Preferences['name'] = 'ABC'; - var level: webdriver.logging.Level = webdriver.logging.getLevel('OFF'); + var level: webdriver.logging.ILevel = webdriver.logging.getLevel('OFF'); level = webdriver.logging.getLevel(1); level = webdriver.logging.Level.ALL; @@ -667,13 +672,6 @@ function TestLogging() { var name: string = level.name; var value: number = level.value; - name = webdriver.logging.LevelName.ALL; - name = webdriver.logging.LevelName.DEBUG; - name = webdriver.logging.LevelName.INFO; - name = webdriver.logging.LevelName.OFF; - name = webdriver.logging.LevelName.SEVERE; - name = webdriver.logging.LevelName.WARNING; - var type: string; type = webdriver.logging.Type.BROWSER; type = webdriver.logging.Type.CLIENT; @@ -702,47 +700,44 @@ function TestLoggingEntry() { entry = webdriver.logging.Entry.fromClosureLogRecord({}, webdriver.logging.Type.DRIVER); } -function TestProcess() { - var isNative: boolean = webdriver.process.isNative(); - var value: string; +function TestPromiseNamespace() { + var stringPromise: webdriver.promise.Promise = new webdriver.promise.Promise(); + var numberPromise: webdriver.promise.Promise; + var booleanPromise: webdriver.promise.Promise; + var voidPromise: webdriver.promise.Promise; - value = webdriver.process.getEnv('name'); - value = webdriver.process.getEnv('name', 'default'); + webdriver.promise.asap('abc', function(value: any){ return true; }); + webdriver.promise.asap('abc', function(value: any){}, function(err: any) { return 'ABC'; }); - webdriver.process.setEnv('name', 'value'); - webdriver.process.setEnv('name', 123); -} - -function TestPromise() { - var promise: webdriver.promise.Promise = new webdriver.promise.Promise(); - - webdriver.promise.asap(promise, function(value: any){ return true; }); - webdriver.promise.asap(promise, function(value: any){}, function(err: any) { return 'ABC'; }); - - promise = webdriver.promise.checkedNodeCall(function(err: any, value: any) { return 123; }); + stringPromise = webdriver.promise.checkedNodeCall(function(err: any, value: any) { return 'abc'; }); var flow: webdriver.promise.ControlFlow = webdriver.promise.controlFlow(); - promise = webdriver.promise.createFlow(function(newFlow: webdriver.promise.ControlFlow) { }); + stringPromise = webdriver.promise.createFlow(function(newFlow: webdriver.promise.ControlFlow) { return 'ABC' }); - var deferred: webdriver.promise.Deferred; - deferred = webdriver.promise.defer(function() {}); - deferred = webdriver.promise.defer(function(reason?: any) {}); + var deferred: webdriver.promise.Deferred; + deferred = webdriver.promise.defer(); + deferred = webdriver.promise.defer(); - promise = webdriver.promise.delayed(123); + stringPromise = deferred.promise; - promise = webdriver.promise.fulfilled(); - promise = webdriver.promise.fulfilled({a: 123}); + deferred.fulfill('ABC'); + deferred.reject('error'); - promise = webdriver.promise.fullyResolved({a: 123}); + voidPromise = webdriver.promise.delayed(123); + + voidPromise = webdriver.promise.fulfilled(); + stringPromise = webdriver.promise.fulfilled('abc'); + + stringPromise = webdriver.promise.fullyResolved('abc'); var isPromise: boolean = webdriver.promise.isPromise('ABC'); - promise = webdriver.promise.rejected({a: 123}); + voidPromise = webdriver.promise.rejected({a: 123}); webdriver.promise.setDefaultFlow(new webdriver.promise.ControlFlow()); - promise = webdriver.promise.when(promise, function(value: any) { return 123; }, function(err: Error) { return 123; }); + numberPromise = webdriver.promise.when('abc', function(value: any) { return 123; }, function(err: Error) { return 123; }); } function TestControlFlow() { @@ -763,14 +758,14 @@ function TestControlFlow() { var e: any = flow.annotateError(new Error('Error')); - var promise: webdriver.promise.Promise; + var stringPromise: webdriver.promise.Promise; - promise = flow.await(promise); + stringPromise = flow.await(stringPromise); flow.clearHistory(); - promise = flow.execute(function() { return promise; }); - promise = flow.execute(function() { return promise; }, 'Description'); + stringPromise = flow.execute(function() { return stringPromise; }); + stringPromise = flow.execute(function() { return stringPromise; }, 'Description'); var history: string[] = flow.getHistory(); @@ -778,12 +773,12 @@ function TestControlFlow() { flow.reset(); - promise = flow.timeout(123); - promise = flow.timeout(123, 'Description'); + var voidPromise: webdriver.promise.Promise = flow.timeout(123); + voidPromise = flow.timeout(123, 'Description'); - promise = flow.wait(function() { return true; }, 123); - promise = flow.wait(function() { return true; }, 123, 'Timeout Message'); - promise = flow.wait(function() { return promise; }, 123, 'Timeout Message'); + voidPromise = flow.wait(function() { return true; }, 123); + voidPromise = flow.wait(function() { return true; }, 123, 'Timeout Message'); + voidPromise = flow.wait(function() { return stringPromise; }, 123, 'Timeout Message'); var timer: webdriver.promise.IControlFlowTimer = flow.timer; @@ -792,53 +787,33 @@ function TestControlFlow() { } function TestDeferred() { - var deferred: webdriver.promise.Deferred; + var deferred: webdriver.promise.Deferred; - deferred = new webdriver.promise.Deferred(); - deferred = new webdriver.promise.Deferred(function() {}); - deferred = new webdriver.promise.Deferred(function(reason: any) { }); - deferred = new webdriver.promise.Deferred(function() {}, new webdriver.promise.ControlFlow()); + deferred = new webdriver.promise.Deferred(); + deferred = new webdriver.promise.Deferred(new webdriver.promise.ControlFlow()); - var promise: webdriver.promise.Promise = deferred; + var promise: webdriver.promise.Promise = deferred.promise; deferred.errback(new Error('Error')); deferred.errback('Error'); - deferred.fulfill(123); + deferred.fulfill('abc'); deferred.reject(new Error('Error')); deferred.reject('Error'); deferred.removeAll(); - - promise = deferred.promise; } function TestPromiseClass() { - var promise: webdriver.promise.Promise = new webdriver.promise.Promise(); + var promise: webdriver.promise.Promise = new webdriver.promise.Promise(); - var obj = { - a: 5 - } - - promise = promise.addBoth(function( a: any ) { }); - promise = promise.addBoth(function( a: any ) { return 123; }); - promise = promise.addBoth(function( a: any ) { }, obj); - - promise = promise.addCallback(function( a: any ) { }); - promise = promise.addCallback(function( a: any ) { return 123; }); - promise = promise.addCallback(function( a: any ) { }, obj); - - promise = promise.addErrback(function( e: any ) { }); - promise = promise.addErrback(function( e: any ) { return 123; }); - promise = promise.addErrback(function( e: any ) { }, obj); - - promise.cancel(obj); + promise.cancel('Abort'); var isPending: boolean = promise.isPending(); promise = promise.then(); - promise = promise.then(function( a: any ) { }); - promise = promise.then(function( a: any ) { return 123; }); - promise = promise.then(function( a: any ) {}, function( e: any) {}); - promise = promise.then(function( a: any ) {}, function( e: any) { return 123; }); + promise = promise.then(function( a: string ) { }); + promise = promise.then(function( a: string ) { return 'cde'; }); + promise = promise.then(function( a: string ) {}, function( e: any) {}); + promise = promise.then(function( a: string ) {}, function( e: any) { return 123; }); } function TestErrorCode() { diff --git a/selenium-webdriver/selenium-webdriver.d.ts b/selenium-webdriver/selenium-webdriver.d.ts index 3d65230160..e38049e1d4 100644 --- a/selenium-webdriver/selenium-webdriver.d.ts +++ b/selenium-webdriver/selenium-webdriver.d.ts @@ -3,10 +3,49 @@ // Definitions by: Bill Armstrong // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// +/// + declare module webdriver { module error { - var ErrorCode: bot.IErrorCode; + 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 @@ -15,13 +54,92 @@ declare module webdriver { * * @extends {Error} */ - var Error: { + class Error { + + //region Constructors + /** * @param {!bot.ErrorCode} code The error's status code. * @param {string=} opt_message Optional error message. * @constructor */ - new (code: number, opt_message?: string): bot.Error; + 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 } } @@ -32,7 +150,7 @@ declare module webdriver { * @typedef {Object.} */ class Preferences { - setLevel(type: string, level: Level): void; + setLevel(type: string, level: ILevel): void; toJSON(): { [key: string]: string }; } @@ -59,24 +177,18 @@ declare module webdriver { * Logging levels. * @enum {{value: number, name: webdriver.logging.LevelName}} */ - class Level { - //region Static Properties - - static ALL: Level; - static DEBUG: Level; - static INFO: Level; - static WARNING: Level; - static SEVERE: Level; - static OFF: Level; - - //endregion - - //region Properties - + interface ILevel { value: number; name: string; + } - //endregion + var Level: { + ALL: ILevel; + DEBUG: ILevel; + INFO: ILevel; + WARNING: ILevel; + SEVERE: ILevel; + OFF: ILevel; } /** @@ -87,8 +199,8 @@ declare module webdriver { * convert . * @return {!webdriver.logging.Level} The converted level. */ - function getLevel(nameOrValue: string): Level; - function getLevel(nameOrValue: number): Level; + function getLevel(nameOrValue: string): ILevel; + function getLevel(nameOrValue: number): ILevel; interface IEntryJSON { level: string; @@ -113,7 +225,7 @@ declare module webdriver { * @param {string=} opt_type The log type, if known. * @constructor */ - constructor(level: Level, message: string, opt_timestamp?:number, opt_type?:string); + constructor(level: ILevel, message: string, opt_timestamp?:number, opt_type?:string); constructor(level: string, message: string, opt_timestamp?:number, opt_type?:string); //endregion @@ -121,7 +233,7 @@ declare module webdriver { //region Public Properties /** @type {!webdriver.logging.Level} */ - level: Level; + level: ILevel; /** @type {string} */ message: string; @@ -453,7 +565,7 @@ declare module webdriver { * resolving the promise. * @return {!webdriver.promise.Promise} The promise. */ - function delayed(ms: number): Promise; + function delayed(ms: number): Promise; /** * Calls a function for each element in an array, and if the function returns @@ -578,7 +690,7 @@ declare module webdriver { * generator's final result. * @throws {TypeError} If the given function is not a generator. */ - function consume(generatorFn: (...var_args) => T, opt_self?: any, ...var_args): Promise; + function consume(generatorFn: Function, opt_self?: any, ...var_args): Promise; /** * Registers an observer on a promised {@code value}, returning a new promise @@ -591,8 +703,8 @@ declare module webdriver { * rejected. * @return {!webdriver.promise.Promise} A new promise. */ - function when(value: T, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise; - function when(value: Promise, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise; + function when(value: T, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise; + function when(value: Promise, opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise; /** * Returns a promise that will be resolved with the input value in a @@ -613,7 +725,7 @@ declare module webdriver { * @return {!webdriver.promise.Promise} A promise for a fully resolved version * of the input value. */ - function fullyResolved(value: T): Promise; + function fullyResolved(value: any): Promise; /** * Changes the default flow to use when no others are active. @@ -674,7 +786,7 @@ declare module webdriver { * @return {!webdriver.promise.Promise} A new promise which will be resolved * with the result of the invoked callback. */ - then(opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise; + then(opt_callback?: (value: T) => any, opt_errback?: (error: any) => any): Promise; /** @@ -701,7 +813,7 @@ declare module webdriver { * resolved with the result of the invoked callback. * @template R */ - thenCatch(errback: (error: any) => any): Promise; + thenCatch(errback: (error: any) => any): Promise; /** @@ -743,7 +855,7 @@ declare module webdriver { * with the callback result. * @template R */ - thenFinally(callback: () => any): Promise; + thenFinally(callback: () => any): Promise; //endregion } @@ -1629,24 +1741,9 @@ declare module webdriver { * {@code prompt}. Provides functions to retrieve the message displayed with * the alert, accept or dismiss the alert, and set the response text (in the * case of {@code prompt}). - * @extends {webdriver.promise.Deferred} */ interface Alert { - //region Constructors - - /** - * @param {!webdriver.WebDriver} driver The driver controlling the browser this - * alert is attached to. - * @param {!(string|webdriver.promise.Promise)} text Either the message text - * displayed with this alert, or a promise that will be resolved to said - * text. - * @constructor - */ - constructor(driver: WebDriver, text: string); - - //endregion - //region Methods /** @@ -1714,19 +1811,7 @@ declare module webdriver { * current page. * @extends {bot.Error} */ - class UnhandledAlertError extends bot.Error { - //region Constructors - - /** - * @param {string} message The error message. - * @param {string} text The text displayed with the unhandled alert. - * @param {!webdriver.Alert} alert The alert handle. - * @constructor - */ - constructor(message: string, text: string, alert: Alert); - - //endregion - + interface UnhandledAlertError extends webdriver.error.Error { //region Methods /** @@ -2458,48 +2543,17 @@ declare module webdriver { //endregion } - /** - * @implements {webdriver.CommandExecutor} - */ - class FirefoxDomExecutor implements CommandExecutor { - //region Constructors - - /** - * @constructor - */ - constructor(); - - //endregion - - //region Static Methods - - /** - * @return {boolean} Whether the current environment supports the - * FirefoxDomExecutor. - */ - static isAvailable(): boolean; - - //endretion - - //region Methods - - /** @override */ - execute(command: Command, callback: (error: Error, responseObject: any) => any ): void; - - //endregion - } - /** * Interface for navigating back and forth in the browser history. */ - class WebDriverNavigation { + interface WebDriverNavigation { //region Constructors /** * @param {!webdriver.WebDriver} driver The parent driver. * @constructor */ - constructor(driver: WebDriver); + new (driver: WebDriver): WebDriverNavigation; //endregion @@ -2549,14 +2603,14 @@ declare module webdriver { /** * Provides methods for managing browser and driver state. */ - class WebDriverOptions { + interface WebDriverOptions { //region Constructors /** * @param {!webdriver.WebDriver} driver The parent driver. * @constructor */ - constructor(driver: webdriver.WebDriver); + new (driver: webdriver.WebDriver): WebDriverOptions; //endregion @@ -2639,14 +2693,14 @@ declare module webdriver { /** * An interface for managing timeout behavior for WebDriver instances. */ - class WebDriverTimeouts { + interface WebDriverTimeouts { //region Constructors /** * @param {!webdriver.WebDriver} driver The parent driver. * @constructor */ - constructor(driver: WebDriver); + new (driver: WebDriver): WebDriverTimeouts; //endregion @@ -2701,7 +2755,7 @@ declare module webdriver { /** * An interface for managing the current window. */ - class WebDriverWindow { + interface WebDriverWindow { //region Constructors @@ -2709,7 +2763,7 @@ declare module webdriver { * @param {!webdriver.WebDriver} driver The parent driver. * @constructor */ - constructor(driver: WebDriver); + new (driver: WebDriver): WebDriverWindow; //endregion @@ -2764,7 +2818,7 @@ declare module webdriver { /** * Interface for managing WebDriver log records. */ - class WebDriverLogs { + interface WebDriverLogs { //region Constructors @@ -2772,7 +2826,7 @@ declare module webdriver { * @param {!webdriver.WebDriver} driver The parent driver. * @constructor */ - constructor(driver: WebDriver); + new (driver: WebDriver): WebDriverLogs; //endregion @@ -2807,7 +2861,7 @@ declare module webdriver { /** * An interface for changing the focus of the driver to another frame or window. */ - class WebDriverTargetLocator { + interface WebDriverTargetLocator { //region Constructors @@ -2815,7 +2869,7 @@ declare module webdriver { * @param {!webdriver.WebDriver} driver The parent driver. * @constructor */ - constructor(driver: WebDriver); + new (driver: WebDriver): WebDriverTargetLocator; //endregion @@ -2921,12 +2975,12 @@ declare module webdriver { //region Static Properties - static Navigation: { new (webDriver: WebDriver): WebDriverNavigation; }; - static Options: { new (webDriver: WebDriver): WebDriverOptions; }; - static Timeouts: { new (webDriver: WebDriver): WebDriverTimeouts; }; - static Window: { new (webDriver: WebDriver): WebDriverWindow; }; - static Logs: { new (webDriver: WebDriver): WebDriverLogs; }; - static TargetLocator: { new (webDriver: WebDriver): WebDriverTargetLocator; }; + static Navigation: WebDriverNavigation; + static Options: WebDriverOptions; + static Timeouts: WebDriverTimeouts; + static Window: WebDriverWindow; + static Logs: WebDriverLogs; + static TargetLocator: WebDriverTargetLocator; //endregion @@ -3806,19 +3860,7 @@ declare module webdriver { /** * An element locator. */ - class Locator { - - //region Constructors - - /** - * An element locator. - * @param {string} using The type of strategy to use for this locator. - * @param {string} value The search target of this locator. - * @constructor - */ - constructor(using: string, value: string); - - //endregion + interface Locator { //region Properties @@ -3836,45 +3878,12 @@ declare module webdriver { //endregion - //region Static Properties - - /** - * Factory methods for the supported locator strategies. - * @type {Object.} - */ - static Strategy: ILocatorStrategy; - - //endregion - //region Methods /** @return {string} String representation of this locator. */ toString(): string; //endregion - - //region Static Methods - - /** - * Creates a new Locator from an object whose only property is also a key in - * the {@code webdriver.Locator.Strategy} map. - * @param {Object.} obj The object to convert into a locator. - * @return {webdriver.Locator} The new locator object. - */ - static createFromObj(obj: any): Locator - - /** - * Verifies that a {@code locator} is a valid locator to use for searching for - * elements on the page. - * @param {webdriver.Locator|Object.} locator The locator - * to verify, or a short-hand object that can be converted into a locator - * to verify. - * @return {!webdriver.Locator} The validated locator. - */ - static checkLocator(locator: Locator): Locator; - static checkLocator(obj: any): Locator; - - //endregion } /** @@ -3925,727 +3934,7 @@ declare module webdriver { } } -declare module bot { - 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 - } -} - -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; - } - - /** - * 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.)} var_args The arguments to add. - * @return {!Options} A self reference. - */ - addArguments(...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): 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 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 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., - * binary: (string|undefined), - * detach: boolean, - * extensions: !Array., - * 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 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.)} 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.} 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); -} - -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.)} var_args Either the arguments to add as - * varargs, or the arguments as an array. - */ - addArguments(...var_args: string[]); - - - /** - * 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.} A promise for the process result. - * @throws {Error} If this instance has already been started. - */ - launch(profile: string): webdriver.promise.Promise; - - - /** - * Kills the managed Firefox process. - * @return {!promise.Promise} A promise for when the process has terminated. - */ - kill(): webdriver.promise.Promise; - } - - /** - * 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); - - - /** - * 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); - setPreference(key: string, value: number); - setPreference(key: string, value: boolean); - - - /** - * 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); - - - /** - * @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); - - - /** - * Sets whether to assume untrusted certificates come from untrusted issuers. - * @param {boolean} value . - */ - setAssumeUntrustedCertIssuer(value: boolean); - - - /** - * @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); - - - /** - * 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.} A promise for the path to the new - * profile directory. - */ - writeToDisk(opt_excludeWebDriverExt?: boolean): webdriver.promise.Promise; - - - /** - * Encodes this profile as a zipped, base64 encoded directory. - * @return {!promise.Promise.} A promise for the encoded profile. - */ - encode(): webdriver.promise.Promise; - } -} - declare module 'selenium-webdriver' { export = webdriver; } -declare module 'selenium-webdriver/chrome' { - export = chrome; -} - -declare module 'selenium-webdriver/firefox' { - export = firefox; -} - -declare module 'selenium-webdriver/error' { - export = bot; -} - -declare module 'selenium-webdriver/testing' { - - /** - * Registers a new test suite. - * @param name The suite name. - * @param fn The suite function, or {@code undefined} to define a pending test suite. - */ - function describe(name: string, fn: Function): void; - - /** - * Defines a suppressed test suite. - * @param name The suite name. - * @param fn The suite function, or {@code undefined} to define a pending test suite. - */ - function xdescribe(name: string, fn: Function): void; - - /** - * Register a function to call after the current suite finishes. - * @param fn - */ - function after(fn: Function): void; - - /** - * Register a function to call after each test in a suite. - * @param fn - */ - function afterEach(fn: Function): void; - - /** - * Register a function to call before the current suite starts. - * @param fn - */ - function before(fn: Function): void; - - /** - * Register a function to call before each test in a suite. - * @param fn - */ - function beforeEach(fn: Function): void; - - /** - * Add a test to the current suite. - * @param name The test name. - * @param fn The test function, or {@code undefined} to define a pending test case. - */ - function it(name: string, fn: Function): void; - - /** - * An alias for {@link #it()} that flags the test as the only one that should - * be run within the current suite. - * @param name The test name. - * @param fn The test function, or {@code undefined} to define a pending test case. - */ - function iit(name: string, fn: Function): void; - - /** - * Adds a test to the current suite while suppressing it so it is not run. - * @param name The test name. - * @param fn The test function, or {@code undefined} to define a pending test case. - */ - function xit(name: string, fn: Function): void; -} - -declare module 'selenium-webdriver/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): webdriver.CommandExecutor; -} diff --git a/selenium-webdriver/testing.d.ts b/selenium-webdriver/testing.d.ts new file mode 100644 index 0000000000..a63aaca0b8 --- /dev/null +++ b/selenium-webdriver/testing.d.ts @@ -0,0 +1,62 @@ +declare module 'selenium-webdriver/testing' { + + /** + * Registers a new test suite. + * @param name The suite name. + * @param fn The suite function, or {@code undefined} to define a pending test suite. + */ + function describe(name: string, fn: Function): void; + + /** + * Defines a suppressed test suite. + * @param name The suite name. + * @param fn The suite function, or {@code undefined} to define a pending test suite. + */ + function xdescribe(name: string, fn: Function): void; + + /** + * Register a function to call after the current suite finishes. + * @param fn + */ + function after(fn: Function): void; + + /** + * Register a function to call after each test in a suite. + * @param fn + */ + function afterEach(fn: Function): void; + + /** + * Register a function to call before the current suite starts. + * @param fn + */ + function before(fn: Function): void; + + /** + * Register a function to call before each test in a suite. + * @param fn + */ + function beforeEach(fn: Function): void; + + /** + * Add a test to the current suite. + * @param name The test name. + * @param fn The test function, or {@code undefined} to define a pending test case. + */ + function it(name: string, fn: Function): void; + + /** + * An alias for {@link #it()} that flags the test as the only one that should + * be run within the current suite. + * @param name The test name. + * @param fn The test function, or {@code undefined} to define a pending test case. + */ + function iit(name: string, fn: Function): void; + + /** + * Adds a test to the current suite while suppressing it so it is not run. + * @param name The test name. + * @param fn The test function, or {@code undefined} to define a pending test case. + */ + function xit(name: string, fn: Function): void; +} \ No newline at end of file