Automated testing suite Based on phantomjs
Today, we will introduce a suite of automated testing tools named nightmare. It is a testing framework based on phantomjs and a set of high-level APIs encapsulated for testing applications based on phantomjs. Its API uses goto, refresh, click, type... And so on. Its official in http://www.nightmarejs.org /. if your project test does not need to be understood by the tester, you may be a good choice to test the code based on nightmare. You can reduce the cost of the test code and deploy the test suite. We can choose to integrate the test suite Based on jasmine-node. Install nginx mare: 1npm install it. Next we will compare it with 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. querySelector ('. searchsubmit '); Var event = document. createEvent ('mouseevent'); event. initEvent ('click', true, false); el. dispatchEvent (event);}, function (result) {ph. exit () ;}) ;};}); the Code of the maid is new nightmare (). goto ('HTTP: // yahoo.com '). type ('input [title = "Search"] ', 'github nightmare '). click ('. searchsubmit '). run (); everything is obvious, not to mention. You can also use the plug-in to extract public logic for reuse and increase the meaning of the test code. For example:/*** Login to a Swiftly account. ** @ param {String} email * @ param {String} password */exports. login = function (email, password) {return function (nightmare) {nightmare. viewport (800,160 0 ). goto ('https: // swiftly.com/login '). type ('# username', email ). type ('# password', password ). click ('. button -- primary '). wait () ;};}; the code is simple: var Swiftly = require ('nightmare-swiftly'); new nightmare (). use (Swiftly. login (email, password )). use (Swiftly. task (instructions, uploads, path )). run ();