Skip to content

Commit

Permalink
updated api docs and static asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Jun 13, 2021
1 parent 7603a23 commit c3cde8a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 71 deletions.
2 changes: 2 additions & 0 deletions lib/api/_loaders/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ module.exports = class StaticAssert {
notDeepEqual: ['not deepEqual', 'deepEqual'],
strictEqual: ['===', '!=='],
notStrictEqual: ['!==', '==='],
deepStrictEqual: ['deep strict equal', 'not deep strict equal'],
throws: ['throws', 'doesNotThrow'],
doesNotThrow: ['doesNotThrow', 'throws'],
match: ['matches', 'does not match'],
fail: 'fail',
ifError: 'ifError'
};
Expand Down
2 changes: 1 addition & 1 deletion lib/api/assertions/enabled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* Checks if the given element is visible on the page.
* Checks if the given element is enabled (as indicated by the 'disabled' attribute).
*
* ```
* this.demoTest = function (browser) {
Expand Down
45 changes: 11 additions & 34 deletions lib/api/element-commands/findElement.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
const BaseElementCommand = require('./_baseElementCommand.js');

/**
* Search for an element on the page, starting from the document root. The located element will be returned as a web element JSON object.
* First argument to be passed is the locator strategy, which is detailed on the [WebDriver docs](https://www.w3.org/TR/webdriver/#locator-strategies).
*
* The locator strategy can be one of:
* - `css selector`
* - `link text`
* - `partial link text`
* - `tag name`
* - `xpath`
* Search for an elements on the page, starting from the document root. The located element will be returned as web element JSON object (with an added .getId() convenience method).
* First argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).
*
* @example
* module.exports = {
* 'demo Test' : function(browser) {
* browser.element('css selector', 'body', function(result) {
* console.log(result.value)
* });
* },
*
* 'es6 async demo Test': async function(browser) {
* const result = await browser.element('css selector', 'body');
* console.log('result value is:', result.value);
* }
* }
* 'demo Test': function(browser) {
* const resultElement = await browser.findElement('.features-container li:first-child');
*
* // Example with using page object elements
* module.exports = {
* 'demo Test with page object' : function(browser) {
* const loginPage = browser.page.login();
* loginPage.api.element('@resultContainer', function(result) {
* console.log(result.value)
* });
* }
* }
* console.log('Element Id:', resultElement.getId());
* },
*
*
* @link /#find-element
* @syntax .findElement(using, value, callback)
* @editline L680
* @param {string} using The locator strategy to use.
* @param {string} value The search target.
* @param {function} callback Callback function which is called with the result value.
* @syntax browser.findElement(selector, callback)
* @syntax await browser.findElement(selector);
* @param {string} selector The search target.
* @param {function} [callback] Callback function to be invoked with the result when the command finishes.
* @since 1.7.0
* @api protocol.elements
*/
const FindElements = require('./findElements.js');
Expand Down
42 changes: 8 additions & 34 deletions lib/api/element-commands/findElements.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,25 @@
const BaseElementCommand = require('./_baseElementCommand.js');

/**
* Search for multiple elements on the page, starting from the document root. The located elements will be returned as web element JSON objects.
* First argument to be passed is the locator strategy, which is detailed on the [WebDriver docs](https://www.w3.org/TR/webdriver/#locator-strategies).
* Search for multiple elements on the page, starting from the document root. The located elements will be returned as web element JSON objects (with an added .getId() convenience method).
* First argument is the element selector, either specified as a string or as an object (with 'selector' and 'locateStrategy' properties).
*
* The locator strategy can be one of:
* - `css selector`
* - `link text`
* - `partial link text`
* - `tag name`
* - `xpath`
*
* @example
* module.exports = {
* 'demo Test' : function(browser) {
* browser.elements('css selector', 'ul li', function(result) {
* console.log(result.value)
* });
* },
* 'demo Test': function(browser) {
* const resultElements = await browser.findElements('.features-container li');
*
* 'es6 async demo Test': async function(browser) {
* const result = await browser.elements('css selector', 'ul li');
* console.log('result value is:', result.value);
* resultElements.forEach(item => console.log('Element Id:', item.getId()));
* },
*
* 'page object demo Test': function (browser) {
* var nightwatch = browser.page.nightwatch();
* nightwatch
* .navigate()
* .assert.titleContains('Nightwatch.js');
*
* nightwatch.api.elements('@featuresList', function(result) {
* console.log(result);
* });
*
* browser.end();
* }
* }
*
* @link /#find-elements
* @syntax browser.findElements(using, value, callback)
* @syntax browser.findElements(selector, callback)
* @syntax await browser.findElements(selector);
* @editline L734
* @param {string|null} using The locator strategy to use.
* @param {string} value The search target.
* @param {function} callback Callback function to be invoked with the result when the command finishes.
* @param {string} selector The search target.
* @param {function} [callback] Callback function to be invoked with the result when the command finishes.
* @since 1.7.0
* @api protocol.elements
*/
module.exports = class Elements extends BaseElementCommand {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/element-commands/setPassword.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const BaseElementCommand = require('./_baseElementCommand.js');

/**
* 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 alias of "setValue" command, but hides the content from the nightwatch logs.
*
* <div class="alert alert-warning"><strong>setValue</strong> does not clear the existing value of the element. To do so, use the <strong>clearValue()</strong> command.</div>
* <div class="alert alert-warning"><strong>setValue/setPassword</strong> do not clear the existing value of the element. To do so, use the <strong>clearValue()</strong> command.</div>
*
* An object map with available keys and their respective UTF-8 characters, as defined on [W3C WebDriver draft spec](https://www.w3.org/TR/webdriver/#character-types), is loaded onto the main Nightwatch instance as `browser.Keys`.
*
Expand Down

0 comments on commit c3cde8a

Please sign in to comment.