Web front-end automatic interface scanning

Source: Internet
Author: User

The first time to send a blog, but also ask you a lot of advice.

Currently in the project is separated from the front and back, using wiremock data, but the interface is generally driven by the background (version manager in the background). Many times the background changes the interface often did not inform the foreground, resulting in a frequent interface error, and many times there is a dependency between the interfaces, if the previous interface can not test the subsequent interface is not able to proceed. Based on this, it is necessary to develop a set of methods that can automatically test the interface.

Directly on the code, Testportforconsole.js:

var postdatas = [{url: '/getstudents.do ', portname: ', Description: ', data:{ ServiceName: "Getstudents", Class: "Six", Grade: "Both"}, {URL: "/get Score.do ", PortName: ', Description: ', data:{serviceName:" Getscore ", Stude Ntid: "08070146", Subject: "Math"}}
Each of these elements corresponds to an interface];(function () {Localstorage.removeitem (' success '); Localstorage.removeitem (' failed '); var send = function (url,param,portname) {$.ajax ({url:url, type: ' POST ', data:j Son.stringify (param), DataType: ' application/json,text/plain.*/* '}). Success (function (data) { Localstorage.setitem (' Success ', Localstorage.getitem (' success ') + PortName + ' interface return success | '); }). Error (function (data) {Localstorage.setitem (' failed ', Localstorage.getitem (' failed ') + PortName + ' interface return failed | ') ; Throw PortName + ' interface return failed '; }) }; for (var s = 0,len = Postdatas.length;s < len;s++) {send (Postdatas[s].url,postdatas[s].data, Postdatas[s].portnam e); }})();

If there are too many interfaces, consider using the grunt command to merge the mock data from each of the issued requests from the project, which facilitates sub-module maintenance and management.

Module.exports = function (grunt) {    //project configuration    grunt.initconfig ({        Pkg:grunt.file.readJSON (' Package.json '),        concat: {            options: {                banner: ' [\ n ',                separator: ', \ n ',                footer: '] ',                stripbanners: ' True '            },            build: {                src: ' Src/**/*.json ',                dest: ' Dest/dest.json '}}}    );    Grunt.loadnpmtasks (' Grunt-contrib-concat ');    Grunt.registertask (' Default ', [' concat ']);}

This can be done directly in the original project directly in the Testportforconsole.js code copy run to automatically complete the interface scan. The results of the scan are saved in localstorage and can be obtained by the following methods

Console.dir (Localstorage.getitem (' success '). Split (' | '));
Console.dir (Localstorage.getitem (' failed '). Split (' | '));

Novice seeking support ~_~.

Web front-end automatic interface scanning

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.