Socket
Socket
Sign inDemoInstall

nightwatch-commands

Package Overview
Dependencies
69
Maintainers
4
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nightwatch-commands

A set of Mobify specific custom commands for Nightwatch.js


Version published
Weekly downloads
227
increased by70.68%
Maintainers
4
Install size
37.0 MB
Created
Weekly downloads
 

Readme

Source

nightwatch-commands

NPM version

A set of Mobify specific custom commands for Nightwatch.js

Download

To begin, clone this repository. cd into your chosen folder, and run the following: npm install

Selenium server and Chromedriver will also be downloaded into /selenium.

Currently Using https://www.npmjs.com/package/selenium-download version: 2.0.10 - selenium chromedriver 2.29 - selenium standalone server 3.4.0

Linting

JavaScript in this tool is linted with ESLint according to our code syntax and style standards here at Mobify.

Linting may be run with the grunt lint command. Code is also linted automatically on CircleCI.

Use

In order for your project to be able to access these commands and assertions you need to include them in your projects nightwatch.js settings.json file.

It should look something like this:

"custom_commands_path": "./node_modules/nightwatch-commands/commands",
"custom_assertions_path": "./node_modules/nightwatch-commands/assertions"

Assertions

elementsCount(selector, expected, message, callback)

The elementsCount assertion checks if the given selector is present the number of times that is expected for that selector to appear.

Parameter NameParameter TypeDescription
selectorStringThe CSS/Xpath selector to locate the element.
expectedNumberThe expected number of times for the attribute to appear.
messageStringoptional The message to output.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.assert.elementsCount('#x-root', 1);
}
elementsPresent(selector, message, callback)

The elementsPresent assertion checks if the given selectors are present. It returns a list of the missing selectors.

Parameter NameParameter TypeDescription
selectorStringThe CSS/Xpath selector to locate the element.
messageStringoptional The message to output.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.assert.elementsPresent('#x-root', '#x-header', '#x-footer');
};
elementsVisible(selector, message, callback)

The elementsVisible assertion checks if one or more selectors are visible. It returns a list of one or more selectors that are not visible on the page.

Parameter NameParameter TypeDescription
selectorsStringThe CSS/Xpath selector to locate the element.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.assert.elementsVisible('#x-root', '#x-head');
};
templateName(expected, message, callback)

The templateName assertion checks if the given template name is correct.

Parameter NameParameter TypeDescription
expectedStringThe expected value of the attribute to check.
messageStringoptional A log message to display in the output. If the parameter is not specified, a default message is displayed.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (client) {
    browser.assert.templateName('home');
};

Commands

get(url, callback)

The get command combines the url and waitUntilMobified functions. This command uses the browser.execute function to run code within the client browser. It then waits for the Mobifyor Adaptive object to be present on the page

Parameter NameParameter TypeDescription
urlStringThe URL to load
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.get('http://www.test.com');
};
getMobifyEvaluatedData(callback)

The getMobifyEvaluatedData command uses the waitForCondition method to retrieve the Mobify.evaluatedData from the client browser.

Input

Parameter NameParameter TypeDescription
callbackFunctionoptional A function to call after the current command finishes execution.

Output

Parameter NameDescription
ObjectReturns the client object after waitUntilMobified executes on it with the specified parameters.
this.demoTest = function (browser) {
    browser.getMobifyEvaluatedData();
};
htmlCapture(message, callback)

htmlCapture is a helper command that saves HTML to tests/system/integration/fixtures. This command was designed to collect and save HTML files for use in integration tests. This command is intended to be run using a Nightwatch environment with a desktop user agent, however, it can still be used to capture any HTML as required.

Parameter NameParameter TypeDescription
fileNameStringcamelCased alphanumeric string ending with ".html", representing the name of the fixture
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.htmlCapture('cart.html');
};
log(message, callback)

The log command prints a message to the console. Use this command to output messages in a test.

Parameter NameParameter TypeDescription
messageStringThe message to log on the console.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.log('Testing submitting form');
};
clickAndWaitUntilMobified(selector, callback)

The clickAndWaitUntilMobified command initiates a click command on the supplied selector link, navigates to the URL, and then it initiates the waitUntilMobified function before it continues the chain of tests.

Parameter NameParameter TypeDescription
selectorStringThe CSS selector to click on to navigate to the new URL.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.clickAndWaitUntilMobified('.myLink');
};
preview(url, bundle, callback)

The preview command uses http://preview.mobify.com to open a website specified by url to preview a given bundle specified by bundle.

