Nightmare PHANTOMJS-based automated test suite

Source: Internet
Author: User

Today will introduce an automated test suite called nightmare, a PHANTOMJS-based test framework, a set of high-level APIs based on PHANTOMJS for the test application. Its API to Goto, refresh, click, type ... such as simple common e2e test action package, make its semantics clear, concise. Its official in http://www.nightmarejs.org/.

If your project test does not need to be understood by the needs and testers, then the nightmare-based test may be a good choice, your cost of reducing the test code, and the deployment of the test suite. We can choose to integrate as a test suite based on Jasmine-node.

Install Nightmare:

NPM Install Nightmare

Below we compare the comparison with the remote PHANTOMJS:

The original PHANTOMJS code:

Phantom.create (function (ph) {  ph.createpage (function (page) {    page.open (' http://yahoo.com '), function ( Status) {      page.evaluate (function () {        var el =          document.queryselector (' input[title= "Search"] ");        El.value = ' GitHub nightmare ';      }, function (result) {        page.evaluate (function () {          var el = Document.querysele ctor ('. Searchsubmit ');          var event = document.createevent (' MouseEvent ');          Event.initevent (' Click ', True, false);          El.dispatchevent (event);        }, function (result) {          ph.exit ();        })    ;});  });

  

Nightmare code:

New Nightmare ()  . Goto (' http://yahoo.com ')  . Type (' input[title= "Search"] ', ' GitHub nightmare ')  . Click ('. Searchsubmit ')  . Run ();

Everything is obvious, don't say much.

Nightmare also supports plug-in methods for extracting common logic for reuse and for improving test code semantics, as in the following example:

/** * Login to a swiftly account. * * @param {string} email * @param {string} password */exports.login = function (email, password) {  return function (nigh Tmare) {    nightmare      . Viewport (+).      Goto (' Https://swiftly.com/login ')        . Type (' #username ', email).        type (' #password ', password).        Click ('. Button--primary ').      wait ();  };};

Using the code is simple:

var swiftly = require (' nightmare-swiftly '); new Nightmare ()  . Use (Swiftly.login (e-mail, password))  . Use ( Swiftly.task (instructions, uploads, path))  . Run ();

  

Nightmare PHANTOMJS-based automated test suite

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.