Automated testing suite Based on phantomjs

Source: Internet
Author: User

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 ();

Related Article

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.