Parameter NameParameter TypeDescription
urlStringThe URL to preview, equivalent to the Site URL field.
bundleStringoptional The bundle URL, equivalent to the Bundle Location field. Default is https://localhost:8443/loader.js
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (client) {
    browser.preview('https://www.merlinspotions.com', 'https://localhost:8443/loader.js', );
};
trigger(selector, type, callback)

The trigger command simulates a specified event type on the supplied DOM element specified by the selector parameter.

Parameter NameParameter TypeDescription
selectorStringThe CSS/Xpath selector to locate the element.
typeStringThe specified event type, for example click in the enabled JSON Wire Protocols.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.trigger('.myLink', 'click');
};
triggerClick(selector, callback)

The triggerClick command uses Javascript's click function on a given selector. Use this when the regular Selenium .click does not work.

Parameter NameParameter TypeDescription
selectorStringThe CSS/Xpath selector to locate the element.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.triggerClick('.myLink');
};
triggerTouch(selector, type, callback)

The triggerTouch command simulates a specified touch type event on the supplied DOM element. Use this command when Selenium's click does not register.

Parameter NameParameter TypeDescription
selectorStringThe CSS/Xpath selector to locate the element.
typeStringThe specified event type, for example click in the enabled JSON Wire Protocols.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.triggerTouch('.myLink', 'click');
};
waitForAjaxCompleted(callback)

The waitForAjaxCompleted command uses the waitForCondition function to execute code within the client browser. The command checks the value of jQuery.active to ensure that the number of active connections is 0.

Parameter NameParameter TypeDescription
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.waitForAjaxCompleted();
};
waitForAnimation(milliSeconds, callback)

The waitForAnimation command suspends the test for the given time in milliseconds while it waits for animation to complete.

Parameter NameParameter TypeDescription
milliSecondsNumberThe number of millliseconds to wait.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.waitForAnimation();
};
waitForCondition(condition, milliSeconds, timeout, message, callback)

The waitForCondition command receives a condition to check for, waits for a maximum time before timing out, and polls at a specified time interval. The condition returns either as a success or a timeout.

Parameter NameParameter TypeDescription
conditionFunctionThe condition to check against.
milliSecondsNumberoptional The number of milliseconds to poll before timeout.
timeoutNumberoptional The number of milliseconds between each poll.
messageStringoptional The message to output.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    return browser.waitForCondition('return $.active;', 8000, function(result) {
        if (typeof callback === 'function') {
           callback.call(browser, result);
        }
    });
};
waitForContextsReady(expectedContextsCount, milliseconds, timeout, messages, callback)

The waitForContextsReady command receives a number of expected contexts to check for, waits for a maximum time before timing out, and polls at a specified time interval. Used with Appium when testing hybrid mobile web apps. See http://nightwatchjs.org/api/contexts.html

Parameter NameParameter TypeDescription
expectedContextsCountNumberThe condition to check against.
milliSecondsNumberoptional The number of milliseconds to poll before timeout.
timeoutNumberoptional The number of milliseconds between each poll.
messageStringoptional The message to output.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.waitForContextsReady(3, 8000);
    // At this point, it is safe to switch the context to either the NATIVE
    // context or any of the WEBVIEW_* contexts.
};
waitForUrl(url, milliseconds, timeout, messages, callback)

The waitForUrl command waits until the page URL is equal to the specified url.

Parameter NameParameter TypeDescription
urlStringExpected URL
milliSecondsNumberoptional The number of milliseconds to poll before timeout.
timeoutNumberoptional The number of milliseconds between each poll.
messageStringoptional The message to output.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.waitForUrl('http://www.google.ca/');
};
waitForUrlToContain(url, milliseconds, timeout, messages, callback)

The waitForUrlToContain command waits until the page URL contains the specified url.

Parameter NameParameter TypeDescription
urlStringA partial URL to match against.
milliSecondsNumberoptional The number of milliseconds to poll before timeout.
timeoutNumberoptional The number of milliseconds between each poll.
messageStringoptional The message to output.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.waitForUrlToContain('google');
};
waitUntilMobified(milliSeconds, callback)

The waitUntilMobified command will use the waitForCondition command to poll for the Mobify or Adaptive object on the page to ensure that the adaptation is complete. Use this command to browse to a page or if the page reloads.

Parameter NameParameter TypeDescription
milliSecondsNumberoptional The number of milliseconds to poll before timeout.
If not specified, the default timeout is 10,000 milliseconds.
callbackFunctionoptional A function to call after the current command finishes execution.
this.demoTest = function (browser) {
    browser.waitUntilMobified();
};

FAQs

Last updated on 14 Jul 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc