From 869af223ba43753e0fc76ffd5b3cadd8c318653a Mon Sep 17 00:00:00 2001 From: Connor Schlesiger Date: Wed, 23 Aug 2017 12:42:54 -0400 Subject: [PATCH 1/6] Update tests to suit DefinitlyTyped standard --- custom-assertions.d.ts | 3 - custom-commands.d.ts | 3 - page-objects.d.ts | 9 - .../nightwatch/index.d.ts | 1540 +++++++++-------- types/nightwatch/nightwatch-tests.ts | 13 + types/nightwatch/tsconfig.json | 22 + types/nightwatch/tslint.json | 1 + typings.json | 4 - 8 files changed, 813 insertions(+), 782 deletions(-) delete mode 100644 custom-assertions.d.ts delete mode 100644 custom-commands.d.ts delete mode 100644 page-objects.d.ts rename nightwatch.d.ts => types/nightwatch/index.d.ts (73%) create mode 100644 types/nightwatch/nightwatch-tests.ts create mode 100644 types/nightwatch/tsconfig.json create mode 100644 types/nightwatch/tslint.json delete mode 100644 typings.json diff --git a/custom-assertions.d.ts b/custom-assertions.d.ts deleted file mode 100644 index aec1c32..0000000 --- a/custom-assertions.d.ts +++ /dev/null @@ -1,3 +0,0 @@ - -export interface NightWatchCustomAsserions { -} \ No newline at end of file diff --git a/custom-commands.d.ts b/custom-commands.d.ts deleted file mode 100644 index fccacc7..0000000 --- a/custom-commands.d.ts +++ /dev/null @@ -1,3 +0,0 @@ - -export interface NightWatchCustomCommands { -} \ No newline at end of file diff --git a/page-objects.d.ts b/page-objects.d.ts deleted file mode 100644 index 1a2454a..0000000 --- a/page-objects.d.ts +++ /dev/null @@ -1,9 +0,0 @@ - -export interface PageObjects { -} - -export interface NightWatchCustomPageObjects { - page: PageObjects; -} - - diff --git a/nightwatch.d.ts b/types/nightwatch/index.d.ts similarity index 73% rename from nightwatch.d.ts rename to types/nightwatch/index.d.ts index 56b603c..0596f09 100644 --- a/nightwatch.d.ts +++ b/types/nightwatch/index.d.ts @@ -1,132 +1,144 @@ -// Type definitions for nightwatchjs +// Type definitions for nightwatch 0.9 // Project: http://nightwatchjs.org/api -// Definitions by: Rahul Kavalapara +// Definitions by: Rahul Kavalapara +// Connor Schlesiger +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import {NightWatchCustomCommands} from "./custom-commands"; -import {NightWatchCustomPageObjects} from "./page-objects"; +interface NightWatchCustomAssertions { +} + +interface NightWatchCustomCommands { +} -export interface DesiredCapabilities { +interface NightWatchPageObjects { +} + +interface NightWatchCustomPageObjects { + page: NightWatchPageObjects; +} + +interface DesiredCapabilities { /** * The name of the browser being used; should be one of {android|chrome|firefox|htmlunit|internet explorer|iPhone|iPad|opera|safari}. - */ + */ browserName?: string; - + /** * The browser version, or the empty string if unknown. */ version?: string; - + /** - * A key specifying which platform the browser should be running on. This value should be one of {WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANDROID}. - * When requesting a new session, the client may specify ANY to indicate any available platform may be used. + * A key specifying which platform the browser should be running on. This value should be one of {WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANDROID}. + * When requesting a new session, the client may specify ANY to indicate any available platform may be used. * For more information see [GridPlatforms (https://code.google.com/p/selenium/wiki/GridPlatforms)] */ platform?: string; - + /** * Whether the session supports taking screenshots of the current page. */ takesScreenShot?: boolean; - + /** * Whether the session can interact with modal popups, such as window.alert and window.confirm. - */ + */ handlesAlerts: boolean; - + /** * Whether the session supports CSS selectors when searching for elements. - */ + */ cssSelectorsEnabled?: boolean; - + /** * Whether the session supports executing user supplied JavaScript in the context of the current page (only on HTMLUnitDriver). */ javascriptEnabled?: boolean; - - /** + + /** * Whether the session can interact with database storage. */ databaseEnabled?: boolean; - - /** + + /** * Whether the session can set and query the browser's location context. */ locationContextEnabled?: boolean; - + /** * Whether the session can interact with the application cache. */ applicationCacheEnabled?: boolean; - + /** * Whether the session can query for the browser's connectivity and disable it if desired. */ browserConnectionEnabled?: boolean; - + /** * Whether the session supports interactions with storage objects (http://www.w3.org/TR/2009/WD-webstorage-20091029/). */ webStorageEnabled?: boolean; - + /** * Whether the session should accept all SSL certs by default. */ acceptSslCerts?: boolean; - + /** * Whether the session can rotate the current page's current layout between portrait and landscape orientations (only applies to mobile platforms). */ rotatable?: boolean; - - /** + + /** * Whether the session is capable of generating native events when simulating user input. */ nativeEvents?: boolean; - + /** * What the browser should do with an unhandled alert before throwing out the UnhandledAlertException. Possible values are "accept", "dismiss" and "ignore" */ unexpectedAlertBehaviour?: string; - + /** - * Allows the user to specify whether elements are scrolled into the viewport for interaction to align with the top (0) or bottom (1) of the viewport. - * The default value is to align with the top of the viewport. Supported in IE and Firefox (since 2.36) - */ + * Allows the user to specify whether elements are scrolled into the viewport for interaction to align with the top (0) or bottom (1) of the viewport. + * The default value is to align with the top of the viewport. Supported in IE and Firefox (since 2.36) + */ elementScrollBehaviour?: number; - + /** - * A JSON object describing the logging level of different components in the browser, the driver, or any intermediary WebDriver servers. - * Available values for most loggers are "OFF", "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST", "ALL". + * A JSON object describing the logging level of different components in the browser, the driver, or any intermediary WebDriver servers. + * Available values for most loggers are "OFF", "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST", "ALL". * This produces a JSON object looking something like: {"loggingPrefs": {"driver": "INFO", "server": "OFF", "browser": "FINE"}}. */ loggingPrefs?: { browser?: string; driver?: string; server?: string; - }; - + }; + } -export interface ScreenshotOptions { +interface ScreenshotOptions { enabled?: boolean; on_failure?: boolean; on_error?: boolean; path?: string; } -export interface NightWatchTestRunner { +interface NightWatchTestRunner { "type"?: string; - options?: { - ui?: string; + options?: { + ui?: string; }; } -export interface NightWatchTestWorker { +interface NightWatchTestWorker { enabled: boolean; workers: string; } -export interface NightWatchOptions { +interface NightWatchOptions { /** * An array of folders (excluding subfolders) where the tests are located. */ @@ -153,7 +165,7 @@ export interface NightWatchOptions { page_object_path?: string | string[]; /** - * Location of an external globals module which will be loaded and made available to the test as a property globals on the main client instance. + * Location of an external globals module which will be loaded and made available to the test as a property globals on the main client instance. * Globals can also be defined/overwritten inside a test_settings environment. */ globals_path?: string; @@ -184,104 +196,104 @@ export interface NightWatchOptions { parallel_process_delay?: number; /** - * Whether or not to run individual test files in parallel. If set to true, runs the tests in parallel and determines the number of workers automatically. + * Whether or not to run individual test files in parallel. If set to true, runs the tests in parallel and determines the number of workers automatically. * If set to an object, can specify specify the number of workers as "auto" or a number. Example: "test_workers" : {"enabled" : true, "workers" : "auto"} */ test_workers?: boolean | NightWatchTestWorker; /** - * Specifies which test runner to use when running the tests. Values can be either default (built in nightwatch runner) or mocha. + * Specifies which test runner to use when running the tests. Values can be either default (built in nightwatch runner) or mocha. * Example: "test_runner" : {"type" : "mocha", "options" : {"ui" : "tdd"}} */ test_runner?: string | NightWatchTestRunner; } -export interface SeleniumOptions { +interface SeleniumOptions { /** * Whether or not to manage the selenium process automatically. */ start_process: boolean; /** - * Whether or not to automatically start the Selenium session. + * Whether or not to automatically start the Selenium session. */ start_session: boolean; /** - * The location of the selenium jar file. This needs to be specified if start_process is enabled.E.g.: lib/selenium-server-standalone-2.43.0.jar + * The location of the selenium jar file. This needs to be specified if start_process is enabled.E.g.: lib/selenium-server-standalone-2.43.0.jar */ server_path: string; /** - * The location where the selenium Selenium-debug.log file will be placed. Defaults to current directory. To disable Selenium logging, set this to false + * The location where the selenium Selenium-debug.log file will be placed. Defaults to current directory. To disable Selenium logging, set this to false */ log_path: string | boolean; /** - * Usually not required and only used if start_process is true. Specify the IP address you wish Selenium to listen on. + * Usually not required and only used if start_process is true. Specify the IP address you wish Selenium to listen on. */ host: string; /** - * The port number Selenium will listen on. + * The port number Selenium will listen on. */ port: number; /** - * List of cli arguments to be passed to the Selenium process. Here you can set various options for browser drivers, such as: - * - * webdriver.firefox.profile: Selenium will be default create a new Firefox profile for each session. - * If you wish to use an existing Firefox profile you can specify its name here. - * Complete list of Firefox Driver arguments available https://code.google.com/p/selenium/wiki/FirefoxDriver. - * - * webdriver.chrome.driver: Nightwatch can run the tests using Chrome browser also. To enable this you have to download the ChromeDriver binary - * (http://chromedriver.storage.googleapis.com/index.html) and specify it's location here. Also don't forget to specify chrome as the browser name in the - * desiredCapabilities object. + * List of cli arguments to be passed to the Selenium process. Here you can set various options for browser drivers, such as: + * + * webdriver.firefox.profile: Selenium will be default create a new Firefox profile for each session. + * If you wish to use an existing Firefox profile you can specify its name here. + * Complete list of Firefox Driver arguments available https://code.google.com/p/selenium/wiki/FirefoxDriver. + * + * webdriver.chrome.driver: Nightwatch can run the tests using Chrome browser also. To enable this you have to download the ChromeDriver binary + * (http://chromedriver.storage.googleapis.com/index.html) and specify it's location here. Also don't forget to specify chrome as the browser name in the + * desiredCapabilities object. * More information can be found on the ChromeDriver website (https://sites.google.com/a/chromium.org/chromedriver/). - * - * webdriver.ie.driver: Nightwatch has support for Internet Explorer also. To enable this you have to download the IE Driver binary - * (https://code.google.com/p/selenium/wiki/InternetExplorerDriver) and specify it's location here. Also don't forget to specify "internet explorer" as the browser + * + * webdriver.ie.driver: Nightwatch has support for Internet Explorer also. To enable this you have to download the IE Driver binary + * (https://code.google.com/p/selenium/wiki/InternetExplorerDriver) and specify it's location here. Also don't forget to specify "internet explorer" as the browser * name in the desiredCapabilities object. - */ + */ cli_args: any; } -export interface NightWatchTestSettings { +interface NightWatchTestSettings { /** - * A url which can be used later in the tests as the main url to load. Can be useful if your tests will run on different environments, each one with a different url. + * A url which can be used later in the tests as the main url to load. Can be useful if your tests will run on different environments, each one with a different url. */ launch_url: string; /** - * The hostname/IP on which the selenium server is accepting connections. + * The hostname/IP on which the selenium server is accepting connections. */ selenium_host: string; /** - * The port number on which the selenium server is accepting connections. + * The port number on which the selenium server is accepting connections. */ selenium_port: number; /** - * Whether to show extended Selenium command logs. + * Whether to show extended Selenium command logs. */ silent: boolean; /** - * Use to disable terminal output completely. + * Use to disable terminal output completely. */ output: boolean; /** - * Use to disable colored output in the terminal. + * Use to disable colored output in the terminal. */ disable_colors: boolean; /** - * Selenium generates screenshots when command errors occur. With on_failure set to true, also generates screenshots for failing or erroring tests. These are saved on the disk. - * Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false. - * Example: + * Selenium generates screenshots when command errors occur. With on_failure set to true, also generates screenshots for failing or erroring tests. These are saved on the disk. + * Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false. + * Example: * "screenshots" : { * "enabled" : true, * "on_failure" : true, @@ -292,30 +304,30 @@ export interface NightWatchTestSettings { screenshots: ScreenshotOptions; /** - * In case the selenium server requires credentials this username will be used to compute the Authorization header. + * In case the selenium server requires credentials this username will be used to compute the Authorization header. * The value can be also an environment variable, in which case it will look like this: "username" : "${SAUCE_USERNAME}" */ username: string; /** - * This field will be used together with username to compute the Authorization header. + * This field will be used together with username to compute the Authorization header. * Like username, the value can be also an environment variable: "access_key" : "${SAUCE_ACCESS_KEY}" */ access_key: string; /** - * Proxy requests to the selenium server. http, https, socks(v5), socks5, sock4, and pac are accepted. Uses node-proxy-agent. Example: http://user:pass@host:port + * Proxy requests to the selenium server. http, https, socks(v5), socks5, sock4, and pac are accepted. Uses node-proxy-agent. Example: http://user:pass@host:port */ proxy: string; /** - * An object which will be passed to the Selenium WebDriver when a new session will be created. You can specify browser name for instance along with other capabilities. + * An object which will be passed to the Selenium WebDriver when a new session will be created. You can specify browser name for instance along with other capabilities. * Example: * "desiredCapabilities" : { - * "browserName" : "firefox", + * "browserName" : "firefox", * "acceptSslCerts" : true * } - * You can view the complete list of capabilities https://code.google.com/p/selenium/wiki/DesiredCapabilities. + * You can view the complete list of capabilities https://code.google.com/p/selenium/wiki/DesiredCapabilities. */ desiredCapabilities: DesiredCapabilities; @@ -325,58 +337,58 @@ export interface NightWatchTestSettings { globals: any; /** - * An array of folders or file patterns to be skipped (relative to the main source folder). + * An array of folders or file patterns to be skipped (relative to the main source folder). * Example: "exclude" : ["excluded-folder"] or: "exclude" : ["test-folder/*-smoke.js"] */ exclude: string[]; /** - * Folder or file pattern to be used when loading the tests. Files that don't match this patter will be ignored. + * Folder or file pattern to be used when loading the tests. Files that don't match this patter will be ignored. * Example: "filter" : "tests/*-smoke.js" */ filter: string; /** - * Do not show the Base64 image data in the (verbose) log when taking screenshots. + * Do not show the Base64 image data in the (verbose) log when taking screenshots. */ log_screenshot_data: boolean; /** - * Use xpath as the default locator strategy + * Use xpath as the default locator strategy */ use_xpath: boolean; /** - * Same as Selenium settings cli_args. You can override the global cli_args on a per-environment basis. + * Same as Selenium settings cli_args. You can override the global cli_args on a per-environment basis. */ cli_args: any; /** - * End the session automatically when the test is being terminated, usually after a failed assertion. + * End the session automatically when the test is being terminated, usually after a failed assertion. */ end_session_on_fail: boolean; /** - * Skip the rest of testcases (if any) when one testcase fails.. + * Skip the rest of testcases (if any) when one testcase fails.. */ skip_testcases_on_fail: boolean; } -export interface TestSuite { +interface TestSuite { name: string; "module": string; group: string; results: any; } -export interface AssertionError { +interface AssertionError { name: string; message: string; showDiff: boolean; stack: string; } -export interface LanguageChains { +interface LanguageChains { to: Expect; be: Expect; been: Expect; @@ -391,20 +403,20 @@ export interface LanguageChains { of: Expect; } -export interface Expect extends LanguageChains, NightWatchBrowser { +interface Expect extends LanguageChains, NightWatchBrowser { /** * Returns the DOM Element - * @param property: Css / Id property of the DOM element - * @returns {} + * @param property: Css / Id property of the DOM element + * @returns {} */ element: (property: string) => NightWatchBrowser; /** - * These methods will perform assertions on the specified target on the current element. + * These methods will perform assertions on the specified target on the current element. * The targets can be an attribute value, the element's inner text and a css property. - * @param value - * @param message + * @param value + * @param message * @returns {} */ equal: (value: string) => NightWatchBrowser; @@ -412,132 +424,132 @@ export interface Expect extends LanguageChains, NightWatchBrowser { match: (value: string) => NightWatchBrowser; /** - * Negates any of assertions following in the chain. + * Negates any of assertions following in the chain. */ not: NightWatchBrowser; /** - * These methods perform the same thing which is essentially retrying the assertion for the given amount of time (in milliseconds). - * before or after can be chained to any assertion and thus adding retry capability. You can change the polling interval by defining - * a waitForConditionPollInterval property (in milliseconds) as a global property in your nightwatch.json or in + * These methods perform the same thing which is essentially retrying the assertion for the given amount of time (in milliseconds). + * before or after can be chained to any assertion and thus adding retry capability. You can change the polling interval by defining + * a waitForConditionPollInterval property (in milliseconds) as a global property in your nightwatch.json or in * your external globals file. Similarly, a default timeout can be specified as a global waitForConditionTimeout property (in milliseconds). - * @param value: Number of milliseconds to wait to perform and operation of check + * @param value: Number of milliseconds to wait to perform and operation of check * @returns {} */ before: (value: number) => NightWatchBrowser; after: (value: number) => NightWatchBrowser; /** - * Checks if the type (i.e. tag name) of a specified element is of an expected value. - * @param value: The expected type - * @param message: Optional log message to display in the output. If missing, one is displayed by default. + * Checks if the type (i.e. tag name) of a specified element is of an expected value. + * @param value: The expected type + * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ a: (value: string, message?: string) => NightWatchBrowser; an: (value: string, message?: string) => NightWatchBrowser; /** - * Checks if a given attribute of an element exists and optionally if it has the expected value. - * @param attribute: The attribute name - * @param message: Optional log message to display in the output. If missing, one is displayed by default. + * Checks if a given attribute of an element exists and optionally if it has the expected value. + * @param attribute: The attribute name + * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ attribute: (name: string, message?: string) => NightWatchBrowser; /** - * Checks a given css property of an element exists and optionally if it has the expected value. - * @param property: The css property name - * @param message: Optional log message to display in the output. If missing, one is displayed by default. + * Checks a given css property of an element exists and optionally if it has the expected value. + * @param property: The css property name + * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ css: (property: string, message?: string) => NightWatchBrowser; /** - * Property that checks if an element is currently enabled. + * Property that checks if an element is currently enabled. */ enabled: NightWatchBrowser; /** - * Property that checks if an element is present in the DOM. + * Property that checks if an element is present in the DOM. */ present: NightWatchBrowser; /** - * Property that checks if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected. + * Property that checks if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected. */ selected: NightWatchBrowser; /** - * Property that retrieves the text contained by an element. Can be chained to check if contains/equals/matches the specified text or regex. + * Property that retrieves the text contained by an element. Can be chained to check if contains/equals/matches the specified text or regex. */ text: NightWatchBrowser; /** - * Property that retrieves the value (i.e. the value attributed) of an element. Can be chained to check if contains/equals/matches the specified text or regex. + * Property that retrieves the value (i.e. the value attributed) of an element. Can be chained to check if contains/equals/matches the specified text or regex. */ value: NightWatchBrowser; /** - * Property that asserts the visibility of a specified element. + * Property that asserts the visibility of a specified element. */ visible: NightWatchBrowser; } -export interface Assertion extends NightWatchBrowser { +interface Assertion extends NightWatchBrowser { /** - * Checks if the given attribute of an element contains the expected value. - * @param selector: The selector (CSS / Xpath) used to locate the element. - * @param attribute: The attribute name - * @param expected: The expected contained value of the attribute to check. - * @param message: Optional log message to display in the output. If missing, one is displayed by default. + * Checks if the given attribute of an element contains the expected value. + * @param selector: The selector (CSS / Xpath) used to locate the element. + * @param attribute: The attribute name + * @param expected: The expected contained value of the attribute to check. + * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ attributeContains: (selector: string, attribute: string, expected: string, message?: string) => NightWatchBrowser; /** - * Checks if the given attribute of an element has the expected value. + * Checks if the given attribute of an element has the expected value. * @param cssSelector: The CSS selector used to locate the element. * @param attribute: The attribute name * @param expected: The expected value of the attribute to check. * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * @returns {} */ attributeEquals: (cssSelector: string, attribute: string, expected: string, msg?: string) => NightWatchBrowser; /** - * Checks if the given element contains the specified text. - * @param cssSelector: The CSS selector used to locate the element. + * Checks if the given element contains the specified text. + * @param cssSelector: The CSS selector used to locate the element. * @param expectedText: The text to look for. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ containsText: (cssSelector: string, expectedText: string, msg?: string) => NightWatchBrowser; /** * Checks if the given element has the specified CSS class. - * @param cssSelector: The CSS selector used to locate the element. - * @param className: The CSS class to look for. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * @param cssSelector: The CSS selector used to locate the element. + * @param className: The CSS class to look for. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ cssClassPresent: (cssSelector: string, className: string, msg?: string) => NightWatchBrowser; /** - * Checks if the given element does not have the specified CSS class. - * @param cssSelector: The CSS selector used to locate the element. - * @param className: The CSS class to look for. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * Checks if the given element does not have the specified CSS class. + * @param cssSelector: The CSS selector used to locate the element. + * @param className: The CSS class to look for. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ cssClassNotPresent: (cssSelector: string, className: string, msg?: string) => NightWatchBrowser; /** - * Checks if the specified css property of a given element has the expected value. - * @param cssSelector: The CSS selector used to locate the element. + * Checks if the specified css property of a given element has the expected value. + * @param cssSelector: The CSS selector used to locate the element. * @param cssProperty: The CSS property. - * @param expected: The expected value of the css property to check. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * @param expected: The expected value of the css property to check. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ cssProperty: (cssSelector: string, cssProperty: string, expected: string | number, msg?: string) => NightWatchBrowser; @@ -548,18 +560,18 @@ export interface Assertion extends NightWatchBrowser { doesNotThrow: (value: any, expected: any, message?: string) => NightWatchBrowser; /** - * Checks if the given element exists in the DOM. - * @param cssSelector: The CSS selector used to locate the element. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * Checks if the given element exists in the DOM. + * @param cssSelector: The CSS selector used to locate the element. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ elementPresent: (cssSelector: string, msg?: string) => NightWatchBrowser; /** - * Checks if the given element does not exist in the DOM. + * Checks if the given element does not exist in the DOM. * @param cssSelector: The CSS selector used to locate the element. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ elementNotPresent: (cssSelector: string, msg?: string) => NightWatchBrowser; @@ -568,10 +580,10 @@ export interface Assertion extends NightWatchBrowser { fail: (actual?: any, expected?: any, message?: string, operator?: string) => NightWatchBrowser; /** - * Checks if the given element is not visible on the page. - * @param cssSelector: The CSS selector used to locate the element. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * Checks if the given element is not visible on the page. + * @param cssSelector: The CSS selector used to locate the element. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ hidden: (cssSelector: string, msg?: string) => NightWatchBrowser; @@ -592,69 +604,69 @@ export interface Assertion extends NightWatchBrowser { throws: (fn: Function, msg?: string) => NightWatchBrowser; /** - * Checks if the page title equals the given value. - * @param expected: The expected page title. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} - * + * Checks if the page title equals the given value. + * @param expected: The expected page title. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} + * * Defined in base class. */ //title: (expected: string, msg?: string) => NightWatchBrowser; /** - * Checks if the current URL contains the given value. - * @param expectedText: The value expected to exist within the current URL. + * Checks if the current URL contains the given value. + * @param expectedText: The value expected to exist within the current URL. * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * @returns {} */ urlContains: (expectedText: string, msg?: string) => NightWatchBrowser; /** - * Checks if the current url equals the given value. - * @param expected: The expected url. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * Checks if the current url equals the given value. + * @param expected: The expected url. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ urlEquals: (expected: string, msg?: string) => NightWatchBrowser; /** - * Checks if the given form element's value equals the expected value. - * @param cssSelector: The CSS selector used to locate the element. - * @param expectedText: The expected text. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * Checks if the given form element's value equals the expected value. + * @param cssSelector: The CSS selector used to locate the element. + * @param expectedText: The expected text. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ value: (cssSelector: string, expectedText: string, msg?: string) => NightWatchBrowser; /** - * Checks if the given form element's value contains the expected value. + * Checks if the given form element's value contains the expected value. * @param cssSelector: The CSS selector used to locate the element. - * @param expectedText: The expected text. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * @param expectedText: The expected text. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ valueContains: (cssSelector: string, expectedText: string, msg?: string) => NightWatchBrowser; /** - * Checks if the given element is visible on the page. - * @param cssSelector: The CSS selector used to locate the element. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} + * Checks if the given element is visible on the page. + * @param cssSelector: The CSS selector used to locate the element. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @returns {} */ visible: (cssSelector: string, msg?: string) => NightWatchBrowser; AssertionError: AssertionError; } -export interface TypedCallbackResult { +interface TypedCallbackResult { status: number; value: T; } -export interface CallbackResult extends TypedCallbackResult { +interface CallbackResult extends TypedCallbackResult { } -export interface LogEntry { +interface LogEntry { /** * The log entry message. */ @@ -671,7 +683,7 @@ export interface LogEntry { level: string; } -export interface Keys { +interface Keys { /** Releases all held modifier keys. */ "NULL": string; /** OS-specific keystroke sequence that performs a cancel action. */ @@ -796,16 +808,16 @@ export interface Keys { } -export interface NightWatchClient { +interface NightWatchClient { assert: Assertion; expect: Expect; - verify: Assertion; + verify: Assertion; /** - * Clear a textarea or a text input element's value. Uses elementIdValue protocol command. + * Clear a textarea or a text input element's value. Uses elementIdValue protocol command. * * Usage: * ``` @@ -813,527 +825,527 @@ export interface NightWatchClient { * client.clearValue('input[type=text]'); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ clearValue: (selector: string, callback?: () => void) => NightWatchBrowser; /** * Simulates a click event on the given DOM element. Uses elementIdClick protocol command. - * + * * Usage: * ``` - * this.demoTest = function (client) { + * this.demoTest = function (client) { * client.click("#main ul li a.first"); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ click: (selector: string, callback?: () => void) => NightWatchBrowser; /** - * Close the current window. This can be useful when you're working with multiple windows open (e.g. an OAuth login). Uses window protocol command. - * + * Close the current window. This can be useful when you're working with multiple windows open (e.g. an OAuth login). Uses window protocol command. + * * Usage: * ``` - * this.demoTest = function (client) { + * this.demoTest = function (client) { * client.closeWindow(); * }; * ``` - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ closeWindow: (callback?: () => void) => NightWatchBrowser; /** * Delete the cookie with the given name. This command is a no-op if there is no such cookie visible to the current page. - * + * * Usage: * ``` - * this.demoTest = function(browser) { - * browser.deleteCookie("test_cookie", function() { - * // do something more in here + * this.demoTest = function(browser) { + * browser.deleteCookie("test_cookie", function() { + * // do something more in here * }); * } * ``` - * @param The: name of the cookie to delete. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param The: name of the cookie to delete. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ deleteCookie: (The: string, callback?: () => void) => NightWatchBrowser; /** * Delete all cookies visible to the current page. - * + * * Usage: * ``` - * this.demoTest = function(browser) { - * browser.deleteCookies(function() { - * // do something more in here - * }); + * this.demoTest = function(browser) { + * browser.deleteCookies(function() { + * // do something more in here + * }); * } * ``` - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ deleteCookies: (callback?: () => void) => NightWatchBrowser; /** * Ends the session. Uses session protocol command. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.end(); + * this.demoTest = function (browser) { + * browser.end(); * }; * ``` * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @returns {} */ end: (callback?: () => void) => NightWatchBrowser; /** * Retrieve the value of an attribute for a given DOM element. Uses elementIdAttribute protocol command. - * + * * Usage: * ``` - * this.demoTest = function (client) { - * client.getAttribute("#main ul li a.first", "href", function(result) { - * this.assert.equal(typeof result, "object"); - * this.assert.equal(result.status, 0); - * this.assert.equal(result.value, "#home"); - * }); + * this.demoTest = function (client) { + * client.getAttribute("#main ul li a.first", "href", function(result) { + * this.assert.equal(typeof result, "object"); + * this.assert.equal(result.status, 0); + * this.assert.equal(result.value, "#home"); + * }); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param attribute: The attribute name to inspect. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The value of the attribute} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param attribute: The attribute name to inspect. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The value of the attribute} */ getAttribute: (selector: string, attribute: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** - * Retrieve a single cookie visible to the current page. The cookie is returned as a cookie JSON object, as defined here. + * Retrieve a single cookie visible to the current page. The cookie is returned as a cookie JSON object, as defined here. * Uses cookie protocol command. - * + * * Usage: * ``` - * this.demoTest = function(browser) { - * browser.getCookie(name, function callback(result) { - * this.assert.equal(result.value, '123456'); - * this.assert.equals(result.name, 'test_cookie'); + * this.demoTest = function(browser) { + * browser.getCookie(name, function callback(result) { + * this.assert.equal(result.value, '123456'); + * this.assert.equals(result.name, 'test_cookie'); * }); * } * ``` - * @param name: The cookie name - * @param callback: The callback function which will receive the response as an argument. - * @returns {The cookie object as a selenium cookie JSON object or null if the cookie wasn't found.} + * @param name: The cookie name + * @param callback: The callback function which will receive the response as an argument. + * @returns {The cookie object as a selenium cookie JSON object or null if the cookie wasn't found.} */ getCookie: (name: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** - * Retrieve all cookies visible to the current page. The cookies are returned as an array of cookie JSON object, + * Retrieve all cookies visible to the current page. The cookies are returned as an array of cookie JSON object, * as defined here. Uses cookie protocol command. - * + * * Usage: * ``` - * this.demoTest = function(browser) { - * browser.getCookies(function callback(result) { - * this.assert.equal(result.value.length, 1); - * this.assert.equals(result.value[0].name, 'test_cookie'); - * }); + * this.demoTest = function(browser) { + * browser.getCookies(function callback(result) { + * this.assert.equal(result.value.length, 1); + * this.assert.equals(result.value[0].name, 'test_cookie'); + * }); * } * ``` * @param callback: The callback function which will receive the response as an argument. - * @returns {A list of cookies} + * @returns {A list of cookies} */ getCookies: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Retrieve the value of a css property for a given DOM element. Uses elementIdCssProperty protocol command. - * + * * Usage: * ``` - * this.demoTest = function (client) { - * client.getCssProperty("#main ul li a.first", "display", function(result) { - * this.assert.equal(typeof result, "object"); - * this.assert.equal(result.status, 0); - * this.assert.equal(result.value, 'inline'); + * this.demoTest = function (client) { + * client.getCssProperty("#main ul li a.first", "display", function(result) { + * this.assert.equal(typeof result, "object"); + * this.assert.equal(result.status, 0); + * this.assert.equal(result.value, 'inline'); * }); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param cssProperty: The CSS property to inspect. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The value of the css property} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param cssProperty: The CSS property to inspect. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The value of the css property} */ getCssProperty: (selector: string, cssProperty: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine an element's size in pixels. Uses elementIdSize protocol command. - * + * * Usage: * ``` - * this.demoTest = function (client) { - * client.getElementSize("#main ul li a.first", function(result) { - * this.assert.equal(typeof result, "object"); - * this.assert.equal(result.status, 0); - * this.assert.equal(result.value.width, 500); - * this.assert.equal(result.value.height, 20); - * }); + * this.demoTest = function (client) { + * client.getElementSize("#main ul li a.first", function(result) { + * this.assert.equal(typeof result, "object"); + * this.assert.equal(result.status, 0); + * this.assert.equal(result.value.width, 500); + * this.assert.equal(result.value.height, 20); + * }); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The width and height of the element in pixels} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The width and height of the element in pixels} */ getElementSize: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. - * The element's coordinates are returned as a JSON object with x and y properties. Uses elementIdLocation protocol command. - * + * The element's coordinates are returned as a JSON object with x and y properties. Uses elementIdLocation protocol command. + * * Usage: * ``` - * this.demoTest = function (client) { - * client.getLocation("#main ul li a.first", function(result) { - * this.assert.equal(typeof result, "object"); - * this.assert.equal(result.status, 0); - * this.assert.equal(result.value.x, 200); - * this.assert.equal(result.value.y, 200); - * }); + * this.demoTest = function (client) { + * client.getLocation("#main ul li a.first", function(result) { + * this.assert.equal(typeof result, "object"); + * this.assert.equal(result.status, 0); + * this.assert.equal(result.value.x, 200); + * this.assert.equal(result.value.y, 200); + * }); * }; - * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The X and Y coordinates for the element on the page} + * ``` + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The X and Y coordinates for the element on the page} */ getLocation: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine an element's location on the screen once it has been scrolled into view. Uses elementIdLocationInView protocol command. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.getLocationInView("#main ul li a.first", function(result) { - * this.assert.equal(typeof result, "object"); - * this.assert.equal(result.status, 0); - * this.assert.equal(result.value.x, 200); - * this.assert.equal(result.value.y, 200); - * }); + * this.demoTest = function (browser) { + * browser.getLocationInView("#main ul li a.first", function(result) { + * this.assert.equal(typeof result, "object"); + * this.assert.equal(result.status, 0); + * this.assert.equal(result.value.x, 200); + * this.assert.equal(result.value.y, 200); + * }); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The X and Y coordinates for the element on the page.} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The X and Y coordinates for the element on the page.} */ getLocationInView: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Gets a log from selenium - * + * * Usage: * ``` - * this.demoTest = function(client) { - * this.getLog('browser', function(logEntriesArray) { - * console.log('Log length: ' + logEntriesArray.length); - * logEntriesArray.forEach(function(log) { - * console.log('[' + log.level + '] ' + log.timestamp + ' : ' + log.message); - * }); + * this.demoTest = function(client) { + * this.getLog('browser', function(logEntriesArray) { + * console.log('Log length: ' + logEntriesArray.length); + * logEntriesArray.forEach(function(log) { + * console.log('[' + log.level + '] ' + log.timestamp + ' : ' + log.message); + * }); * }); * }; * ``` - * @param typestring: Log type to request - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param typestring: Log type to request + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ getLog: (typestring: string, callback?: (log: LogEntry[]) => void) => NightWatchBrowser; /** * Gets the available log types - * + * * Usage: * ``` - * this.demoTest = function(client) { - * this.getLogTypes(function(typesArray) { - * console.log(typesArray); + * this.demoTest = function(client) { + * this.getLogTypes(function(typesArray) { + * console.log(typesArray); * }); * }; * ``` - * @param callback: Optional callback function to be called when the command finishes. - * @returns {Available log types} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {Available log types} */ getLogTypes: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Query for an element's tag name. Uses elementIdName protocol command. - * + * * Usage: * ``` - * this.demoTest = function (client) { - * client.getTagName("#main ul li .first", function(result) { - * this.assert.equal(typeof result, "object"); - * this.assert.equal(result.status, 0); + * this.demoTest = function (client) { + * client.getTagName("#main ul li .first", function(result) { + * this.assert.equal(typeof result, "object"); + * this.assert.equal(result.status, 0); * this.assert.equal(result.value, "a"); * }); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The element's tag name, as a lowercase string.} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The element's tag name, as a lowercase string.} */ getTagName: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Returns the visible text for the element. Uses elementIdText protocol command. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.getText("#main ul li a.first", function(result) { - * this.assert.equal(typeof result, "object"); - * this.assert.equal(result.status, 0); + * this.demoTest = function (browser) { + * browser.getText("#main ul li a.first", function(result) { + * this.assert.equal(typeof result, "object"); + * this.assert.equal(result.status, 0); * this.assert.equal(result.value, "nightwatchjs.org"); * }); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The element's visible text.} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The element's visible text.} */ getText: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Returns the title of the current page. Uses title protocol command. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.getTitle(function(title) { - * this.assert.equal(typeof title, 'string'); + * this.demoTest = function (browser) { + * browser.getTitle(function(title) { + * this.assert.equal(typeof title, 'string'); * this.assert.equal(title, 'Nightwatch.js'); * }); * }; * ``` - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The page title.} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The page title.} */ getTitle: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Returns a form element current value. Uses elementIdValue protocol command. - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.getValue("form.login input[type=text]", function(result) { - * this.assert.equal(typeof result, "object"); - * this.assert.equal(result.status, 0); + * this.assert.equal(typeof result, "object"); + * this.assert.equal(result.status, 0); * this.assert.equal(result.value, "enter username"); * }); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The element's value.} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The element's value.} */ getValue: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** - * This command is an alias to url and also a convenience method when called without any arguments in the sense that it performs a call to .url() with passing the value of launch_url - * field from the settings file. Uses url protocol command. - * + * This command is an alias to url and also a convenience method when called without any arguments in the sense that it performs a call to .url() with passing the value of launch_url + * field from the settings file. Uses url protocol command. + * * Usage: * ``` - * this.demoTest = function (client) { + * this.demoTest = function (client) { * client.init(); * }; * ``` - * @param url: Url to navigate to. - * @returns {} + * @param url: Url to navigate to. + * @returns {} */ init: (url?: string) => NightWatchBrowser; /** * Utility command to load an external script into the page specified by url. - * + * * Usage: * ``` - * this.demoTest = function(client) { + * this.demoTest = function(client) { * this.injectScript("{script-url}", function() { * // we're all done here. * }); * }; * ``` - * @param scriptUrl: The script file url - * @param id: Dom element id to be set on the script tag. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The newly created script tag.} + * @param scriptUrl: The script file url + * @param id: Dom element id to be set on the script tag. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The newly created script tag.} */ injectScript: (scriptUrl: string, id?: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Utility command to test if the log type is available - * + * * Usage: * ``` - * this.demoTest = function(browser) { - * browser.isLogAvailable('browser', function(isAvailable) { - * // do something more in here + * this.demoTest = function(browser) { + * browser.isLogAvailable('browser', function(isAvailable) { + * // do something more in here * }); * } * ``` - * @param typeString: Type of log to test + * @param typeString: Type of log to test * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @returns {} */ isLogAvailable: (typeString: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine if an element is currently displayed. Uses elementIdDisplayed protocol command. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.isVisible('#main', function(result) { - * this.assert.equal(typeof result, "object"); - * this.assert.equal(result.status, 0); - * this.assert.equal(result.value, true); + * this.demoTest = function (browser) { + * browser.isVisible('#main', function(result) { + * this.assert.equal(typeof result, "object"); + * this.assert.equal(result.status, 0); + * this.assert.equal(result.value, true); * }); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ isVisible: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Maximizes the current window. - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.maximizeWindow(); * }; * ``` - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ maximizeWindow: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Move the mouse by an offset of the specified element. Uses moveTo protocol command. - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.moveToElement('#main', 10, 10); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param xoffset: X offset to move to, relative to the top-left corner of the element. - * @param yoffset: Y offset to move to, relative to the top-left corner of the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param xoffset: X offset to move to, relative to the top-left corner of the element. + * @param yoffset: Y offset to move to, relative to the top-left corner of the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ moveToElement: (selector: string, xoffset: number, yoffset: number, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Suspends the test for the given time in milliseconds. If the milliseconds argument is missing it will suspend the test indefinitely - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.pause(1000); * // or suspend indefinitely * browser.pause(); * }; * ``` * @param ms: The number of milliseconds to wait. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ pause: (ms: number, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * A simple perform command which allows access to the "api" in a callback. Can be useful if you want to read variables set by other commands. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * var elementValue; + * this.demoTest = function (browser) { + * var elementValue; * browser - * .getValue('.some-element', function(result) { - * elementValue = result.value; - * }) + * .getValue('.some-element', function(result) { + * elementValue = result.value; + * }) * // other stuff going on ... * // * // self-completing callback - * .perform(function() { - * console.log('elementValue', elementValue); - * // without any defined parameters, perform + * .perform(function() { + * console.log('elementValue', elementValue); + * // without any defined parameters, perform * // completes immediately (synchronously) * }) * // - * // asynchronous completion - * .perform(function(done) { - * console.log('elementValue', elementValue); - * // potentially other async stuff going on + * // asynchronous completion + * .perform(function(done) { + * console.log('elementValue', elementValue); + * // potentially other async stuff going on * // on finished, call the done callback * done(); * }) * // * // asynchronous completion including api (client) - * .perform(function(client, done) { - * console.log('elementValue', elementValue); - * // similar to before, but now with client - * // potentially other async stuff going on + * .perform(function(client, done) { + * console.log('elementValue', elementValue); + * // similar to before, but now with client + * // potentially other async stuff going on * // on finished, call the done callback * done(); * }); * }; * ``` - * @param callback: The function to run as part of the queue. Its signature can have up to two parameters. No parameters: callback runs and - * perform completes immediately at the end of the execution of the callback. One parameter: allows for asynchronous execution within the - * callback providing a done callback function for completion as the first argument. Two parameters: allows for asynchronous execution + * @param callback: The function to run as part of the queue. Its signature can have up to two parameters. No parameters: callback runs and + * perform completes immediately at the end of the execution of the callback. One parameter: allows for asynchronous execution within the + * callback providing a done callback function for completion as the first argument. Two parameters: allows for asynchronous execution * with the "api" object passed in as the first argument, followed by the done callback. - * @returns {} + * @returns {} */ perform: (callback: (browser: NightWatchBrowser, done?: () => void) => void) => NightWatchBrowser; /** - * Resizes the current window. - * + * Resizes the current window. + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.resizeWindow(1000, 800); * }; * ``` - * @param width: The new window width. - * @param height: The new window height. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param width: The new window width. + * @param height: The new window height. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ resizeWindow: (width: number, height: number, callback?: () => void) => NightWatchBrowser; /** * Take a screenshot of the current page and saves it as the given filename. - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.saveScreenshot('/path/to/fileName.png'); * }; * ``` - * @param fileName: The complete path to the file name where the screenshot should be saved. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param fileName: The complete path to the file name where the screenshot should be saved. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ saveScreenshot: (fileName: string, callback?: () => void) => NightWatchBrowser; @@ -1341,70 +1353,70 @@ export interface NightWatchClient { * SessionId of the session used by the Nightwatch api. */ sessionId: string; - + /** * Override the sessionId used by Nightwatch client with another session id. * @param sessionId: The session Id to set. - * @returns {} + * @returns {} */ setSessionId: (sessionId: string) => NightWatchBrowser; /** - * Set a cookie, specified as a cookie JSON object, as defined https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object. + * Set a cookie, specified as a cookie JSON object, as defined https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object. * Uses cookie protocol command. - * + * * Usage: * ``` - * this.demoTest = function(browser) { - * browser.setCookie({ - * name : "test_cookie", - * value : "test_value", - * path : "/", (Optional) - * domain : "example.org", (Optional) - * secure : false, (Optional) - * httpOnly : false, // (Optional) + * this.demoTest = function(browser) { + * browser.setCookie({ + * name : "test_cookie", + * value : "test_value", + * path : "/", (Optional) + * domain : "example.org", (Optional) + * secure : false, (Optional) + * httpOnly : false, // (Optional) * expiry : 1395002765 // (Optional) time in seconds since midnight, January 1, 1970 UTC * }); * } * ``` - * @param cookie: The cookie object. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param cookie: The cookie object. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ setCookie: (cookie: any, callback?: () => void) => NightWatchBrowser; /** * Sends some text to an element. Can be used to set the value of a form element or to send a sequence of key strokes to an element. Any UTF-8 character may be specified. - * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec (http://www.w3.org/TR/webdriver/#character-types), + * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec (http://www.w3.org/TR/webdriver/#character-types), * is loaded onto the main Nightwatch instance as client.Keys. - * + * * Usage: * ``` - * // send some simple text to an input - * this.demoTest = function (browser) { + * // send some simple text to an input + * this.demoTest = function (browser) { * browser.setValue('input[type=text]', 'nightwatch'); * }; - * + * * // - * // send some text to an input and hit enter. - * this.demoTest = function (browser) { + * // send some text to an input and hit enter. + * this.demoTest = function (browser) { * browser.setValue('input[type=text]', ['nightwatch', browser.Keys.ENTER]); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param inputValue: The text to send to the element or key strokes. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param inputValue: The text to send to the element or key strokes. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ setValue: (selector: string, inputValue: string, callback?: () => void) => NightWatchBrowser; /** * Sets the current window position. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.setWindowPosition(0, 0); + * this.demoTest = function (browser) { + * browser.setWindowPosition(0, 0); * }; * ``` * @param OffsetX: The new window offset x-position. @@ -1416,98 +1428,98 @@ export interface NightWatchClient { /** * Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. Uses submit protocol command. - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.submitForm('form.login'); * }; * ``` - * @param selector: The CSS/Xpath selector used to locate the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param selector: The CSS/Xpath selector used to locate the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ submitForm: (selector: string, callback?: () => void) => NightWatchBrowser; /** * Change focus to another window. The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute. * To find out the window handle use window_handles protocol action - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.window_handles(function(result) { - * var handle = result.value[0]; - * browser.switchWindow(handle); + * this.demoTest = function (browser) { + * browser.window_handles(function(result) { + * var handle = result.value[0]; + * browser.switchWindow(handle); * }); * }; * ``` - * @param handleOrName: The server assigned window handle or the name attribute. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param handleOrName: The server assigned window handle or the name attribute. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ switchWindow: (handleOrName: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Convenience method that adds the specified hash (i.e. url fragment) to the current value of the launch_url as set in nightwatch.json. - * - * Usage: + * + * Usage: * ``` - * this.demoTest = function (client) { + * this.demoTest = function (client) { * client.urlHash('#hashvalue'); - * // or + * // or * client.urlHash('hashvalue'); * }; * ``` - * @param hash: The hash to add/replace to the current url (i.e. the value set in the launch_url property in nightwatch.json). - * @param callback: - * @returns {} + * @param hash: The hash to add/replace to the current url (i.e. the value set in the launch_url property in nightwatch.json). + * @param callback: + * @returns {} */ urlHash: (hash: string) => NightWatchBrowser; - + /** - * Opposite of waitForElementPresent. Waits a given time in milliseconds for an element to be not present (i.e. removed) in the page before performing any other commands - * or assertions. If the element is still present after the specified amount of time, the test fails. You can change the polling interval by defining + * Opposite of waitForElementPresent. Waits a given time in milliseconds for an element to be not present (i.e. removed) in the page before performing any other commands + * or assertions. If the element is still present after the specified amount of time, the test fails. You can change the polling interval by defining * a waitForConditionPollInterval property (in milliseconds) in as a global property in your nightwatch.json or in your external globals file. * Similarly, a default timeout can be specified as a global waitForConditionTimeout property (in milliseconds). - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.waitForElementNotPresent('#dialog', 1000); * }; * ``` - * @param selector: The selector (CSS / Xpath) used to locate the element. - * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. - * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. - * To set this globally you can define a property `abortOnAssertionFailure` in your globals. - * @param callback: Optional callback function to be called when the command finishes. - * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time + * @param selector: The selector (CSS / Xpath) used to locate the element. + * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. + * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. + * To set this globally you can define a property `abortOnAssertionFailure` in your globals. + * @param callback: Optional callback function to be called when the command finishes. + * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time * (e.g. Element %s was not in the page for %d ms). - * @returns {} + * @returns {} */ waitForElementNotPresent: (selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string) => NightWatchBrowser; /** - * Opposite of waitForElementVisible. Waits a given time in milliseconds for an element to be not visible (i.e. hidden but existing) in the page before performing - * any other commands or assertions. If the element fails to be hidden in the specified amount of time, the test fails. You can change the polling interval by + * Opposite of waitForElementVisible. Waits a given time in milliseconds for an element to be not visible (i.e. hidden but existing) in the page before performing + * any other commands or assertions. If the element fails to be hidden in the specified amount of time, the test fails. You can change the polling interval by * defining a waitForConditionPollInterval property (in milliseconds) in as a global property in your nightwatch.json or in your external globals file. * Similarly, a default timeout can be specified as a global waitForConditionTimeout property (in milliseconds). - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.waitForElementNotVisible('#dialog', 1000); * }; * ``` - * @param selector: The selector (CSS / Xpath) used to locate the element. - * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. - * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. - * To set this globally you can define a property `abortOnAssertionFailure` in your globals. - * @param callback: Optional callback function to be called when the command finishes. - * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time + * @param selector: The selector (CSS / Xpath) used to locate the element. + * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. + * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. + * To set this globally you can define a property `abortOnAssertionFailure` in your globals. + * @param callback: Optional callback function to be called when the command finishes. + * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time * (e.g. Element %s was not in the page for %d ms). - * @returns {} + * @returns {} */ waitForElementNotVisible: (selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string) => NightWatchBrowser; @@ -1515,80 +1527,80 @@ export interface NightWatchClient { /** * Waits a given time in milliseconds for an element to be present in the page before performing any other commands or assertions. * If the element fails to be present in the specified amount of time, the test fails. You can change this by setting abortOnFailure to false. - * You can change the polling interval by defining a waitForConditionPollInterval property (in milliseconds) in as a global property in your nightwatch.json or in + * You can change the polling interval by defining a waitForConditionPollInterval property (in milliseconds) in as a global property in your nightwatch.json or in * your external globals file. * Similarly, a default timeout can be specified as a global waitForConditionTimeout property (in milliseconds). - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser.waitForElementPresent('body', 1000); * // continue if failed * browser.waitForElementPresent('body', 1000, false); * // with callback - * browser.waitForElementPresent('body', 1000, function() { - * // do something while we're here + * browser.waitForElementPresent('body', 1000, function() { + * // do something while we're here * }); - * // custom Spanish message - * browser.waitForElementPresent('body', 1000, 'elemento %s no era presente en %d ms'); - * // many combinations possible - the message is always the last argument + * // custom Spanish message + * browser.waitForElementPresent('body', 1000, 'elemento %s no era presente en %d ms'); + * // many combinations possible - the message is always the last argument * browser.waitForElementPresent('body', 1000, false, function() {}, 'elemento %s no era presente en %d ms'); * }; - * ``` - * @param selector: The selector (CSS / Xpath) used to locate the element. - * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. - * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. - * To set this globally you can define a property `abortOnAssertionFailure` in your globals. - * @param callback: Optional callback function to be called when the command finishes. - * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time + * ``` + * @param selector: The selector (CSS / Xpath) used to locate the element. + * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. + * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. + * To set this globally you can define a property `abortOnAssertionFailure` in your globals. + * @param callback: Optional callback function to be called when the command finishes. + * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time * (e.g. Element %s was not in the page for %d ms). - * @returns {} + * @returns {} */ waitForElementPresent: (selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string) => NightWatchBrowser; /** * Waits a given time in milliseconds for an element to be visible in the page before performing any other commands or assertions. * If the element fails to be present and visible in the specified amount of time, the test fails. You can change this by setting abortOnFailure to false. - * You can change the polling interval by defining a waitForConditionPollInterval property (in milliseconds) in as a global property in your nightwatch.json + * You can change the polling interval by defining a waitForConditionPollInterval property (in milliseconds) in as a global property in your nightwatch.json * or in your external globals file. - * Similarly, a default timeout can be specified as a global waitForConditionTimeout property (in milliseconds). - * + * Similarly, a default timeout can be specified as a global waitForConditionTimeout property (in milliseconds). + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.waitForElementVisible('body', 1000); + * this.demoTest = function (browser) { + * browser.waitForElementVisible('body', 1000); * // continue if failed - * browser.waitForElementVisible('body', 1000, false); - * // with callback - * browser.waitForElementVisible('body', 1000, function() { + * browser.waitForElementVisible('body', 1000, false); + * // with callback + * browser.waitForElementVisible('body', 1000, function() { * // do something while we're here - * }); - * // custom Spanish message - * browser.waitForElementVisible('body', 1000, 'elemento %s no era visible en %d ms'); - * // many combinations possible - the message is always the last argument - * browser.waitForElementVisible('body', 1000, false, function() {}, 'elemento %s no era visible en %d ms'); + * }); + * // custom Spanish message + * browser.waitForElementVisible('body', 1000, 'elemento %s no era visible en %d ms'); + * // many combinations possible - the message is always the last argument + * browser.waitForElementVisible('body', 1000, false, function() {}, 'elemento %s no era visible en %d ms'); * }; - * ``` - * @param selector: The selector (CSS / Xpath) used to locate the element. - * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. - * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnAssertionFailure` in your globals. - * @param callback: Optional callback function to be called when the command finishes. + * ``` + * @param selector: The selector (CSS / Xpath) used to locate the element. + * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. + * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnAssertionFailure` in your globals. + * @param callback: Optional callback function to be called when the command finishes. * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time (e.g. Element %s was not in the page for %d ms). - * @returns {} + * @returns {} */ waitForElementVisible: (selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string) => NightWatchBrowser; /** * Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ acceptAlert: (callback?: () => void) => NightWatchBrowser; /** * Navigate backwards in the browser history, if possible. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ back: (callback?: () => void) => NightWatchBrowser; @@ -1596,569 +1608,569 @@ export interface NightWatchClient { * Get a list of the available contexts. * Used by Appium when testing hybrid mobile web apps. More info here: https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/hybrid.md. * @param callback: Callback function to be called when the command finishes. - * @returns {an array of strings representing available contexts, e.g 'WEBVIEW', or 'NATIVE'} + * @returns {an array of strings representing available contexts, e.g 'WEBVIEW', or 'NATIVE'} */ contexts: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Retrieve or delete all cookies visible to the current page or set a cookie. - * @param method - * @param callbackorCookie - * @returns {a string representing the current context or `null`, representing "no context"} + * @param method + * @param callbackorCookie + * @returns {a string representing the current context or `null`, representing "no context"} */ cookie: (method: string, callbackorCookie?: () => void) => NightWatchBrowser; /** - * Get current context. - * @param callback: Callback function to be called when the command finishes. - * @returns {} + * Get current context. + * @param callback: Callback function to be called when the command finishes. + * @returns {} */ currentContext: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Dismisses the currently displayed alert dialog. For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button. * For alert() dialogs, this is equivalent to clicking the 'OK' button. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ dismissAlert: (callback?: () => void) => NightWatchBrowser; /** * Double-clicks at the current mouse coordinates (set by moveto). - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ doubleClick: (callback?: () => void) => NightWatchBrowser; /** * Search for an element on the page, starting from the document root. The located element will be returned as a WebElement JSON object. - * + * * Usage: * ``` - * module.exports = { - * 'demo Test' : function(browser) { - * browser.element('css selector', 'body', function(res) { + * module.exports = { + * 'demo Test' : function(browser) { + * browser.element('css selector', 'body', function(res) { * console.log(res) * }); * } * }; * ``` - * @param using: The locator's strategy to use. - * @param value: The search target. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param using: The locator's strategy to use. + * @param value: The search target. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ element: (using: string, value: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Get the element on the page that currently has focus. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementActive: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Get the value of an element's attribute. - * @param id: ID of the element to route the command to. - * @param attributeName: The attribute name - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param attributeName: The attribute name + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdAttribute: (id: string, attributeName: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Clear a TEXTAREA or text INPUT element's value. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdClear: (id: string, callback?: () => void) => NightWatchBrowser; /** * Click on an element. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdClick: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** - * Query the value of an element's computed CSS property. + * Query the value of an element's computed CSS property. * The CSS property to query should be specified using the CSS property name, not the JavaScript property name (e.g. background-color instead of backgroundColor). - * @param id - * @param cssPropertyName - * @param callback - * @returns {} + * @param id + * @param cssPropertyName + * @param callback + * @returns {} */ elementIdCssProperty: (id: string, cssPropertyName: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine if an element is currently displayed. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdDisplayed: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Search for an element on the page, starting from the identified element. The located element will be returned as a WebElement JSON object. - * @param id: ID of the element to route the command to. - * @param using: The locator strategy to use. - * @param value: The search target. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param using: The locator strategy to use. + * @param value: The search target. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdElement: (id: string, using: string, value: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Search for multiple elements on the page, starting from the identified element. The located element will be returned as a WebElement JSON objects. - * @param id: ID of the element to route the command to. - * @param using: The locator strategy to use. - * @param value: The search target. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param using: The locator strategy to use. + * @param value: The search target. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdElements: (id: string, using: string, value: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine if an element is currently enabled. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdEnabled: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Test if two element IDs refer to the same DOM element. - * @param id: ID of the element to route the command to. - * @param otherId: ID of the element to compare against. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param otherId: ID of the element to compare against. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdEquals: (id: string, otherId: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. * The element's coordinates are returned as a JSON object with x and y properties. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The X and Y coordinates for the element on the page.} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The X and Y coordinates for the element on the page.} */ elementIdLocation: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine an element's location on the screen once it has been scrolled into view. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdLocationInView: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Query for an element's tag name. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdName: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdSelected: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdSize: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Returns the visible text for the element. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ elementIdText: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Send a sequence of key strokes to an element or returns the current value of the element. - * @param id: ID of the element to route the command to. + * @param id: ID of the element to route the command to. * @param value: Value to send to element in case of POST - * @param callback - * @returns {} + * @param callback + * @returns {} */ elementIdValue: (id: string, value?: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Search for multiple elements on the page, starting from the document root. The located elements will be returned as a WebElement JSON objects. * Valid strings to use as locator strategies are: "class name", "css selector", "id", "name", "link text", "partial link text", "tag name", "xpath" - * @param using: The locator strategy to use. - * @param value: The search target. - * @param callback: Callback function to be invoked with the result when the command finishes. - * @returns {} + * @param using: The locator strategy to use. + * @param value: The search target. + * @param callback: Callback function to be invoked with the result when the command finishes. + * @returns {} */ elements: (using: string, value: string, callback: (result: CallbackResult) => void) => NightWatchBrowser; /** - * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous and + * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous and * the result of evaluating the script is returned to the client. * The script argument defines the script to execute in the form of a function body. The value returned by that function will be returned to the client. * The function will be invoked with the provided args array and the values may be accessed via the arguments object in the order specified. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.execute(function(data) { + * this.demoTest = function (browser) { + * browser.execute(function(data) { * // resize operation * return true; - * }, [imagedata], function(result) { + * }, [imagedata], function(result) { * ... * }); * }; * ``` - * @param body: The function body to be injected. - * @param args: An array of arguments which will be passed to the function. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The script result.} + * @param body: The function body to be injected. + * @param args: An array of arguments which will be passed to the function. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The script result.} */ execute: (body: ((...data: any[]) => void) | string, args?: any[], callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** - * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be asynchronous - * and the result of evaluating the script is returned to the client. + * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be asynchronous + * and the result of evaluating the script is returned to the client. * Asynchronous script commands may not span page loads. If an unload event is fired while waiting for a script result, an error should be returned to the client. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.executeAsync(function(data, done) { - * someAsyncOperation(function() { - * done(true); + * this.demoTest = function (browser) { + * browser.executeAsync(function(data, done) { + * someAsyncOperation(function() { + * done(true); * }); - * }, [imagedata], function(result) { + * }, [imagedata], function(result) { * // ... * }); * }; * ``` - * @param script: The function body to be injected. - * @param args: An array of arguments which will be passed to the function. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The script result.} + * @param script: The function body to be injected. + * @param args: An array of arguments which will be passed to the function. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The script result.} */ executeAsync: (script: ((...data: any[]) => void) | string, args?: any[], callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Navigate forwards in the browser history, if possible. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ forward: (callback?: () => void) => NightWatchBrowser; /** - * Change focus to another frame on the page. If the frame id is missing or null, the server should switch to the page's default content. - * @param frameId: Identifier for the frame to change focus to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * Change focus to another frame on the page. If the frame id is missing or null, the server should switch to the page's default content. + * @param frameId: Identifier for the frame to change focus to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ frame: (frameId?: string, callback?: () => void) => NightWatchBrowser; /** * Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ frameParent: (callback?: () => void) => NightWatchBrowser; /** - * Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {The text of the currently displayed alert.} + * Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {The text of the currently displayed alert.} */ getAlertText: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Get the current browser orientation. - * @param callback: Callback function to be called when the command finishes. - * @returns {The current browser orientation: LANDSCAPE|PORTRAIT} + * @param callback: Callback function to be called when the command finishes. + * @returns {The current browser orientation: LANDSCAPE|PORTRAIT} */ getOrientation: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** - * Send a sequence of key strokes to the active element. The sequence is defined in the same format as the sendKeys command. - * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec, is loaded onto the main Nightwatch instance as client.Keys. + * Send a sequence of key strokes to the active element. The sequence is defined in the same format as the sendKeys command. + * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec, is loaded onto the main Nightwatch instance as client.Keys. * Rather than the setValue, the modifiers are not released at the end of the call. The state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed. - * @param keysToSend: The keys sequence to be sent. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param keysToSend: The keys sequence to be sent. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ keys: (keysToSend: string[], callback?: () => void) => NightWatchBrowser; /** - * Click at the current mouse coordinates (set by moveto). + * Click at the current mouse coordinates (set by moveto). * The button can be (0, 1, 2) or ('left', 'middle', 'right'). It defaults to left mouse button, and if you don't pass in a button but do pass in a callback, it will handle it correctly. - * @param button: The mouse button - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param button: The mouse button + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ mouseButtonClick: (button: string, callback?: () => void) => NightWatchBrowser; /** - * Click and hold the left mouse button (at the coordinates set by the last moveto command). Note that the next mouse-related command that should follow is mouseButtonUp . Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour. + * Click and hold the left mouse button (at the coordinates set by the last moveto command). Note that the next mouse-related command that should follow is mouseButtonUp . Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour. * Can be used for implementing drag-and-drop. The button can be (0, 1, 2) or ('left', 'middle', 'right'). It defaults to left mouse button, and if you don't pass in a button but do pass in a callback, it will handle it correctly. * @param button: The mouse button - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ mouseButtonDown: (button: string, callback?: () => void) => NightWatchBrowser; /** - * Releases the mouse button previously held (where the mouse is currently at). Must be called once for every mouseButtonDown command issued. + * Releases the mouse button previously held (where the mouse is currently at). Must be called once for every mouseButtonDown command issued. * Can be used for implementing drag-and-drop. The button can be (0, 1, 2) or ('left', 'middle', 'right'). It defaults to left mouse button, and if you don't pass in a button but do pass in a callback, it will handle it correctly. - * @param button: The mouse button - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param button: The mouse button + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ mouseButtonUp: (button: string, callback?: () => void) => NightWatchBrowser; /** - * Move the mouse by an offset of the specificed element. If no element is specified, the move is relative to the current mouse cursor. If an element is provided but no offset, the mouse will be moved to the center of the element. + * Move the mouse by an offset of the specificed element. If no element is specified, the move is relative to the current mouse cursor. If an element is provided but no offset, the mouse will be moved to the center of the element. * If the element is not visible, it will be scrolled into view. - * @param element: Opaque ID assigned to the element to move to. If not specified or is null, the offset is relative to current position of the mouse. - * @param xofset: X offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. - * @param yoffset: Y offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param element: Opaque ID assigned to the element to move to. If not specified or is null, the offset is relative to current position of the mouse. + * @param xofset: X offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. + * @param yoffset: Y offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ moveTo: (element: string, xofset: number, yoffset: number, callback?: () => void) => NightWatchBrowser; /** * Refresh the current page. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ refresh: (callback?: () => void) => NightWatchBrowser; /** * Take a screenshot of the current page. - * @param log_screenshot_data: Whether or not the screenshot data should appear in the logs when running with --verbose - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param log_screenshot_data: Whether or not the screenshot data should appear in the logs when running with --verbose + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ screenshot: (log_screenshot_data: boolean, callback?: () => void) => NightWatchBrowser; /** * Get info about, delete or create a new session. Defaults to the current session. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.session(function(result) { + * this.demoTest = function (browser) { + * browser.session(function(result) { * console.log(result.value); - * }); - * // - * browser.session('delete', function(result) { + * }); + * // + * browser.session('delete', function(result) { * console.log(result.value); - * }); + * }); * // - * browser.session('delete', '12345-abc', function(result) { - * console.log(result.value); + * browser.session('delete', '12345-abc', function(result) { + * console.log(result.value); * }); * }; * ``` - * @param action: The http verb to use, can be "get", "post" or "delete". If only the callback is passed, get is assumed as default. - * @param sessionId: The id of the session to get info about or delete. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param action: The http verb to use, can be "get", "post" or "delete". If only the callback is passed, get is assumed as default. + * @param sessionId: The id of the session to get info about or delete. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ session: (action?: string, sessionId?: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Gets the text of the log type specified - * @param typeString: Type of log to request - * @param callback: Optional callback function to be called when the command finishes. - * @returns {Array of the text entries of the log.} + * @param typeString: Type of log to request + * @param callback: Optional callback function to be called when the command finishes. + * @returns {Array of the text entries of the log.} */ sessionLog: (typeString: string, callback?: (log: LogEntry[]) => void) => NightWatchBrowser; /** * Gets an array of strings for which log types are available. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {Available log types} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {Available log types} */ sessionLogTypes: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Returns a list of the currently active sessions. - * + * * Usage: * ``` - * this.demoTest = function (browser) { - * browser.sessions(function(result) { - * console.log(result.value); - * }); + * this.demoTest = function (browser) { + * browser.sessions(function(result) { + * console.log(result.value); + * }); * }; * ``` - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ sessions: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Sends keystrokes to a JavaScript prompt() dialog. - * @param value: Keystrokes to send to the prompt() dialog - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param value: Keystrokes to send to the prompt() dialog + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ setAlertText: (value: string, callback?: () => void) => NightWatchBrowser; /** * Sets the context - * @param context: context name to switch to - a string representing an available context. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param context: context name to switch to - a string representing an available context. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ setContext: (context: string, callback?: () => void) => NightWatchBrowser; /** - * Sets the browser orientation. - * @param orientation: The new browser orientation: {LANDSCAPE|PORTRAIT} - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * Sets the browser orientation. + * @param orientation: The new browser orientation: {LANDSCAPE|PORTRAIT} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ setOrientation: (orientation: string, callback?: () => void) => NightWatchBrowser; /** * Get the current page source. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ source: (callback?: () => void) => NightWatchBrowser; /** * Query the server's current status. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ status: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. - * @param id: ID of the element to route the command to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param id: ID of the element to route the command to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ submit: (id: string, callback?: () => void) => NightWatchBrowser; /** * Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client. - * @param typeOfOperation: The type of operation to set the timeout for. Valid values are: "script" for script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting a page load timeout. - * @param ms: The amount of time, in milliseconds, that time-limited commands are permitted to run. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param typeOfOperation: The type of operation to set the timeout for. Valid values are: "script" for script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting a page load timeout. + * @param ms: The amount of time, in milliseconds, that time-limited commands are permitted to run. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ timeouts: (typeOfOperation: string, ms: number, callback?: () => void) => NightWatchBrowser; /** * Set the amount of time, in milliseconds, that asynchronous scripts executed by /session/:sessionId/execute_async are permitted to run before they are aborted and a |Timeout| error is returned to the client. - * @param ms: The amount of time, in milliseconds, that time-limited commands are permitted to run. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param ms: The amount of time, in milliseconds, that time-limited commands are permitted to run. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ timeoutsAsyncScript: (ms: number, callback?: () => void) => NightWatchBrowser; /** * Set the amount of time the driver should wait when searching for elements. If this command is never sent, the driver will default to an implicit wait of 0ms. - * @param ms: The amount of time, in milliseconds, that time-limited commands are permitted to run. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param ms: The amount of time, in milliseconds, that time-limited commands are permitted to run. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ timeoutsImplicitWait: (ms: number, callback?: () => void) => NightWatchBrowser; /** * Get the current page title. - * @param expected: The expected page title. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param expected: The expected page title. + * @param msg: Optional log message to display in the output. If missing, one is displayed by default. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ title: (expected: string, msg?: string, callback?: () => void) => NightWatchBrowser; /** * Retrieve the URL of the current page or navigate to a new URL. - * + * * Usage: * ``` - * module.exports = { - * 'demo Test' : function(browser) { - * browser.url(function(result) { - * // return the current url - * console.log(result); - * }); - * // + * module.exports = { + * 'demo Test' : function(browser) { + * browser.url(function(result) { + * // return the current url + * console.log(result); + * }); + * // * // navigate to new url: - * browser.url('{URL}'); + * browser.url('{URL}'); * // * // - * // navigate to new url: - * browser.url('{URL}', function(result) { - * console.log(result); + * // navigate to new url: + * browser.url('{URL}', function(result) { + * console.log(result); * }); * } * }; * ``` - * @param url: If missing, it will return the URL of the current page as an argument to the supplied callback - * @param callback Optional callback function to be called when the command finishes. - * @returns {} + * @param url: If missing, it will return the URL of the current page as an argument to the supplied callback + * @param callback Optional callback function to be called when the command finishes. + * @returns {} */ url: (url?: string | ((result: CallbackResult) => void), callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Change focus to another window or close the current window. - * @param method: The HTTP method to use - * @param handleOrName: The window to change focus to. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param method: The HTTP method to use + * @param handleOrName: The window to change focus to. + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ window: (method: string, handleOrName: string, callback?: () => void) => NightWatchBrowser; /** * Retrieve the current window handle. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ windowHandle: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Retrieve the list of all window handles available to the session. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ windowHandles: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Retrieve the list of all window handles available to the session. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ window_handles: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; /** * Retrieve the current window handle. * @param handleOrName: windowHandle URL parameter; if it is "current", the currently active window will be maximized. - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ windowMaximize: (handleOrName?: string, callback?: () => void) => NightWatchBrowser; /** * Change or get the position of the specified window. If the second argument is a function it will be used as a callback and the call will perform a get request to retrieve the existing window position. - * @param windowHandle: + * @param windowHandle: * @param: offsetX: * @param: offsetY: * @param: callback: @@ -2168,42 +2180,42 @@ export interface NightWatchClient { /** * Change or get the size of the specified window. If the second argument is a function it will be used as a callback and the call will perform a get request to retrieve the existing window size. - * @param windowHandle: - * @param width: - * @param height: - * @param callback: Optional callback function to be called when the command finishes. - * @returns {} + * @param windowHandle: + * @param width: + * @param height: + * @param callback: Optional callback function to be called when the command finishes. + * @returns {} */ windowSize: (windowHandle: string, width: number, height: number, callback?: () => void) => NightWatchBrowser; /** - * To switch to xpath selectors instead of css as the locate strategy. + * To switch to xpath selectors instead of css as the locate strategy. * To always use xpath by default set the property "use_xpath": true in your test settings. - * + * * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser * .useXpath() // every selector now must be xpath * .click("//tr[@data-recordid]/span[text()='Search Text']"); * }; * ``` - * @returns {} + * @returns {} */ useXpath: () => NightWatchBrowser; /** * To switch to css selectors instead of xpath as the locate strategy - * - * Usage: + * + * Usage: * ``` - * this.demoTest = function (browser) { + * this.demoTest = function (browser) { * browser * .useCss() // we're back to CSS now * .setValue('input[type=text]', 'nightwatch'); * }; * ``` - * @returns {} + * @returns {} */ useCss: () => NightWatchBrowser; @@ -2216,8 +2228,10 @@ export interface NightWatchClient { launch_url: string; } -export interface NightWatchBrowser extends NightWatchClient, NightWatchCustomCommands, NightWatchCustomPageObjects { } +interface NightWatchBrowser extends NightWatchClient, NightWatchCustomCommands, NightWatchCustomPageObjects { } +interface NightWatchTest { + (arg1: NightWatchBrowser): void; +} - - +interface NightWatchTests {[key: string]: NightWatchTest} diff --git a/types/nightwatch/nightwatch-tests.ts b/types/nightwatch/nightwatch-tests.ts new file mode 100644 index 0000000..319091b --- /dev/null +++ b/types/nightwatch/nightwatch-tests.ts @@ -0,0 +1,13 @@ +export = { + 'Demo test Google': function (browser) { + browser + .url('http://www.google.com') + .waitForElementVisible('body', 1000) + .setValue('input[type=text]', 'nightwatch') + .waitForElementVisible('button[name=btnG]', 1000) + .click('button[name=btnG]') + .pause(1000) + .assert.containsText('#main', 'Night Watch') + .end(); + } +} as NightWatchTests; diff --git a/types/nightwatch/tsconfig.json b/types/nightwatch/tsconfig.json new file mode 100644 index 0000000..b46be78 --- /dev/null +++ b/types/nightwatch/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "nightwatch-tests.ts" + ] +} diff --git a/types/nightwatch/tslint.json b/types/nightwatch/tslint.json new file mode 100644 index 0000000..3db14f8 --- /dev/null +++ b/types/nightwatch/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/typings.json b/typings.json deleted file mode 100644 index 24cc7c1..0000000 --- a/typings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "nightwatch", - "main": "nightwatch.d.ts" -} From 804838cd129cee23d3442082dd1804b137aa12b0 Mon Sep 17 00:00:00 2001 From: Connor Schlesiger Date: Wed, 23 Aug 2017 17:21:08 -0400 Subject: [PATCH 2/6] Update files according to linter and add dom lib --- types/nightwatch/index.d.ts | 325 +++++++++++++-------------- types/nightwatch/nightwatch-tests.ts | 8 +- types/nightwatch/tsconfig.json | 3 +- 3 files changed, 159 insertions(+), 177 deletions(-) diff --git a/types/nightwatch/index.d.ts b/types/nightwatch/index.d.ts index 0596f09..5316aa4 100644 --- a/types/nightwatch/index.d.ts +++ b/types/nightwatch/index.d.ts @@ -4,17 +4,10 @@ // Connor Schlesiger // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface NightWatchCustomAssertions { -} - -interface NightWatchCustomCommands { -} - -interface NightWatchPageObjects { -} +/* tslint:disable:max-line-length */ interface NightWatchCustomPageObjects { - page: NightWatchPageObjects; + page: {}; } interface DesiredCapabilities { @@ -116,7 +109,6 @@ interface DesiredCapabilities { driver?: string; server?: string; }; - } interface ScreenshotOptions { @@ -181,8 +173,8 @@ interface NightWatchOptions { test_settings: NightWatchTestSettings; /** - * Whether or not to buffer the output in case of parallel running. See below for details. - */ + * Whether or not to buffer the output in case of parallel running. See below for details. + */ live_output?: boolean; /** @@ -256,7 +248,6 @@ interface SeleniumOptions { * name in the desiredCapabilities object. */ cli_args: any; - } interface NightWatchTestSettings { @@ -404,13 +395,12 @@ interface LanguageChains { } interface Expect extends LanguageChains, NightWatchBrowser { - /** * Returns the DOM Element * @param property: Css / Id property of the DOM element * @returns {} */ - element: (property: string) => NightWatchBrowser; + element(property: string): NightWatchBrowser; /** * These methods will perform assertions on the specified target on the current element. @@ -419,9 +409,9 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param message * @returns {} */ - equal: (value: string) => NightWatchBrowser; - contain: (value: string) => NightWatchBrowser; - match: (value: string) => NightWatchBrowser; + equal(value: string): NightWatchBrowser; + contain(value: string): NightWatchBrowser; + match(value: string): NightWatchBrowser; /** * Negates any of assertions following in the chain. @@ -436,8 +426,8 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param value: Number of milliseconds to wait to perform and operation of check * @returns {} */ - before: (value: number) => NightWatchBrowser; - after: (value: number) => NightWatchBrowser; + before(value: number): NightWatchBrowser; + after(value: number): NightWatchBrowser; /** * Checks if the type (i.e. tag name) of a specified element is of an expected value. @@ -445,8 +435,8 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - a: (value: string, message?: string) => NightWatchBrowser; - an: (value: string, message?: string) => NightWatchBrowser; + a(value: string, message?: string): NightWatchBrowser; + an(value: string, message?: string): NightWatchBrowser; /** * Checks if a given attribute of an element exists and optionally if it has the expected value. @@ -454,7 +444,7 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - attribute: (name: string, message?: string) => NightWatchBrowser; + attribute(name: string, message?: string): NightWatchBrowser; /** * Checks a given css property of an element exists and optionally if it has the expected value. @@ -462,7 +452,7 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - css: (property: string, message?: string) => NightWatchBrowser; + css(property: string, message?: string): NightWatchBrowser; /** * Property that checks if an element is currently enabled. @@ -504,7 +494,7 @@ interface Assertion extends NightWatchBrowser { * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - attributeContains: (selector: string, attribute: string, expected: string, message?: string) => NightWatchBrowser; + attributeContains(selector: string, attribute: string, expected: string, message?: string): NightWatchBrowser; /** * Checks if the given attribute of an element has the expected value. @@ -514,7 +504,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - attributeEquals: (cssSelector: string, attribute: string, expected: string, msg?: string) => NightWatchBrowser; + attributeEquals(cssSelector: string, attribute: string, expected: string, msg?: string): NightWatchBrowser; /** * Checks if the given element contains the specified text. @@ -523,7 +513,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - containsText: (cssSelector: string, expectedText: string, msg?: string) => NightWatchBrowser; + containsText(cssSelector: string, expectedText: string, msg?: string): NightWatchBrowser; /** * Checks if the given element has the specified CSS class. @@ -532,7 +522,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - cssClassPresent: (cssSelector: string, className: string, msg?: string) => NightWatchBrowser; + cssClassPresent(cssSelector: string, className: string, msg?: string): NightWatchBrowser; /** * Checks if the given element does not have the specified CSS class. @@ -541,7 +531,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - cssClassNotPresent: (cssSelector: string, className: string, msg?: string) => NightWatchBrowser; + cssClassNotPresent(cssSelector: string, className: string, msg?: string): NightWatchBrowser; /** * Checks if the specified css property of a given element has the expected value. @@ -551,13 +541,13 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - cssProperty: (cssSelector: string, cssProperty: string, expected: string | number, msg?: string) => NightWatchBrowser; + cssProperty(cssSelector: string, cssProperty: string, expected: string | number, msg?: string): NightWatchBrowser; - deepEqual: (value: any, expected: any, message?: string) => NightWatchBrowser; + deepEqual(value: any, expected: any, message?: string): NightWatchBrowser; - deepStrictEqual: (value: any, expected: any, message?: string) => NightWatchBrowser; + deepStrictEqual(value: any, expected: any, message?: string): NightWatchBrowser; - doesNotThrow: (value: any, expected: any, message?: string) => NightWatchBrowser; + doesNotThrow(value: any, expected: any, message?: string): NightWatchBrowser; /** * Checks if the given element exists in the DOM. @@ -565,7 +555,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - elementPresent: (cssSelector: string, msg?: string) => NightWatchBrowser; + elementPresent(cssSelector: string, msg?: string): NightWatchBrowser; /** * Checks if the given element does not exist in the DOM. @@ -573,11 +563,11 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - elementNotPresent: (cssSelector: string, msg?: string) => NightWatchBrowser; + elementNotPresent(cssSelector: string, msg?: string): NightWatchBrowser; - equal: (value: any, expected: any, message?: string) => NightWatchBrowser; + equal(value: any, expected: any, message?: string): NightWatchBrowser; - fail: (actual?: any, expected?: any, message?: string, operator?: string) => NightWatchBrowser; + fail(actual?: any, expected?: any, message?: string, operator?: string): NightWatchBrowser; /** * Checks if the given element is not visible on the page. @@ -585,33 +575,23 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - hidden: (cssSelector: string, msg?: string) => NightWatchBrowser; + hidden(cssSelector: string, msg?: string): NightWatchBrowser; - ifError: (value: any, message?: string) => NightWatchBrowser; + ifError(value: any, message?: string): NightWatchBrowser; - notDeepEqual: (actual: any, expected: any, message?: string) => NightWatchBrowser; + notDeepEqual(actual: any, expected: any, message?: string): NightWatchBrowser; - notDeepStrictEqual: (value: any, message?: string) => NightWatchBrowser; + notDeepStrictEqual(value: any, message?: string): NightWatchBrowser; - notEqual: (actual: any, expected: any, message?: string) => NightWatchBrowser; + notEqual(actual: any, expected: any, message?: string): NightWatchBrowser; - notStrictEqual: (value: any, expected: any, message?: string) => NightWatchBrowser; + notStrictEqual(value: any, expected: any, message?: string): NightWatchBrowser; - ok: (actual: boolean, message?: string) => NightWatchBrowser; + ok(actual: boolean, message?: string): NightWatchBrowser; - strictEqual: (value: any, expected: any, message?: string) => NightWatchBrowser; + strictEqual(value: any, expected: any, message?: string): NightWatchBrowser; - throws: (fn: Function, msg?: string) => NightWatchBrowser; - - /** - * Checks if the page title equals the given value. - * @param expected: The expected page title. - * @param msg: Optional log message to display in the output. If missing, one is displayed by default. - * @returns {} - * - * Defined in base class. - */ - //title: (expected: string, msg?: string) => NightWatchBrowser; + throws(fn: () => void, msg?: string): NightWatchBrowser; /** * Checks if the current URL contains the given value. @@ -619,7 +599,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - urlContains: (expectedText: string, msg?: string) => NightWatchBrowser; + urlContains(expectedText: string, msg?: string): NightWatchBrowser; /** * Checks if the current url equals the given value. @@ -627,7 +607,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - urlEquals: (expected: string, msg?: string) => NightWatchBrowser; + urlEquals(expected: string, msg?: string): NightWatchBrowser; /** * Checks if the given form element's value equals the expected value. @@ -636,7 +616,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - value: (cssSelector: string, expectedText: string, msg?: string) => NightWatchBrowser; + value(cssSelector: string, expectedText: string, msg?: string): NightWatchBrowser; /** * Checks if the given form element's value contains the expected value. @@ -645,7 +625,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - valueContains: (cssSelector: string, expectedText: string, msg?: string) => NightWatchBrowser; + valueContains(cssSelector: string, expectedText: string, msg?: string): NightWatchBrowser; /** * Checks if the given element is visible on the page. @@ -653,7 +633,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - visible: (cssSelector: string, msg?: string) => NightWatchBrowser; + visible(cssSelector: string, msg?: string): NightWatchBrowser; AssertionError: AssertionError; } @@ -663,6 +643,7 @@ interface TypedCallbackResult { value: T; } +// tslint:disable-next-line:no-empty-interface interface CallbackResult extends TypedCallbackResult { } @@ -804,12 +785,9 @@ interface Keys { "META": string; /** The command (⌘) key. */ "COMMAND": string; - - } interface NightWatchClient { - assert: Assertion; expect: Expect; @@ -829,7 +807,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - clearValue: (selector: string, callback?: () => void) => NightWatchBrowser; + clearValue(selector: string, callback?: () => void): NightWatchBrowser; /** * Simulates a click event on the given DOM element. Uses elementIdClick protocol command. @@ -844,7 +822,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - click: (selector: string, callback?: () => void) => NightWatchBrowser; + click(selector: string, callback?: () => void): NightWatchBrowser; /** * Close the current window. This can be useful when you're working with multiple windows open (e.g. an OAuth login). Uses window protocol command. @@ -858,7 +836,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - closeWindow: (callback?: () => void) => NightWatchBrowser; + closeWindow(callback?: () => void): NightWatchBrowser; /** * Delete the cookie with the given name. This command is a no-op if there is no such cookie visible to the current page. @@ -875,7 +853,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - deleteCookie: (The: string, callback?: () => void) => NightWatchBrowser; + deleteCookie(The: string, callback?: () => void): NightWatchBrowser; /** * Delete all cookies visible to the current page. @@ -891,7 +869,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - deleteCookies: (callback?: () => void) => NightWatchBrowser; + deleteCookies(callback?: () => void): NightWatchBrowser; /** * Ends the session. Uses session protocol command. @@ -905,7 +883,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - end: (callback?: () => void) => NightWatchBrowser; + end(callback?: () => void): NightWatchBrowser; /** * Retrieve the value of an attribute for a given DOM element. Uses elementIdAttribute protocol command. @@ -925,7 +903,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The value of the attribute} */ - getAttribute: (selector: string, attribute: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getAttribute(selector: string, attribute: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Retrieve a single cookie visible to the current page. The cookie is returned as a cookie JSON object, as defined here. @@ -944,7 +922,7 @@ interface NightWatchClient { * @param callback: The callback function which will receive the response as an argument. * @returns {The cookie object as a selenium cookie JSON object or null if the cookie wasn't found.} */ - getCookie: (name: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getCookie(name: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Retrieve all cookies visible to the current page. The cookies are returned as an array of cookie JSON object, @@ -962,7 +940,7 @@ interface NightWatchClient { * @param callback: The callback function which will receive the response as an argument. * @returns {A list of cookies} */ - getCookies: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getCookies(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Retrieve the value of a css property for a given DOM element. Uses elementIdCssProperty protocol command. @@ -982,7 +960,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The value of the css property} */ - getCssProperty: (selector: string, cssProperty: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getCssProperty(selector: string, cssProperty: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine an element's size in pixels. Uses elementIdSize protocol command. @@ -1002,7 +980,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The width and height of the element in pixels} */ - getElementSize: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getElementSize(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. @@ -1023,7 +1001,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The X and Y coordinates for the element on the page} */ - getLocation: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getLocation(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine an element's location on the screen once it has been scrolled into view. Uses elementIdLocationInView protocol command. @@ -1043,7 +1021,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The X and Y coordinates for the element on the page.} */ - getLocationInView: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getLocationInView(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Gets a log from selenium @@ -1063,7 +1041,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - getLog: (typestring: string, callback?: (log: LogEntry[]) => void) => NightWatchBrowser; + getLog(typestring: string, callback?: (log: LogEntry[]) => void): NightWatchBrowser; /** * Gets the available log types @@ -1079,7 +1057,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {Available log types} */ - getLogTypes: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getLogTypes(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Query for an element's tag name. Uses elementIdName protocol command. @@ -1098,7 +1076,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The element's tag name, as a lowercase string.} */ - getTagName: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getTagName(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Returns the visible text for the element. Uses elementIdText protocol command. @@ -1117,7 +1095,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The element's visible text.} */ - getText: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getText(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Returns the title of the current page. Uses title protocol command. @@ -1134,7 +1112,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The page title.} */ - getTitle: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getTitle(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Returns a form element current value. Uses elementIdValue protocol command. @@ -1153,7 +1131,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The element's value.} */ - getValue: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getValue(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * This command is an alias to url and also a convenience method when called without any arguments in the sense that it performs a call to .url() with passing the value of launch_url @@ -1168,7 +1146,7 @@ interface NightWatchClient { * @param url: Url to navigate to. * @returns {} */ - init: (url?: string) => NightWatchBrowser; + init(url?: string): NightWatchBrowser; /** * Utility command to load an external script into the page specified by url. @@ -1186,7 +1164,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The newly created script tag.} */ - injectScript: (scriptUrl: string, id?: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + injectScript(scriptUrl: string, id?: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Utility command to test if the log type is available @@ -1203,7 +1181,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - isLogAvailable: (typeString: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + isLogAvailable(typeString: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine if an element is currently displayed. Uses elementIdDisplayed protocol command. @@ -1222,7 +1200,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - isVisible: (selector: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + isVisible(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Maximizes the current window. @@ -1236,7 +1214,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - maximizeWindow: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + maximizeWindow(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Move the mouse by an offset of the specified element. Uses moveTo protocol command. @@ -1253,7 +1231,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - moveToElement: (selector: string, xoffset: number, yoffset: number, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + moveToElement(selector: string, xoffset: number, yoffset: number, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Suspends the test for the given time in milliseconds. If the milliseconds argument is missing it will suspend the test indefinitely @@ -1270,7 +1248,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - pause: (ms: number, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + pause(ms: number, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * A simple perform command which allows access to the "api" in a callback. Can be useful if you want to read variables set by other commands. @@ -1316,7 +1294,7 @@ interface NightWatchClient { * with the "api" object passed in as the first argument, followed by the done callback. * @returns {} */ - perform: (callback: (browser: NightWatchBrowser, done?: () => void) => void) => NightWatchBrowser; + perform(callback: (browser: NightWatchBrowser, done?: () => void) => void): NightWatchBrowser; /** * Resizes the current window. @@ -1332,7 +1310,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - resizeWindow: (width: number, height: number, callback?: () => void) => NightWatchBrowser; + resizeWindow(width: number, height: number, callback?: () => void): NightWatchBrowser; /** * Take a screenshot of the current page and saves it as the given filename. @@ -1347,7 +1325,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - saveScreenshot: (fileName: string, callback?: () => void) => NightWatchBrowser; + saveScreenshot(fileName: string, callback?: () => void): NightWatchBrowser; /** * SessionId of the session used by the Nightwatch api. @@ -1359,7 +1337,7 @@ interface NightWatchClient { * @param sessionId: The session Id to set. * @returns {} */ - setSessionId: (sessionId: string) => NightWatchBrowser; + setSessionId(sessionId: string): NightWatchBrowser; /** * Set a cookie, specified as a cookie JSON object, as defined https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object. @@ -1383,7 +1361,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setCookie: (cookie: any, callback?: () => void) => NightWatchBrowser; + setCookie(cookie: any, callback?: () => void): NightWatchBrowser; /** * Sends some text to an element. Can be used to set the value of a form element or to send a sequence of key strokes to an element. Any UTF-8 character may be specified. @@ -1408,7 +1386,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setValue: (selector: string, inputValue: string, callback?: () => void) => NightWatchBrowser; + setValue(selector: string, inputValue: string, callback?: () => void): NightWatchBrowser; /** * Sets the current window position. @@ -1424,7 +1402,7 @@ interface NightWatchClient { * @param callback: ptional callback function to be called when the command finishes. * @returns {} */ - setWindowPosition: (OffsetX: number, OffsetY: number, callback?: () => void) => NightWatchBrowser; + setWindowPosition(OffsetX: number, OffsetY: number, callback?: () => void): NightWatchBrowser; /** * Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. Uses submit protocol command. @@ -1439,7 +1417,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - submitForm: (selector: string, callback?: () => void) => NightWatchBrowser; + submitForm(selector: string, callback?: () => void): NightWatchBrowser; /** * Change focus to another window. The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute. @@ -1458,7 +1436,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - switchWindow: (handleOrName: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + switchWindow(handleOrName: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Convenience method that adds the specified hash (i.e. url fragment) to the current value of the launch_url as set in nightwatch.json. @@ -1475,7 +1453,7 @@ interface NightWatchClient { * @param callback: * @returns {} */ - urlHash: (hash: string) => NightWatchBrowser; + urlHash(hash: string): NightWatchBrowser; /** * Opposite of waitForElementPresent. Waits a given time in milliseconds for an element to be not present (i.e. removed) in the page before performing any other commands @@ -1498,7 +1476,7 @@ interface NightWatchClient { * (e.g. Element %s was not in the page for %d ms). * @returns {} */ - waitForElementNotPresent: (selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string) => NightWatchBrowser; + waitForElementNotPresent(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): NightWatchBrowser; /** * Opposite of waitForElementVisible. Waits a given time in milliseconds for an element to be not visible (i.e. hidden but existing) in the page before performing @@ -1521,8 +1499,7 @@ interface NightWatchClient { * (e.g. Element %s was not in the page for %d ms). * @returns {} */ - waitForElementNotVisible: (selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string) => NightWatchBrowser; - + waitForElementNotVisible(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): NightWatchBrowser; /** * Waits a given time in milliseconds for an element to be present in the page before performing any other commands or assertions. @@ -1556,7 +1533,7 @@ interface NightWatchClient { * (e.g. Element %s was not in the page for %d ms). * @returns {} */ - waitForElementPresent: (selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string) => NightWatchBrowser; + waitForElementPresent(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): NightWatchBrowser; /** * Waits a given time in milliseconds for an element to be visible in the page before performing any other commands or assertions. @@ -1588,21 +1565,21 @@ interface NightWatchClient { * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time (e.g. Element %s was not in the page for %d ms). * @returns {} */ - waitForElementVisible: (selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string) => NightWatchBrowser; + waitForElementVisible(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): NightWatchBrowser; /** * Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - acceptAlert: (callback?: () => void) => NightWatchBrowser; + acceptAlert(callback?: () => void): NightWatchBrowser; /** * Navigate backwards in the browser history, if possible. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - back: (callback?: () => void) => NightWatchBrowser; + back(callback?: () => void): NightWatchBrowser; /** * Get a list of the available contexts. @@ -1610,7 +1587,7 @@ interface NightWatchClient { * @param callback: Callback function to be called when the command finishes. * @returns {an array of strings representing available contexts, e.g 'WEBVIEW', or 'NATIVE'} */ - contexts: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + contexts(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Retrieve or delete all cookies visible to the current page or set a cookie. @@ -1618,14 +1595,14 @@ interface NightWatchClient { * @param callbackorCookie * @returns {a string representing the current context or `null`, representing "no context"} */ - cookie: (method: string, callbackorCookie?: () => void) => NightWatchBrowser; + cookie(method: string, callbackorCookie?: () => void): NightWatchBrowser; /** * Get current context. * @param callback: Callback function to be called when the command finishes. * @returns {} */ - currentContext: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + currentContext(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Dismisses the currently displayed alert dialog. For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button. @@ -1633,14 +1610,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - dismissAlert: (callback?: () => void) => NightWatchBrowser; + dismissAlert(callback?: () => void): NightWatchBrowser; /** * Double-clicks at the current mouse coordinates (set by moveto). * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - doubleClick: (callback?: () => void) => NightWatchBrowser; + doubleClick(callback?: () => void): NightWatchBrowser; /** * Search for an element on the page, starting from the document root. The located element will be returned as a WebElement JSON object. @@ -1660,14 +1637,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - element: (using: string, value: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + element(using: string, value: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Get the element on the page that currently has focus. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementActive: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementActive(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Get the value of an element's attribute. @@ -1676,7 +1653,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdAttribute: (id: string, attributeName: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdAttribute(id: string, attributeName: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Clear a TEXTAREA or text INPUT element's value. @@ -1684,7 +1661,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdClear: (id: string, callback?: () => void) => NightWatchBrowser; + elementIdClear(id: string, callback?: () => void): NightWatchBrowser; /** * Click on an element. @@ -1692,7 +1669,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdClick: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdClick(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Query the value of an element's computed CSS property. @@ -1702,7 +1679,7 @@ interface NightWatchClient { * @param callback * @returns {} */ - elementIdCssProperty: (id: string, cssPropertyName: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdCssProperty(id: string, cssPropertyName: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine if an element is currently displayed. @@ -1710,7 +1687,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdDisplayed: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdDisplayed(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Search for an element on the page, starting from the identified element. The located element will be returned as a WebElement JSON object. @@ -1720,7 +1697,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdElement: (id: string, using: string, value: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdElement(id: string, using: string, value: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Search for multiple elements on the page, starting from the identified element. The located element will be returned as a WebElement JSON objects. @@ -1730,7 +1707,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdElements: (id: string, using: string, value: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdElements(id: string, using: string, value: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine if an element is currently enabled. @@ -1738,7 +1715,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdEnabled: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdEnabled(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Test if two element IDs refer to the same DOM element. @@ -1747,7 +1724,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdEquals: (id: string, otherId: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdEquals(id: string, otherId: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. @@ -1756,7 +1733,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The X and Y coordinates for the element on the page.} */ - elementIdLocation: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdLocation(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine an element's location on the screen once it has been scrolled into view. @@ -1764,7 +1741,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdLocationInView: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdLocationInView(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Query for an element's tag name. @@ -1772,7 +1749,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdName: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdName(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected. @@ -1780,7 +1757,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdSelected: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdSelected(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties. @@ -1788,7 +1765,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdSize: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdSize(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Returns the visible text for the element. @@ -1796,7 +1773,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdText: (id: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdText(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Send a sequence of key strokes to an element or returns the current value of the element. @@ -1805,7 +1782,7 @@ interface NightWatchClient { * @param callback * @returns {} */ - elementIdValue: (id: string, value?: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + elementIdValue(id: string, value?: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Search for multiple elements on the page, starting from the document root. The located elements will be returned as a WebElement JSON objects. @@ -1815,7 +1792,7 @@ interface NightWatchClient { * @param callback: Callback function to be invoked with the result when the command finishes. * @returns {} */ - elements: (using: string, value: string, callback: (result: CallbackResult) => void) => NightWatchBrowser; + elements(using: string, value: string, callback: (result: CallbackResult) => void): NightWatchBrowser; /** * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous and @@ -1839,7 +1816,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The script result.} */ - execute: (body: ((...data: any[]) => void) | string, args?: any[], callback?: (result: CallbackResult) => void) => NightWatchBrowser; + execute(body: ((...data: any[]) => void) | string, args?: any[], callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be asynchronous @@ -1863,14 +1840,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The script result.} */ - executeAsync: (script: ((...data: any[]) => void) | string, args?: any[], callback?: (result: CallbackResult) => void) => NightWatchBrowser; + executeAsync(script: ((...data: any[]) => void) | string, args?: any[], callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Navigate forwards in the browser history, if possible. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - forward: (callback?: () => void) => NightWatchBrowser; + forward(callback?: () => void): NightWatchBrowser; /** * Change focus to another frame on the page. If the frame id is missing or null, the server should switch to the page's default content. @@ -1878,28 +1855,28 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - frame: (frameId?: string, callback?: () => void) => NightWatchBrowser; + frame(frameId?: string, callback?: () => void): NightWatchBrowser; /** * Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - frameParent: (callback?: () => void) => NightWatchBrowser; + frameParent(callback?: () => void): NightWatchBrowser; /** * Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. * @param callback: Optional callback function to be called when the command finishes. * @returns {The text of the currently displayed alert.} */ - getAlertText: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getAlertText(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Get the current browser orientation. * @param callback: Callback function to be called when the command finishes. * @returns {The current browser orientation: LANDSCAPE|PORTRAIT} */ - getOrientation: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + getOrientation(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Send a sequence of key strokes to the active element. The sequence is defined in the same format as the sendKeys command. @@ -1909,7 +1886,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - keys: (keysToSend: string[], callback?: () => void) => NightWatchBrowser; + keys(keysToSend: string[], callback?: () => void): NightWatchBrowser; /** * Click at the current mouse coordinates (set by moveto). @@ -1918,7 +1895,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - mouseButtonClick: (button: string, callback?: () => void) => NightWatchBrowser; + mouseButtonClick(button: string, callback?: () => void): NightWatchBrowser; /** * Click and hold the left mouse button (at the coordinates set by the last moveto command). Note that the next mouse-related command that should follow is mouseButtonUp . Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour. @@ -1927,7 +1904,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - mouseButtonDown: (button: string, callback?: () => void) => NightWatchBrowser; + mouseButtonDown(button: string, callback?: () => void): NightWatchBrowser; /** * Releases the mouse button previously held (where the mouse is currently at). Must be called once for every mouseButtonDown command issued. @@ -1936,7 +1913,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - mouseButtonUp: (button: string, callback?: () => void) => NightWatchBrowser; + mouseButtonUp(button: string, callback?: () => void): NightWatchBrowser; /** * Move the mouse by an offset of the specificed element. If no element is specified, the move is relative to the current mouse cursor. If an element is provided but no offset, the mouse will be moved to the center of the element. @@ -1947,14 +1924,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - moveTo: (element: string, xofset: number, yoffset: number, callback?: () => void) => NightWatchBrowser; + moveTo(element: string, xofset: number, yoffset: number, callback?: () => void): NightWatchBrowser; /** * Refresh the current page. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - refresh: (callback?: () => void) => NightWatchBrowser; + refresh(callback?: () => void): NightWatchBrowser; /** * Take a screenshot of the current page. @@ -1962,7 +1939,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - screenshot: (log_screenshot_data: boolean, callback?: () => void) => NightWatchBrowser; + screenshot(log_screenshot_data: boolean, callback?: () => void): NightWatchBrowser; /** * Get info about, delete or create a new session. Defaults to the current session. @@ -1988,7 +1965,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - session: (action?: string, sessionId?: string, callback?: (result: CallbackResult) => void) => NightWatchBrowser; + session(action?: string, sessionId?: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Gets the text of the log type specified @@ -1996,14 +1973,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {Array of the text entries of the log.} */ - sessionLog: (typeString: string, callback?: (log: LogEntry[]) => void) => NightWatchBrowser; + sessionLog(typeString: string, callback?: (log: LogEntry[]) => void): NightWatchBrowser; /** * Gets an array of strings for which log types are available. * @param callback: Optional callback function to be called when the command finishes. * @returns {Available log types} */ - sessionLogTypes: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + sessionLogTypes(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Returns a list of the currently active sessions. @@ -2019,7 +1996,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - sessions: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + sessions(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Sends keystrokes to a JavaScript prompt() dialog. @@ -2027,7 +2004,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setAlertText: (value: string, callback?: () => void) => NightWatchBrowser; + setAlertText(value: string, callback?: () => void): NightWatchBrowser; /** * Sets the context @@ -2035,7 +2012,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setContext: (context: string, callback?: () => void) => NightWatchBrowser; + setContext(context: string, callback?: () => void): NightWatchBrowser; /** * Sets the browser orientation. @@ -2043,21 +2020,21 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setOrientation: (orientation: string, callback?: () => void) => NightWatchBrowser; + setOrientation(orientation: string, callback?: () => void): NightWatchBrowser; /** * Get the current page source. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - source: (callback?: () => void) => NightWatchBrowser; + source(callback?: () => void): NightWatchBrowser; /** * Query the server's current status. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - status: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + status(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. @@ -2065,7 +2042,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - submit: (id: string, callback?: () => void) => NightWatchBrowser; + submit(id: string, callback?: () => void): NightWatchBrowser; /** * Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client. @@ -2074,7 +2051,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - timeouts: (typeOfOperation: string, ms: number, callback?: () => void) => NightWatchBrowser; + timeouts(typeOfOperation: string, ms: number, callback?: () => void): NightWatchBrowser; /** * Set the amount of time, in milliseconds, that asynchronous scripts executed by /session/:sessionId/execute_async are permitted to run before they are aborted and a |Timeout| error is returned to the client. @@ -2082,7 +2059,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - timeoutsAsyncScript: (ms: number, callback?: () => void) => NightWatchBrowser; + timeoutsAsyncScript(ms: number, callback?: () => void): NightWatchBrowser; /** * Set the amount of time the driver should wait when searching for elements. If this command is never sent, the driver will default to an implicit wait of 0ms. @@ -2090,7 +2067,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - timeoutsImplicitWait: (ms: number, callback?: () => void) => NightWatchBrowser; + timeoutsImplicitWait(ms: number, callback?: () => void): NightWatchBrowser; /** * Get the current page title. @@ -2099,7 +2076,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - title: (expected: string, msg?: string, callback?: () => void) => NightWatchBrowser; + title(expected: string, msg?: string, callback?: () => void): NightWatchBrowser; /** * Retrieve the URL of the current page or navigate to a new URL. @@ -2128,7 +2105,7 @@ interface NightWatchClient { * @param callback Optional callback function to be called when the command finishes. * @returns {} */ - url: (url?: string | ((result: CallbackResult) => void), callback?: (result: CallbackResult) => void) => NightWatchBrowser; + url(url?: string | ((result: CallbackResult) => void), callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Change focus to another window or close the current window. @@ -2137,28 +2114,28 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - window: (method: string, handleOrName: string, callback?: () => void) => NightWatchBrowser; + window(method: string, handleOrName: string, callback?: () => void): NightWatchBrowser; /** * Retrieve the current window handle. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - windowHandle: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + windowHandle(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Retrieve the list of all window handles available to the session. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - windowHandles: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + windowHandles(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Retrieve the list of all window handles available to the session. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - window_handles: (callback?: (result: CallbackResult) => void) => NightWatchBrowser; + window_handles(callback?: (result: CallbackResult) => void): NightWatchBrowser; /** * Retrieve the current window handle. @@ -2166,7 +2143,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - windowMaximize: (handleOrName?: string, callback?: () => void) => NightWatchBrowser; + windowMaximize(handleOrName?: string, callback?: () => void): NightWatchBrowser; /** * Change or get the position of the specified window. If the second argument is a function it will be used as a callback and the call will perform a get request to retrieve the existing window position. @@ -2176,7 +2153,7 @@ interface NightWatchClient { * @param: callback: * @returns {} */ - windowPosition: (windowHandle: string, offsetX: number, offsetY: number, callback: (result: CallbackResult) => void) => NightWatchBrowser; + windowPosition(windowHandle: string, offsetX: number, offsetY: number, callback: (result: CallbackResult) => void): NightWatchBrowser; /** * Change or get the size of the specified window. If the second argument is a function it will be used as a callback and the call will perform a get request to retrieve the existing window size. @@ -2186,7 +2163,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - windowSize: (windowHandle: string, width: number, height: number, callback?: () => void) => NightWatchBrowser; + windowSize(windowHandle: string, width: number, height: number, callback?: () => void): NightWatchBrowser; /** * To switch to xpath selectors instead of css as the locate strategy. @@ -2202,7 +2179,7 @@ interface NightWatchClient { * ``` * @returns {} */ - useXpath: () => NightWatchBrowser; + useXpath(): NightWatchBrowser; /** * To switch to css selectors instead of xpath as the locate strategy @@ -2217,7 +2194,7 @@ interface NightWatchClient { * ``` * @returns {} */ - useCss: () => NightWatchBrowser; + useCss(): NightWatchBrowser; Keys: Keys; @@ -2228,10 +2205,12 @@ interface NightWatchClient { launch_url: string; } -interface NightWatchBrowser extends NightWatchClient, NightWatchCustomCommands, NightWatchCustomPageObjects { } +interface NightWatchBrowser extends NightWatchClient, NightWatchCustomPageObjects { } + +type NightWatchTest = (arg1: NightWatchBrowser) => void; -interface NightWatchTest { - (arg1: NightWatchBrowser): void; +interface NightWatchTests { + [key: string]: NightWatchTest; } -interface NightWatchTests {[key: string]: NightWatchTest} +/* tslint:enable:max-line-length */ diff --git a/types/nightwatch/nightwatch-tests.ts b/types/nightwatch/nightwatch-tests.ts index 319091b..1e16c29 100644 --- a/types/nightwatch/nightwatch-tests.ts +++ b/types/nightwatch/nightwatch-tests.ts @@ -1,5 +1,5 @@ -export = { - 'Demo test Google': function (browser) { +const test: NightWatchTests = { + 'Demo test Google': (browser) => { browser .url('http://www.google.com') .waitForElementVisible('body', 1000) @@ -10,4 +10,6 @@ export = { .assert.containsText('#main', 'Night Watch') .end(); } -} as NightWatchTests; +}; + +export = test; diff --git a/types/nightwatch/tsconfig.json b/types/nightwatch/tsconfig.json index b46be78..1130615 100644 --- a/types/nightwatch/tsconfig.json +++ b/types/nightwatch/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es6", + "dom" ], "noImplicitAny": true, "noImplicitThis": true, From b767145e15feec69bb0bf1f98a6c48d55aa81fe7 Mon Sep 17 00:00:00 2001 From: Connor Schlesiger Date: Thu, 24 Aug 2017 22:45:14 -0400 Subject: [PATCH 3/6] Add option definition, create generic settings to fix options screenshot conflict, fix test_settings definition --- types/nightwatch/index.d.ts | 55 +++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/types/nightwatch/index.d.ts b/types/nightwatch/index.d.ts index 5316aa4..82b8509 100644 --- a/types/nightwatch/index.d.ts +++ b/types/nightwatch/index.d.ts @@ -238,19 +238,19 @@ interface SeleniumOptions { * If you wish to use an existing Firefox profile you can specify its name here. * Complete list of Firefox Driver arguments available https://code.google.com/p/selenium/wiki/FirefoxDriver. * - * webdriver.chrome.driver: Nightwatch can run the tests using Chrome browser also. To enable this you have to download the ChromeDriver binary + * webdriver.chrome.driver: NightWatch can run the tests using Chrome browser also. To enable this you have to download the ChromeDriver binary * (http://chromedriver.storage.googleapis.com/index.html) and specify it's location here. Also don't forget to specify chrome as the browser name in the * desiredCapabilities object. * More information can be found on the ChromeDriver website (https://sites.google.com/a/chromium.org/chromedriver/). * - * webdriver.ie.driver: Nightwatch has support for Internet Explorer also. To enable this you have to download the IE Driver binary + * webdriver.ie.driver: NightWatch has support for Internet Explorer also. To enable this you have to download the IE Driver binary * (https://code.google.com/p/selenium/wiki/InternetExplorerDriver) and specify it's location here. Also don't forget to specify "internet explorer" as the browser * name in the desiredCapabilities object. */ cli_args: any; } -interface NightWatchTestSettings { +interface NightWatchTestSettingGeneric { /** * A url which can be used later in the tests as the main url to load. Can be useful if your tests will run on different environments, each one with a different url. */ @@ -281,19 +281,6 @@ interface NightWatchTestSettings { */ disable_colors: boolean; - /** - * Selenium generates screenshots when command errors occur. With on_failure set to true, also generates screenshots for failing or erroring tests. These are saved on the disk. - * Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false. - * Example: - * "screenshots" : { - * "enabled" : true, - * "on_failure" : true, - * "on_error" : false, - * "path" : "" - * } - */ - screenshots: ScreenshotOptions; - /** * In case the selenium server requires credentials this username will be used to compute the Authorization header. * The value can be also an environment variable, in which case it will look like this: "username" : "${SAUCE_USERNAME}" @@ -365,6 +352,26 @@ interface NightWatchTestSettings { skip_testcases_on_fail: boolean; } +interface NightWatchTestSettingScreenshots extends NightWatchTestSettingGeneric { + /** + * Selenium generates screenshots when command errors occur. With on_failure set to true, also generates screenshots for failing or erroring tests. These are saved on the disk. + * Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false. + * Example: + * "screenshots" : { + * "enabled" : true, + * "on_failure" : true, + * "on_error" : false, + * "path" : "" + * } + */ + screenshots: ScreenshotOptions; +} + +interface NightWatchTestOptions extends NightWatchTestSettingGeneric { + screenshots: boolean; + screenshotsPath: string; +} + interface TestSuite { name: string; "module": string; @@ -394,6 +401,10 @@ interface LanguageChains { of: Expect; } +interface NightWatchTestSettings { + [key: string]: NightWatchTestSettingScreenshots; +} + interface Expect extends LanguageChains, NightWatchBrowser { /** * Returns the DOM Element @@ -1105,7 +1116,7 @@ interface NightWatchClient { * this.demoTest = function (browser) { * browser.getTitle(function(title) { * this.assert.equal(typeof title, 'string'); - * this.assert.equal(title, 'Nightwatch.js'); + * this.assert.equal(title, 'nightwatch.js'); * }); * }; * ``` @@ -1328,12 +1339,12 @@ interface NightWatchClient { saveScreenshot(fileName: string, callback?: () => void): NightWatchBrowser; /** - * SessionId of the session used by the Nightwatch api. + * SessionId of the session used by the NightWatch api. */ sessionId: string; /** - * Override the sessionId used by Nightwatch client with another session id. + * Override the sessionId used by NightWatch client with another session id. * @param sessionId: The session Id to set. * @returns {} */ @@ -1366,7 +1377,7 @@ interface NightWatchClient { /** * Sends some text to an element. Can be used to set the value of a form element or to send a sequence of key strokes to an element. Any UTF-8 character may be specified. * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec (http://www.w3.org/TR/webdriver/#character-types), - * is loaded onto the main Nightwatch instance as client.Keys. + * is loaded onto the main NightWatch instance as client.Keys. * * Usage: * ``` @@ -1880,7 +1891,7 @@ interface NightWatchClient { /** * Send a sequence of key strokes to the active element. The sequence is defined in the same format as the sendKeys command. - * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec, is loaded onto the main Nightwatch instance as client.Keys. + * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec, is loaded onto the main NightWatch instance as client.Keys. * Rather than the setValue, the modifiers are not released at the end of the call. The state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed. * @param keysToSend: The keys sequence to be sent. * @param callback: Optional callback function to be called when the command finishes. @@ -2196,6 +2207,8 @@ interface NightWatchClient { */ useCss(): NightWatchBrowser; + options: NightWatchTestOptions; + Keys: Keys; currentTest: TestSuite; From 06fbd0d789c59c91ea5b1bab4ad48eb1228f60fd Mon Sep 17 00:00:00 2001 From: Connor Schlesiger Date: Sun, 27 Aug 2017 19:52:32 -0400 Subject: [PATCH 4/6] Add Nightwatch to all exports, fix 'Nightwatch' punctuation, Nightwatch browser returns refer to 'this' for easier extendability --- types/nightwatch/index.d.ts | 450 +++++++++++++++------------ types/nightwatch/nightwatch-tests.ts | 2 +- 2 files changed, 244 insertions(+), 208 deletions(-) diff --git a/types/nightwatch/index.d.ts b/types/nightwatch/index.d.ts index 82b8509..f71beca 100644 --- a/types/nightwatch/index.d.ts +++ b/types/nightwatch/index.d.ts @@ -6,11 +6,11 @@ /* tslint:disable:max-line-length */ -interface NightWatchCustomPageObjects { +interface NightwatchCustomPageObjects { page: {}; } -interface DesiredCapabilities { +interface NightwatchDesiredCapabilities { /** * The name of the browser being used; should be one of {android|chrome|firefox|htmlunit|internet explorer|iPhone|iPad|opera|safari}. */ @@ -111,26 +111,26 @@ interface DesiredCapabilities { }; } -interface ScreenshotOptions { +interface NightwatchScreenshotOptions { enabled?: boolean; on_failure?: boolean; on_error?: boolean; path?: string; } -interface NightWatchTestRunner { +interface NightwatchTestRunner { "type"?: string; options?: { ui?: string; }; } -interface NightWatchTestWorker { +interface NightwatchTestWorker { enabled: boolean; workers: string; } -interface NightWatchOptions { +interface NightwatchOptions { /** * An array of folders (excluding subfolders) where the tests are located. */ @@ -165,12 +165,12 @@ interface NightWatchOptions { /** * An object containing Selenium Server related configuration options. See below for details. */ - selenium?: SeleniumOptions; + selenium?: NightwatchSeleniumOptions; /** * This object contains all the test related options. See below for details. */ - test_settings: NightWatchTestSettings; + test_settings: NightwatchTestSettings; /** * Whether or not to buffer the output in case of parallel running. See below for details. @@ -191,16 +191,16 @@ interface NightWatchOptions { * Whether or not to run individual test files in parallel. If set to true, runs the tests in parallel and determines the number of workers automatically. * If set to an object, can specify specify the number of workers as "auto" or a number. Example: "test_workers" : {"enabled" : true, "workers" : "auto"} */ - test_workers?: boolean | NightWatchTestWorker; + test_workers?: boolean | NightwatchTestWorker; /** * Specifies which test runner to use when running the tests. Values can be either default (built in nightwatch runner) or mocha. * Example: "test_runner" : {"type" : "mocha", "options" : {"ui" : "tdd"}} */ - test_runner?: string | NightWatchTestRunner; + test_runner?: string | NightwatchTestRunner; } -interface SeleniumOptions { +interface NightwatchSeleniumOptions { /** * Whether or not to manage the selenium process automatically. */ @@ -238,19 +238,19 @@ interface SeleniumOptions { * If you wish to use an existing Firefox profile you can specify its name here. * Complete list of Firefox Driver arguments available https://code.google.com/p/selenium/wiki/FirefoxDriver. * - * webdriver.chrome.driver: NightWatch can run the tests using Chrome browser also. To enable this you have to download the ChromeDriver binary + * webdriver.chrome.driver: Nightwatch can run the tests using Chrome browser also. To enable this you have to download the ChromeDriver binary * (http://chromedriver.storage.googleapis.com/index.html) and specify it's location here. Also don't forget to specify chrome as the browser name in the * desiredCapabilities object. * More information can be found on the ChromeDriver website (https://sites.google.com/a/chromium.org/chromedriver/). * - * webdriver.ie.driver: NightWatch has support for Internet Explorer also. To enable this you have to download the IE Driver binary + * webdriver.ie.driver: Nightwatch has support for Internet Explorer also. To enable this you have to download the IE Driver binary * (https://code.google.com/p/selenium/wiki/InternetExplorerDriver) and specify it's location here. Also don't forget to specify "internet explorer" as the browser * name in the desiredCapabilities object. */ cli_args: any; } -interface NightWatchTestSettingGeneric { +interface NightwatchTestSettingGeneric { /** * A url which can be used later in the tests as the main url to load. Can be useful if your tests will run on different environments, each one with a different url. */ @@ -307,7 +307,7 @@ interface NightWatchTestSettingGeneric { * } * You can view the complete list of capabilities https://code.google.com/p/selenium/wiki/DesiredCapabilities. */ - desiredCapabilities: DesiredCapabilities; + desiredCapabilities: NightwatchDesiredCapabilities; /** * An object which will be made available within the test and can be overwritten per environment. Example:"globals" : { "myGlobal" : "some_global" } @@ -352,7 +352,7 @@ interface NightWatchTestSettingGeneric { skip_testcases_on_fail: boolean; } -interface NightWatchTestSettingScreenshots extends NightWatchTestSettingGeneric { +interface NightwatchTestSettingScreenshots extends NightwatchTestSettingGeneric { /** * Selenium generates screenshots when command errors occur. With on_failure set to true, also generates screenshots for failing or erroring tests. These are saved on the disk. * Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false. @@ -364,29 +364,29 @@ interface NightWatchTestSettingScreenshots extends NightWatchTestSettingGeneric * "path" : "" * } */ - screenshots: ScreenshotOptions; + screenshots: NightwatchScreenshotOptions; } -interface NightWatchTestOptions extends NightWatchTestSettingGeneric { +interface NightwatchTestOptions extends NightwatchTestSettingGeneric { screenshots: boolean; screenshotsPath: string; } -interface TestSuite { +interface NightwatchTestSuite { name: string; "module": string; group: string; results: any; } -interface AssertionError { +interface NightwatchAssertionError { name: string; message: string; showDiff: boolean; stack: string; } -interface LanguageChains { +interface NightwatchLanguageChains { to: Expect; be: Expect; been: Expect; @@ -401,17 +401,17 @@ interface LanguageChains { of: Expect; } -interface NightWatchTestSettings { - [key: string]: NightWatchTestSettingScreenshots; +interface NightwatchTestSettings { + [key: string]: NightwatchTestSettingScreenshots; } -interface Expect extends LanguageChains, NightWatchBrowser { +interface Expect extends NightwatchLanguageChains, NightwatchBrowser { /** * Returns the DOM Element * @param property: Css / Id property of the DOM element * @returns {} */ - element(property: string): NightWatchBrowser; + element(property: string): this; /** * These methods will perform assertions on the specified target on the current element. @@ -420,14 +420,14 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param message * @returns {} */ - equal(value: string): NightWatchBrowser; - contain(value: string): NightWatchBrowser; - match(value: string): NightWatchBrowser; + equal(value: string): this; + contain(value: string): this; + match(value: string): this; /** * Negates any of assertions following in the chain. */ - not: NightWatchBrowser; + not: this; /** * These methods perform the same thing which is essentially retrying the assertion for the given amount of time (in milliseconds). @@ -437,8 +437,8 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param value: Number of milliseconds to wait to perform and operation of check * @returns {} */ - before(value: number): NightWatchBrowser; - after(value: number): NightWatchBrowser; + before(value: number): this; + after(value: number): this; /** * Checks if the type (i.e. tag name) of a specified element is of an expected value. @@ -446,8 +446,8 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - a(value: string, message?: string): NightWatchBrowser; - an(value: string, message?: string): NightWatchBrowser; + a(value: string, message?: string): this; + an(value: string, message?: string): this; /** * Checks if a given attribute of an element exists and optionally if it has the expected value. @@ -455,7 +455,7 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - attribute(name: string, message?: string): NightWatchBrowser; + attribute(name: string, message?: string): this; /** * Checks a given css property of an element exists and optionally if it has the expected value. @@ -463,40 +463,40 @@ interface Expect extends LanguageChains, NightWatchBrowser { * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - css(property: string, message?: string): NightWatchBrowser; + css(property: string, message?: string): this; /** * Property that checks if an element is currently enabled. */ - enabled: NightWatchBrowser; + enabled: this; /** * Property that checks if an element is present in the DOM. */ - present: NightWatchBrowser; + present: this; /** * Property that checks if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected. */ - selected: NightWatchBrowser; + selected: this; /** * Property that retrieves the text contained by an element. Can be chained to check if contains/equals/matches the specified text or regex. */ - text: NightWatchBrowser; + text: this; /** * Property that retrieves the value (i.e. the value attributed) of an element. Can be chained to check if contains/equals/matches the specified text or regex. */ - value: NightWatchBrowser; + value: this; /** * Property that asserts the visibility of a specified element. */ - visible: NightWatchBrowser; + visible: this; } -interface Assertion extends NightWatchBrowser { +interface NightwatchAssertion extends NightwatchBrowser { /** * Checks if the given attribute of an element contains the expected value. * @param selector: The selector (CSS / Xpath) used to locate the element. @@ -505,7 +505,7 @@ interface Assertion extends NightWatchBrowser { * @param message: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - attributeContains(selector: string, attribute: string, expected: string, message?: string): NightWatchBrowser; + attributeContains(selector: string, attribute: string, expected: string, message?: string): this; /** * Checks if the given attribute of an element has the expected value. @@ -515,7 +515,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - attributeEquals(cssSelector: string, attribute: string, expected: string, msg?: string): NightWatchBrowser; + attributeEquals(cssSelector: string, attribute: string, expected: string, msg?: string): this; /** * Checks if the given element contains the specified text. @@ -524,7 +524,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - containsText(cssSelector: string, expectedText: string, msg?: string): NightWatchBrowser; + containsText(cssSelector: string, expectedText: string, msg?: string): this; /** * Checks if the given element has the specified CSS class. @@ -533,7 +533,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - cssClassPresent(cssSelector: string, className: string, msg?: string): NightWatchBrowser; + cssClassPresent(cssSelector: string, className: string, msg?: string): this; /** * Checks if the given element does not have the specified CSS class. @@ -542,7 +542,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - cssClassNotPresent(cssSelector: string, className: string, msg?: string): NightWatchBrowser; + cssClassNotPresent(cssSelector: string, className: string, msg?: string): this; /** * Checks if the specified css property of a given element has the expected value. @@ -552,13 +552,13 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - cssProperty(cssSelector: string, cssProperty: string, expected: string | number, msg?: string): NightWatchBrowser; + cssProperty(cssSelector: string, cssProperty: string, expected: string | number, msg?: string): this; - deepEqual(value: any, expected: any, message?: string): NightWatchBrowser; + deepEqual(value: any, expected: any, message?: string): this; - deepStrictEqual(value: any, expected: any, message?: string): NightWatchBrowser; + deepStrictEqual(value: any, expected: any, message?: string): this; - doesNotThrow(value: any, expected: any, message?: string): NightWatchBrowser; + doesNotThrow(value: any, expected: any, message?: string): this; /** * Checks if the given element exists in the DOM. @@ -566,7 +566,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - elementPresent(cssSelector: string, msg?: string): NightWatchBrowser; + elementPresent(cssSelector: string, msg?: string): this; /** * Checks if the given element does not exist in the DOM. @@ -574,11 +574,11 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - elementNotPresent(cssSelector: string, msg?: string): NightWatchBrowser; + elementNotPresent(cssSelector: string, msg?: string): this; - equal(value: any, expected: any, message?: string): NightWatchBrowser; + equal(value: any, expected: any, message?: string): this; - fail(actual?: any, expected?: any, message?: string, operator?: string): NightWatchBrowser; + fail(actual?: any, expected?: any, message?: string, operator?: string): this; /** * Checks if the given element is not visible on the page. @@ -586,23 +586,23 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - hidden(cssSelector: string, msg?: string): NightWatchBrowser; + hidden(cssSelector: string, msg?: string): this; - ifError(value: any, message?: string): NightWatchBrowser; + ifError(value: any, message?: string): this; - notDeepEqual(actual: any, expected: any, message?: string): NightWatchBrowser; + notDeepEqual(actual: any, expected: any, message?: string): this; - notDeepStrictEqual(value: any, message?: string): NightWatchBrowser; + notDeepStrictEqual(value: any, message?: string): this; - notEqual(actual: any, expected: any, message?: string): NightWatchBrowser; + notEqual(actual: any, expected: any, message?: string): this; - notStrictEqual(value: any, expected: any, message?: string): NightWatchBrowser; + notStrictEqual(value: any, expected: any, message?: string): this; - ok(actual: boolean, message?: string): NightWatchBrowser; + ok(actual: boolean, message?: string): this; - strictEqual(value: any, expected: any, message?: string): NightWatchBrowser; + strictEqual(value: any, expected: any, message?: string): this; - throws(fn: () => void, msg?: string): NightWatchBrowser; + throws(fn: () => void, msg?: string): this; /** * Checks if the current URL contains the given value. @@ -610,7 +610,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - urlContains(expectedText: string, msg?: string): NightWatchBrowser; + urlContains(expectedText: string, msg?: string): this; /** * Checks if the current url equals the given value. @@ -618,7 +618,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - urlEquals(expected: string, msg?: string): NightWatchBrowser; + urlEquals(expected: string, msg?: string): this; /** * Checks if the given form element's value equals the expected value. @@ -627,7 +627,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - value(cssSelector: string, expectedText: string, msg?: string): NightWatchBrowser; + value(cssSelector: string, expectedText: string, msg?: string): this; /** * Checks if the given form element's value contains the expected value. @@ -636,7 +636,7 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - valueContains(cssSelector: string, expectedText: string, msg?: string): NightWatchBrowser; + valueContains(cssSelector: string, expectedText: string, msg?: string): this; /** * Checks if the given element is visible on the page. @@ -644,21 +644,21 @@ interface Assertion extends NightWatchBrowser { * @param msg: Optional log message to display in the output. If missing, one is displayed by default. * @returns {} */ - visible(cssSelector: string, msg?: string): NightWatchBrowser; + visible(cssSelector: string, msg?: string): this; - AssertionError: AssertionError; + NightwatchAssertionError: NightwatchAssertionError; } -interface TypedCallbackResult { +interface NightwatchTypedCallbackResult { status: number; value: T; } // tslint:disable-next-line:no-empty-interface -interface CallbackResult extends TypedCallbackResult { +interface NightwatchCallbackResult extends NightwatchTypedCallbackResult { } -interface LogEntry { +interface NightwatchLogEntry { /** * The log entry message. */ @@ -675,7 +675,7 @@ interface LogEntry { level: string; } -interface Keys { +interface NightwatchKeys { /** Releases all held modifier keys. */ "NULL": string; /** OS-specific keystroke sequence that performs a cancel action. */ @@ -798,12 +798,12 @@ interface Keys { "COMMAND": string; } -interface NightWatchClient { - assert: Assertion; +interface NightwatchClient { + assert: NightwatchAssertion; expect: Expect; - verify: Assertion; + verify: NightwatchAssertion; /** * Clear a textarea or a text input element's value. Uses elementIdValue protocol command. @@ -818,7 +818,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - clearValue(selector: string, callback?: () => void): NightWatchBrowser; + clearValue(selector: string, callback?: () => void): this; /** * Simulates a click event on the given DOM element. Uses elementIdClick protocol command. @@ -833,7 +833,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - click(selector: string, callback?: () => void): NightWatchBrowser; + click(selector: string, callback?: () => void): this; /** * Close the current window. This can be useful when you're working with multiple windows open (e.g. an OAuth login). Uses window protocol command. @@ -847,7 +847,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - closeWindow(callback?: () => void): NightWatchBrowser; + closeWindow(callback?: () => void): this; /** * Delete the cookie with the given name. This command is a no-op if there is no such cookie visible to the current page. @@ -864,7 +864,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - deleteCookie(The: string, callback?: () => void): NightWatchBrowser; + deleteCookie(The: string, callback?: () => void): this; /** * Delete all cookies visible to the current page. @@ -880,7 +880,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - deleteCookies(callback?: () => void): NightWatchBrowser; + deleteCookies(callback?: () => void): this; /** * Ends the session. Uses session protocol command. @@ -894,7 +894,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - end(callback?: () => void): NightWatchBrowser; + end(callback?: () => void): this; /** * Retrieve the value of an attribute for a given DOM element. Uses elementIdAttribute protocol command. @@ -914,7 +914,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The value of the attribute} */ - getAttribute(selector: string, attribute: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + getAttribute(selector: string, attribute: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Retrieve a single cookie visible to the current page. The cookie is returned as a cookie JSON object, as defined here. @@ -933,7 +933,7 @@ interface NightWatchClient { * @param callback: The callback function which will receive the response as an argument. * @returns {The cookie object as a selenium cookie JSON object or null if the cookie wasn't found.} */ - getCookie(name: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + getCookie(name: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Retrieve all cookies visible to the current page. The cookies are returned as an array of cookie JSON object, @@ -951,7 +951,7 @@ interface NightWatchClient { * @param callback: The callback function which will receive the response as an argument. * @returns {A list of cookies} */ - getCookies(callback?: (result: CallbackResult) => void): NightWatchBrowser; + getCookies(callback?: (result: NightwatchCallbackResult) => void): this; /** * Retrieve the value of a css property for a given DOM element. Uses elementIdCssProperty protocol command. @@ -971,7 +971,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The value of the css property} */ - getCssProperty(selector: string, cssProperty: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + getCssProperty(selector: string, cssProperty: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine an element's size in pixels. Uses elementIdSize protocol command. @@ -991,7 +991,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The width and height of the element in pixels} */ - getElementSize(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + getElementSize(selector: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. @@ -1012,7 +1012,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The X and Y coordinates for the element on the page} */ - getLocation(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + getLocation(selector: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine an element's location on the screen once it has been scrolled into view. Uses elementIdLocationInView protocol command. @@ -1032,7 +1032,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The X and Y coordinates for the element on the page.} */ - getLocationInView(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + getLocationInView(selector: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Gets a log from selenium @@ -1052,7 +1052,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - getLog(typestring: string, callback?: (log: LogEntry[]) => void): NightWatchBrowser; + getLog(typestring: string, callback?: (log: NightwatchLogEntry[]) => void): this; /** * Gets the available log types @@ -1068,7 +1068,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {Available log types} */ - getLogTypes(callback?: (result: CallbackResult) => void): NightWatchBrowser; + getLogTypes(callback?: (result: NightwatchCallbackResult) => void): this; /** * Query for an element's tag name. Uses elementIdName protocol command. @@ -1087,7 +1087,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The element's tag name, as a lowercase string.} */ - getTagName(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + getTagName(selector: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Returns the visible text for the element. Uses elementIdText protocol command. @@ -1106,7 +1106,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The element's visible text.} */ - getText(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + getText(selector: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Returns the title of the current page. Uses title protocol command. @@ -1123,7 +1123,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The page title.} */ - getTitle(callback?: (result: CallbackResult) => void): NightWatchBrowser; + getTitle(callback?: (result: NightwatchCallbackResult) => void): this; /** * Returns a form element current value. Uses elementIdValue protocol command. @@ -1142,7 +1142,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The element's value.} */ - getValue(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + getValue(selector: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * This command is an alias to url and also a convenience method when called without any arguments in the sense that it performs a call to .url() with passing the value of launch_url @@ -1157,7 +1157,7 @@ interface NightWatchClient { * @param url: Url to navigate to. * @returns {} */ - init(url?: string): NightWatchBrowser; + init(url?: string): this; /** * Utility command to load an external script into the page specified by url. @@ -1175,7 +1175,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The newly created script tag.} */ - injectScript(scriptUrl: string, id?: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + injectScript(scriptUrl: string, id?: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Utility command to test if the log type is available @@ -1192,7 +1192,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - isLogAvailable(typeString: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + isLogAvailable(typeString: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine if an element is currently displayed. Uses elementIdDisplayed protocol command. @@ -1211,7 +1211,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - isVisible(selector: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + isVisible(selector: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Maximizes the current window. @@ -1225,7 +1225,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - maximizeWindow(callback?: (result: CallbackResult) => void): NightWatchBrowser; + maximizeWindow(callback?: (result: NightwatchCallbackResult) => void): this; /** * Move the mouse by an offset of the specified element. Uses moveTo protocol command. @@ -1242,7 +1242,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - moveToElement(selector: string, xoffset: number, yoffset: number, callback?: (result: CallbackResult) => void): NightWatchBrowser; + moveToElement(selector: string, xoffset: number, yoffset: number, callback?: (result: NightwatchCallbackResult) => void): this; /** * Suspends the test for the given time in milliseconds. If the milliseconds argument is missing it will suspend the test indefinitely @@ -1259,7 +1259,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - pause(ms: number, callback?: (result: CallbackResult) => void): NightWatchBrowser; + pause(ms: number, callback?: (result: NightwatchCallbackResult) => void): this; /** * A simple perform command which allows access to the "api" in a callback. Can be useful if you want to read variables set by other commands. @@ -1274,12 +1274,37 @@ interface NightWatchClient { * }) * // other stuff going on ... * // - * // self-completing callback - * .perform(function() { + * // asynchronous completion including api (client) + * .perform(function(client, done) { * console.log('elementValue', elementValue); - * // without any defined parameters, perform - * // completes immediately (synchronously) + * // similar to before, but now with client + * // potentially other async stuff going on + * // on finished, call the done callback + * done(); + * }); + * }; + * ``` + * + * @param callback: The function to run as part of the queue. Its signature can have up to two parameters. No parameters: callback runs and + * perform completes immediately at the end of the execution of the callback. One parameter: allows for asynchronous execution within the + * callback providing a done callback function for completion as the first argument. Two parameters: allows for asynchronous execution + * with the "api" object passed in as the first argument, followed by the done callback. + * @returns {} + */ + perform(callback: (browser: this, done?: () => void) => void): this; + + /** + * A simple perform command which allows access to the "api" in a callback. Can be useful if you want to read variables set by other commands. + * + * Usage: + * ``` + * this.demoTest = function (browser) { + * var elementValue; + * browser + * .getValue('.some-element', function(result) { + * elementValue = result.value; * }) + * // other stuff going on ... * // * // asynchronous completion * .perform(function(done) { @@ -1288,15 +1313,26 @@ interface NightWatchClient { * // on finished, call the done callback * done(); * }) + * }; + * ``` + * + * Usage: + * ``` + * this.demoTest = function (browser) { + * var elementValue; + * browser + * .getValue('.some-element', function(result) { + * elementValue = result.value; + * }) + * // other stuff going on ... * // - * // asynchronous completion including api (client) - * .perform(function(client, done) { + * // self-completing callback + * .perform(function() { * console.log('elementValue', elementValue); - * // similar to before, but now with client - * // potentially other async stuff going on - * // on finished, call the done callback - * done(); - * }); + * // without any defined parameters, perform + * // completes immediately (synchronously) + * }) + * // * }; * ``` * @param callback: The function to run as part of the queue. Its signature can have up to two parameters. No parameters: callback runs and @@ -1305,7 +1341,7 @@ interface NightWatchClient { * with the "api" object passed in as the first argument, followed by the done callback. * @returns {} */ - perform(callback: (browser: NightWatchBrowser, done?: () => void) => void): NightWatchBrowser; + perform(callback: (done?: () => void) => void): this; // tslint:disable-line:unified-signatures /** * Resizes the current window. @@ -1321,7 +1357,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - resizeWindow(width: number, height: number, callback?: () => void): NightWatchBrowser; + resizeWindow(width: number, height: number, callback?: () => void): this; /** * Take a screenshot of the current page and saves it as the given filename. @@ -1336,19 +1372,19 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - saveScreenshot(fileName: string, callback?: () => void): NightWatchBrowser; + saveScreenshot(fileName: string, callback?: () => void): this; /** - * SessionId of the session used by the NightWatch api. + * SessionId of the session used by the Nightwatch api. */ sessionId: string; /** - * Override the sessionId used by NightWatch client with another session id. + * Override the sessionId used by Nightwatch client with another session id. * @param sessionId: The session Id to set. * @returns {} */ - setSessionId(sessionId: string): NightWatchBrowser; + setSessionId(sessionId: string): this; /** * Set a cookie, specified as a cookie JSON object, as defined https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object. @@ -1372,12 +1408,12 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setCookie(cookie: any, callback?: () => void): NightWatchBrowser; + setCookie(cookie: any, callback?: () => void): this; /** * Sends some text to an element. Can be used to set the value of a form element or to send a sequence of key strokes to an element. Any UTF-8 character may be specified. * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec (http://www.w3.org/TR/webdriver/#character-types), - * is loaded onto the main NightWatch instance as client.Keys. + * is loaded onto the main Nightwatch instance as client.Keys. * * Usage: * ``` @@ -1397,7 +1433,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setValue(selector: string, inputValue: string, callback?: () => void): NightWatchBrowser; + setValue(selector: string, inputValue: string, callback?: () => void): this; /** * Sets the current window position. @@ -1413,7 +1449,7 @@ interface NightWatchClient { * @param callback: ptional callback function to be called when the command finishes. * @returns {} */ - setWindowPosition(OffsetX: number, OffsetY: number, callback?: () => void): NightWatchBrowser; + setWindowPosition(OffsetX: number, OffsetY: number, callback?: () => void): this; /** * Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. Uses submit protocol command. @@ -1428,7 +1464,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - submitForm(selector: string, callback?: () => void): NightWatchBrowser; + submitForm(selector: string, callback?: () => void): this; /** * Change focus to another window. The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute. @@ -1447,7 +1483,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - switchWindow(handleOrName: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + switchWindow(handleOrName: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Convenience method that adds the specified hash (i.e. url fragment) to the current value of the launch_url as set in nightwatch.json. @@ -1464,7 +1500,7 @@ interface NightWatchClient { * @param callback: * @returns {} */ - urlHash(hash: string): NightWatchBrowser; + urlHash(hash: string): this; /** * Opposite of waitForElementPresent. Waits a given time in milliseconds for an element to be not present (i.e. removed) in the page before performing any other commands @@ -1481,13 +1517,13 @@ interface NightWatchClient { * @param selector: The selector (CSS / Xpath) used to locate the element. * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. - * To set this globally you can define a property `abortOnAssertionFailure` in your globals. + * To set this globally you can define a property `abortOnNightwatchAssertionFailure` in your globals. * @param callback: Optional callback function to be called when the command finishes. * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time * (e.g. Element %s was not in the page for %d ms). * @returns {} */ - waitForElementNotPresent(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): NightWatchBrowser; + waitForElementNotPresent(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): this; /** * Opposite of waitForElementVisible. Waits a given time in milliseconds for an element to be not visible (i.e. hidden but existing) in the page before performing @@ -1504,13 +1540,13 @@ interface NightWatchClient { * @param selector: The selector (CSS / Xpath) used to locate the element. * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. - * To set this globally you can define a property `abortOnAssertionFailure` in your globals. + * To set this globally you can define a property `abortOnNightwatchAssertionFailure` in your globals. * @param callback: Optional callback function to be called when the command finishes. * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time * (e.g. Element %s was not in the page for %d ms). * @returns {} */ - waitForElementNotVisible(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): NightWatchBrowser; + waitForElementNotVisible(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): this; /** * Waits a given time in milliseconds for an element to be present in the page before performing any other commands or assertions. @@ -1538,13 +1574,13 @@ interface NightWatchClient { * @param selector: The selector (CSS / Xpath) used to locate the element. * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. - * To set this globally you can define a property `abortOnAssertionFailure` in your globals. + * To set this globally you can define a property `abortOnNightwatchAssertionFailure` in your globals. * @param callback: Optional callback function to be called when the command finishes. * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time * (e.g. Element %s was not in the page for %d ms). * @returns {} */ - waitForElementPresent(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): NightWatchBrowser; + waitForElementPresent(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): this; /** * Waits a given time in milliseconds for an element to be visible in the page before performing any other commands or assertions. @@ -1571,26 +1607,26 @@ interface NightWatchClient { * ``` * @param selector: The selector (CSS / Xpath) used to locate the element. * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. - * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnAssertionFailure` in your globals. + * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnNightwatchAssertionFailure` in your globals. * @param callback: Optional callback function to be called when the command finishes. * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time (e.g. Element %s was not in the page for %d ms). * @returns {} */ - waitForElementVisible(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): NightWatchBrowser; + waitForElementVisible(selector: string, time?: number, abortOnFailure?: boolean, callback?: () => void, message?: string): this; /** * Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - acceptAlert(callback?: () => void): NightWatchBrowser; + acceptAlert(callback?: () => void): this; /** * Navigate backwards in the browser history, if possible. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - back(callback?: () => void): NightWatchBrowser; + back(callback?: () => void): this; /** * Get a list of the available contexts. @@ -1598,7 +1634,7 @@ interface NightWatchClient { * @param callback: Callback function to be called when the command finishes. * @returns {an array of strings representing available contexts, e.g 'WEBVIEW', or 'NATIVE'} */ - contexts(callback?: (result: CallbackResult) => void): NightWatchBrowser; + contexts(callback?: (result: NightwatchCallbackResult) => void): this; /** * Retrieve or delete all cookies visible to the current page or set a cookie. @@ -1606,14 +1642,14 @@ interface NightWatchClient { * @param callbackorCookie * @returns {a string representing the current context or `null`, representing "no context"} */ - cookie(method: string, callbackorCookie?: () => void): NightWatchBrowser; + cookie(method: string, callbackorCookie?: () => void): this; /** * Get current context. * @param callback: Callback function to be called when the command finishes. * @returns {} */ - currentContext(callback?: (result: CallbackResult) => void): NightWatchBrowser; + currentContext(callback?: (result: NightwatchCallbackResult) => void): this; /** * Dismisses the currently displayed alert dialog. For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button. @@ -1621,14 +1657,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - dismissAlert(callback?: () => void): NightWatchBrowser; + dismissAlert(callback?: () => void): this; /** * Double-clicks at the current mouse coordinates (set by moveto). * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - doubleClick(callback?: () => void): NightWatchBrowser; + doubleClick(callback?: () => void): this; /** * Search for an element on the page, starting from the document root. The located element will be returned as a WebElement JSON object. @@ -1648,14 +1684,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - element(using: string, value: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + element(using: string, value: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Get the element on the page that currently has focus. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementActive(callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementActive(callback?: (result: NightwatchCallbackResult) => void): this; /** * Get the value of an element's attribute. @@ -1664,7 +1700,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdAttribute(id: string, attributeName: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdAttribute(id: string, attributeName: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Clear a TEXTAREA or text INPUT element's value. @@ -1672,7 +1708,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdClear(id: string, callback?: () => void): NightWatchBrowser; + elementIdClear(id: string, callback?: () => void): this; /** * Click on an element. @@ -1680,7 +1716,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdClick(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdClick(id: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Query the value of an element's computed CSS property. @@ -1690,7 +1726,7 @@ interface NightWatchClient { * @param callback * @returns {} */ - elementIdCssProperty(id: string, cssPropertyName: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdCssProperty(id: string, cssPropertyName: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine if an element is currently displayed. @@ -1698,7 +1734,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdDisplayed(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdDisplayed(id: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Search for an element on the page, starting from the identified element. The located element will be returned as a WebElement JSON object. @@ -1708,7 +1744,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdElement(id: string, using: string, value: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdElement(id: string, using: string, value: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Search for multiple elements on the page, starting from the identified element. The located element will be returned as a WebElement JSON objects. @@ -1718,7 +1754,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdElements(id: string, using: string, value: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdElements(id: string, using: string, value: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine if an element is currently enabled. @@ -1726,7 +1762,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdEnabled(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdEnabled(id: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Test if two element IDs refer to the same DOM element. @@ -1735,7 +1771,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdEquals(id: string, otherId: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdEquals(id: string, otherId: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. @@ -1744,7 +1780,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The X and Y coordinates for the element on the page.} */ - elementIdLocation(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdLocation(id: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine an element's location on the screen once it has been scrolled into view. @@ -1752,7 +1788,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdLocationInView(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdLocationInView(id: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Query for an element's tag name. @@ -1760,7 +1796,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdName(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdName(id: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine if an OPTION element, or an INPUT element of type checkbox or radio button is currently selected. @@ -1768,7 +1804,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdSelected(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdSelected(id: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties. @@ -1776,7 +1812,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdSize(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdSize(id: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Returns the visible text for the element. @@ -1784,7 +1820,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - elementIdText(id: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdText(id: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Send a sequence of key strokes to an element or returns the current value of the element. @@ -1793,7 +1829,7 @@ interface NightWatchClient { * @param callback * @returns {} */ - elementIdValue(id: string, value?: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + elementIdValue(id: string, value?: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Search for multiple elements on the page, starting from the document root. The located elements will be returned as a WebElement JSON objects. @@ -1803,7 +1839,7 @@ interface NightWatchClient { * @param callback: Callback function to be invoked with the result when the command finishes. * @returns {} */ - elements(using: string, value: string, callback: (result: CallbackResult) => void): NightWatchBrowser; + elements(using: string, value: string, callback: (result: NightwatchCallbackResult) => void): this; /** * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous and @@ -1827,7 +1863,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The script result.} */ - execute(body: ((...data: any[]) => void) | string, args?: any[], callback?: (result: CallbackResult) => void): NightWatchBrowser; + execute(body: ((...data: any[]) => void) | string, args?: any[], callback?: (result: NightwatchCallbackResult) => void): this; /** * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be asynchronous @@ -1851,14 +1887,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {The script result.} */ - executeAsync(script: ((...data: any[]) => void) | string, args?: any[], callback?: (result: CallbackResult) => void): NightWatchBrowser; + executeAsync(script: ((...data: any[]) => void) | string, args?: any[], callback?: (result: NightwatchCallbackResult) => void): this; /** * Navigate forwards in the browser history, if possible. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - forward(callback?: () => void): NightWatchBrowser; + forward(callback?: () => void): this; /** * Change focus to another frame on the page. If the frame id is missing or null, the server should switch to the page's default content. @@ -1866,38 +1902,38 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - frame(frameId?: string, callback?: () => void): NightWatchBrowser; + frame(frameId?: string, callback?: () => void): this; /** * Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - frameParent(callback?: () => void): NightWatchBrowser; + frameParent(callback?: () => void): this; /** * Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. * @param callback: Optional callback function to be called when the command finishes. * @returns {The text of the currently displayed alert.} */ - getAlertText(callback?: (result: CallbackResult) => void): NightWatchBrowser; + getAlertText(callback?: (result: NightwatchCallbackResult) => void): this; /** * Get the current browser orientation. * @param callback: Callback function to be called when the command finishes. * @returns {The current browser orientation: LANDSCAPE|PORTRAIT} */ - getOrientation(callback?: (result: CallbackResult) => void): NightWatchBrowser; + getOrientation(callback?: (result: NightwatchCallbackResult) => void): this; /** * Send a sequence of key strokes to the active element. The sequence is defined in the same format as the sendKeys command. - * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec, is loaded onto the main NightWatch instance as client.Keys. + * An object map with available keys and their respective UTF-8 characters, as defined on W3C WebDriver draft spec, is loaded onto the main Nightwatch instance as client.Keys. * Rather than the setValue, the modifiers are not released at the end of the call. The state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed. * @param keysToSend: The keys sequence to be sent. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - keys(keysToSend: string[], callback?: () => void): NightWatchBrowser; + keys(keysToSend: string[], callback?: () => void): this; /** * Click at the current mouse coordinates (set by moveto). @@ -1906,7 +1942,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - mouseButtonClick(button: string, callback?: () => void): NightWatchBrowser; + mouseButtonClick(button: string, callback?: () => void): this; /** * Click and hold the left mouse button (at the coordinates set by the last moveto command). Note that the next mouse-related command that should follow is mouseButtonUp . Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour. @@ -1915,7 +1951,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - mouseButtonDown(button: string, callback?: () => void): NightWatchBrowser; + mouseButtonDown(button: string, callback?: () => void): this; /** * Releases the mouse button previously held (where the mouse is currently at). Must be called once for every mouseButtonDown command issued. @@ -1924,7 +1960,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - mouseButtonUp(button: string, callback?: () => void): NightWatchBrowser; + mouseButtonUp(button: string, callback?: () => void): this; /** * Move the mouse by an offset of the specificed element. If no element is specified, the move is relative to the current mouse cursor. If an element is provided but no offset, the mouse will be moved to the center of the element. @@ -1935,14 +1971,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - moveTo(element: string, xofset: number, yoffset: number, callback?: () => void): NightWatchBrowser; + moveTo(element: string, xofset: number, yoffset: number, callback?: () => void): this; /** * Refresh the current page. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - refresh(callback?: () => void): NightWatchBrowser; + refresh(callback?: () => void): this; /** * Take a screenshot of the current page. @@ -1950,7 +1986,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - screenshot(log_screenshot_data: boolean, callback?: () => void): NightWatchBrowser; + screenshot(log_screenshot_data: boolean, callback?: () => void): this; /** * Get info about, delete or create a new session. Defaults to the current session. @@ -1976,7 +2012,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - session(action?: string, sessionId?: string, callback?: (result: CallbackResult) => void): NightWatchBrowser; + session(action?: string, sessionId?: string, callback?: (result: NightwatchCallbackResult) => void): this; /** * Gets the text of the log type specified @@ -1984,14 +2020,14 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {Array of the text entries of the log.} */ - sessionLog(typeString: string, callback?: (log: LogEntry[]) => void): NightWatchBrowser; + sessionLog(typeString: string, callback?: (log: NightwatchLogEntry[]) => void): this; /** * Gets an array of strings for which log types are available. * @param callback: Optional callback function to be called when the command finishes. * @returns {Available log types} */ - sessionLogTypes(callback?: (result: CallbackResult) => void): NightWatchBrowser; + sessionLogTypes(callback?: (result: NightwatchCallbackResult) => void): this; /** * Returns a list of the currently active sessions. @@ -2007,7 +2043,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - sessions(callback?: (result: CallbackResult) => void): NightWatchBrowser; + sessions(callback?: (result: NightwatchCallbackResult) => void): this; /** * Sends keystrokes to a JavaScript prompt() dialog. @@ -2015,7 +2051,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setAlertText(value: string, callback?: () => void): NightWatchBrowser; + setAlertText(value: string, callback?: () => void): this; /** * Sets the context @@ -2023,7 +2059,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setContext(context: string, callback?: () => void): NightWatchBrowser; + setContext(context: string, callback?: () => void): this; /** * Sets the browser orientation. @@ -2031,21 +2067,21 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - setOrientation(orientation: string, callback?: () => void): NightWatchBrowser; + setOrientation(orientation: string, callback?: () => void): this; /** * Get the current page source. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - source(callback?: () => void): NightWatchBrowser; + source(callback?: () => void): this; /** * Query the server's current status. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - status(callback?: (result: CallbackResult) => void): NightWatchBrowser; + status(callback?: (result: NightwatchCallbackResult) => void): this; /** * Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element. @@ -2053,7 +2089,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - submit(id: string, callback?: () => void): NightWatchBrowser; + submit(id: string, callback?: () => void): this; /** * Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client. @@ -2062,7 +2098,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - timeouts(typeOfOperation: string, ms: number, callback?: () => void): NightWatchBrowser; + timeouts(typeOfOperation: string, ms: number, callback?: () => void): this; /** * Set the amount of time, in milliseconds, that asynchronous scripts executed by /session/:sessionId/execute_async are permitted to run before they are aborted and a |Timeout| error is returned to the client. @@ -2070,7 +2106,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - timeoutsAsyncScript(ms: number, callback?: () => void): NightWatchBrowser; + timeoutsAsyncScript(ms: number, callback?: () => void): this; /** * Set the amount of time the driver should wait when searching for elements. If this command is never sent, the driver will default to an implicit wait of 0ms. @@ -2078,7 +2114,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - timeoutsImplicitWait(ms: number, callback?: () => void): NightWatchBrowser; + timeoutsImplicitWait(ms: number, callback?: () => void): this; /** * Get the current page title. @@ -2087,7 +2123,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - title(expected: string, msg?: string, callback?: () => void): NightWatchBrowser; + title(expected: string, msg?: string, callback?: () => void): this; /** * Retrieve the URL of the current page or navigate to a new URL. @@ -2116,7 +2152,7 @@ interface NightWatchClient { * @param callback Optional callback function to be called when the command finishes. * @returns {} */ - url(url?: string | ((result: CallbackResult) => void), callback?: (result: CallbackResult) => void): NightWatchBrowser; + url(url?: string | ((result: NightwatchCallbackResult) => void), callback?: (result: NightwatchCallbackResult) => void): this; /** * Change focus to another window or close the current window. @@ -2125,28 +2161,28 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - window(method: string, handleOrName: string, callback?: () => void): NightWatchBrowser; + window(method: string, handleOrName: string, callback?: () => void): this; /** * Retrieve the current window handle. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - windowHandle(callback?: (result: CallbackResult) => void): NightWatchBrowser; + windowHandle(callback?: (result: NightwatchCallbackResult) => void): this; /** * Retrieve the list of all window handles available to the session. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - windowHandles(callback?: (result: CallbackResult) => void): NightWatchBrowser; + windowHandles(callback?: (result: NightwatchCallbackResult) => void): this; /** * Retrieve the list of all window handles available to the session. * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - window_handles(callback?: (result: CallbackResult) => void): NightWatchBrowser; + window_handles(callback?: (result: NightwatchCallbackResult) => void): this; /** * Retrieve the current window handle. @@ -2154,7 +2190,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - windowMaximize(handleOrName?: string, callback?: () => void): NightWatchBrowser; + windowMaximize(handleOrName?: string, callback?: () => void): this; /** * Change or get the position of the specified window. If the second argument is a function it will be used as a callback and the call will perform a get request to retrieve the existing window position. @@ -2164,7 +2200,7 @@ interface NightWatchClient { * @param: callback: * @returns {} */ - windowPosition(windowHandle: string, offsetX: number, offsetY: number, callback: (result: CallbackResult) => void): NightWatchBrowser; + windowPosition(windowHandle: string, offsetX: number, offsetY: number, callback: (result: NightwatchCallbackResult) => void): this; /** * Change or get the size of the specified window. If the second argument is a function it will be used as a callback and the call will perform a get request to retrieve the existing window size. @@ -2174,7 +2210,7 @@ interface NightWatchClient { * @param callback: Optional callback function to be called when the command finishes. * @returns {} */ - windowSize(windowHandle: string, width: number, height: number, callback?: () => void): NightWatchBrowser; + windowSize(windowHandle: string, width: number, height: number, callback?: () => void): this; /** * To switch to xpath selectors instead of css as the locate strategy. @@ -2190,7 +2226,7 @@ interface NightWatchClient { * ``` * @returns {} */ - useXpath(): NightWatchBrowser; + useXpath(): this; /** * To switch to css selectors instead of xpath as the locate strategy @@ -2205,25 +2241,25 @@ interface NightWatchClient { * ``` * @returns {} */ - useCss(): NightWatchBrowser; + useCss(): this; - options: NightWatchTestOptions; + options: NightwatchTestOptions; - Keys: Keys; + Keys: NightwatchKeys; - currentTest: TestSuite; + currentTest: NightwatchTestSuite; globals: any; launch_url: string; } -interface NightWatchBrowser extends NightWatchClient, NightWatchCustomPageObjects { } +interface NightwatchBrowser extends NightwatchClient, NightwatchCustomPageObjects { } -type NightWatchTest = (arg1: NightWatchBrowser) => void; +type NightwatchTest = (arg1: NightwatchBrowser) => void; -interface NightWatchTests { - [key: string]: NightWatchTest; +interface NightwatchTests { + [key: string]: NightwatchTest; } /* tslint:enable:max-line-length */ diff --git a/types/nightwatch/nightwatch-tests.ts b/types/nightwatch/nightwatch-tests.ts index 1e16c29..62122fb 100644 --- a/types/nightwatch/nightwatch-tests.ts +++ b/types/nightwatch/nightwatch-tests.ts @@ -1,4 +1,4 @@ -const test: NightWatchTests = { +const test: NightwatchTests = { 'Demo test Google': (browser) => { browser .url('http://www.google.com') From 6db6c44ae9f1ea688e901e94a8f79450bf1d8f86 Mon Sep 17 00:00:00 2001 From: Connor Schlesiger Date: Thu, 31 Aug 2017 21:15:14 -0400 Subject: [PATCH 5/6] Additional changes mostly to fix issues when adding custom assertions and commands --- types/nightwatch/index.d.ts | 114 +++++++++++++++++++++++++++--------- 1 file changed, 85 insertions(+), 29 deletions(-) diff --git a/types/nightwatch/index.d.ts b/types/nightwatch/index.d.ts index f71beca..6fc025e 100644 --- a/types/nightwatch/index.d.ts +++ b/types/nightwatch/index.d.ts @@ -353,23 +353,23 @@ interface NightwatchTestSettingGeneric { } interface NightwatchTestSettingScreenshots extends NightwatchTestSettingGeneric { - /** - * Selenium generates screenshots when command errors occur. With on_failure set to true, also generates screenshots for failing or erroring tests. These are saved on the disk. - * Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false. - * Example: - * "screenshots" : { - * "enabled" : true, - * "on_failure" : true, - * "on_error" : false, - * "path" : "" - * } - */ - screenshots: NightwatchScreenshotOptions; + /** + * Selenium generates screenshots when command errors occur. With on_failure set to true, also generates screenshots for failing or erroring tests. These are saved on the disk. + * Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false. + * Example: + * "screenshots" : { + * "enabled" : true, + * "on_failure" : true, + * "on_error" : false, + * "path" : "" + * } + */ + screenshots: NightwatchScreenshotOptions; } interface NightwatchTestOptions extends NightwatchTestSettingGeneric { - screenshots: boolean; - screenshotsPath: string; + screenshots: boolean; + screenshotsPath: string; } interface NightwatchTestSuite { @@ -379,7 +379,7 @@ interface NightwatchTestSuite { results: any; } -interface NightwatchAssertionError { +interface NightwatchAssertionsError { name: string; message: string; showDiff: boolean; @@ -402,7 +402,7 @@ interface NightwatchLanguageChains { } interface NightwatchTestSettings { - [key: string]: NightwatchTestSettingScreenshots; + [key: string]: NightwatchTestSettingScreenshots; } interface Expect extends NightwatchLanguageChains, NightwatchBrowser { @@ -496,7 +496,7 @@ interface Expect extends NightwatchLanguageChains, NightwatchBrowser { visible: this; } -interface NightwatchAssertion extends NightwatchBrowser { +interface NightwatchAssertions extends NightwatchBrowser { /** * Checks if the given attribute of an element contains the expected value. * @param selector: The selector (CSS / Xpath) used to locate the element. @@ -646,12 +646,13 @@ interface NightwatchAssertion extends NightwatchBrowser { */ visible(cssSelector: string, msg?: string): this; - NightwatchAssertionError: NightwatchAssertionError; + NightwatchAssertionsError: NightwatchAssertionsError; } interface NightwatchTypedCallbackResult { status: number; value: T; + state: Error | string; } // tslint:disable-next-line:no-empty-interface @@ -798,12 +799,12 @@ interface NightwatchKeys { "COMMAND": string; } -interface NightwatchClient { - assert: NightwatchAssertion; +interface NightwatchAPI { + assert: NightwatchAssertions; expect: Expect; - verify: NightwatchAssertion; + verify: NightwatchAssertions; /** * Clear a textarea or a text input element's value. Uses elementIdValue protocol command. @@ -1517,7 +1518,7 @@ interface NightwatchClient { * @param selector: The selector (CSS / Xpath) used to locate the element. * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. - * To set this globally you can define a property `abortOnNightwatchAssertionFailure` in your globals. + * To set this globally you can define a property `abortOnNightwatchAssertionsFailure` in your globals. * @param callback: Optional callback function to be called when the command finishes. * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time * (e.g. Element %s was not in the page for %d ms). @@ -1540,7 +1541,7 @@ interface NightwatchClient { * @param selector: The selector (CSS / Xpath) used to locate the element. * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. - * To set this globally you can define a property `abortOnNightwatchAssertionFailure` in your globals. + * To set this globally you can define a property `abortOnNightwatchAssertionsFailure` in your globals. * @param callback: Optional callback function to be called when the command finishes. * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time * (e.g. Element %s was not in the page for %d ms). @@ -1574,7 +1575,7 @@ interface NightwatchClient { * @param selector: The selector (CSS / Xpath) used to locate the element. * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. - * To set this globally you can define a property `abortOnNightwatchAssertionFailure` in your globals. + * To set this globally you can define a property `abortOnNightwatchAssertionsFailure` in your globals. * @param callback: Optional callback function to be called when the command finishes. * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time * (e.g. Element %s was not in the page for %d ms). @@ -1607,7 +1608,7 @@ interface NightwatchClient { * ``` * @param selector: The selector (CSS / Xpath) used to locate the element. * @param time: The number of milliseconds to wait. The runner performs repeated checks every 500 ms. - * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnNightwatchAssertionFailure` in your globals. + * @param abortOnFailure: By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails. To set this globally you can define a property `abortOnNightwatchAssertionsFailure` in your globals. * @param callback: Optional callback function to be called when the command finishes. * @param message: Optional message to be shown in the output; the message supports two placeholders: %s for current selector and %d for the time (e.g. Element %s was not in the page for %d ms). * @returns {} @@ -1983,10 +1984,10 @@ interface NightwatchClient { /** * Take a screenshot of the current page. * @param log_screenshot_data: Whether or not the screenshot data should appear in the logs when running with --verbose - * @param callback: Optional callback function to be called when the command finishes. + * @param callback: Optional callback function to be called with the resultant value (Base64 PNG) when the command finishes. * @returns {} */ - screenshot(log_screenshot_data: boolean, callback?: () => void): this; + screenshot(log_screenshot_data: boolean, callback?: (screenshotEncoded: string) => void): this; /** * Get info about, delete or create a new session. Defaults to the current session. @@ -2254,12 +2255,67 @@ interface NightwatchClient { launch_url: string; } -interface NightwatchBrowser extends NightwatchClient, NightwatchCustomPageObjects { } +interface NightwatchBrowser extends NightwatchAPI, NightwatchCustomPageObjects { } -type NightwatchTest = (arg1: NightwatchBrowser) => void; + +/** + * Performs an assertion + * + * @param passed + * @param receivedValue + * @param expectedValue + * @param message + * @param abortOnFailure + * @param originalStackTrace + */ +type NightwatchTest = (browser: NightwatchBrowser) => void; interface NightwatchTests { [key: string]: NightwatchTest; } +/** + * Performs an assertion + * + * @param passed + * @param receivedValue + * @param expectedValue + * @param message + * @param abortOnFailure + * @param originalStackTrace + */ +type NightwatchAssert = (passed: boolean, receivedValue?: any, expectedValue?: any, message?: string, abortOnFailure?: boolean, originalStackTrace?: string) => void; + +/** + * Abstract assertion class that will subclass all defined assertions + * + * All assertions must implement the following api: + * + * - @param {boolean|function} expected + * - @param {string} message + * - @param {function} pass + * - @param {function} value + * - @param {function} command + * - @param {function} - Optional failure + */ +interface NightwatchAssertion { + expected: (() => void) | boolean; + message: string; + pass: (...args: any[]) => any; + value: (...args: any[]) => any; + command: (...args: any[]) => any; + failure?: (...args: any[]) => any; + api?: NightwatchAPI; +} + +interface NightwatchClient { + api: NightwatchAPI; + assertion: NightwatchAssert; +} + +interface Nightwatch { + api: NightwatchAPI; + client: NightwatchClient; +} + /* tslint:enable:max-line-length */ From a12f94cd90999dd4f878b1f701c0335be77859fe Mon Sep 17 00:00:00 2001 From: Connor Schlesiger Date: Thu, 31 Aug 2017 22:08:51 -0400 Subject: [PATCH 6/6] Fix lint issues --- types/nightwatch/index.d.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/types/nightwatch/index.d.ts b/types/nightwatch/index.d.ts index 6fc025e..bfebe27 100644 --- a/types/nightwatch/index.d.ts +++ b/types/nightwatch/index.d.ts @@ -2257,7 +2257,6 @@ interface NightwatchAPI { interface NightwatchBrowser extends NightwatchAPI, NightwatchCustomPageObjects { } - /** * Performs an assertion * @@ -2301,10 +2300,10 @@ type NightwatchAssert = (passed: boolean, receivedValue?: any, expectedValue?: a interface NightwatchAssertion { expected: (() => void) | boolean; message: string; - pass: (...args: any[]) => any; - value: (...args: any[]) => any; - command: (...args: any[]) => any; - failure?: (...args: any[]) => any; + pass(...args: any[]): any; + value(...args: any[]): any; + command(...args: any[]): any; + failure?(...args: any[]): any; api?: NightwatchAPI; }