Postman is an interface test tool, the relative JMeter interface flat simple, very convenient to develop debugging interface use, if you want to do testing, to achieve batch interface management, single interface assertion, as well as special character processing, even batch regression test, generate reports, Combining Jenkins to achieve CI integration can be done.
1. Environment variables, global variables-Global variables
Global variables can be used to postman all interfaces, set in such a way that initial value is an initial value that can be used everywhere to share with others, and current value is the value that is used to present the project
-Environment variables
Environment variables can be added multiple, the interface can be built to choose one of the environment variable settings, for example, you can add multiple sets of different environment variable information for testing in different environments, you can also directly import the environment variables exported by colleagues JSON file
2. Add an interface
Postman support for a single interface is quite rich, can be selected on demand, the structure is relatively flat, basic testing of an interface required to be found on a page
Fill in the parameters bulk edit is convenient, especially when there are multiple sets of values when the first click Bulk Edit, paste into multiple sets of Key:value values and then click Key-value Edit can be automatically converted into a table format.
3. Pre-scripted-pre-request script
When doing batch regression testing, there are many interfaces that require parameters such as random strings/random numbers or timestamps, which we can do with scripting. Pre-request script supports JS, which implements random characters with specific format timestamps and assigns to environment variables:
Pm.environment.set ("Randomname", "Test Plan" +math.random ());p M.environment.set ("Today", Getnowformatdate ());functiongetnowformatdate () {varDate =NewDate (); varSeperator1 = "-"; varYear =date.getfullyear (); varmonth = Date.getmonth () + 1; varStrdate =date.getdate (); if(Month >= 1 && month <= 9) {Month= "0" +month; } if(strdate >= 0 && strdate <= 9) {strdate= "0" +strdate; } varcurrentdate = year + seperator1 + month + Seperator1 +strdate; returncurrentdate; }
The above Pre-request script sets up two environment variables, which are good when used with two curly braces, such as:
4. Test Script-test
Test scripts can be used to design interface test assertions, analyze response content, or determine request results and status. The right side of the use of a lot of snippets can be used for reference, Support JS language, you can also write some auxiliary scripts to use
5. Import and Export
Postman supports environment variables, global variables and interface combinations (Collection) to how to export, Collection to the right of the small arrow point to see the Share/run and export-related functions, imported and exported in the form of JSON, Can be placed in the corresponding project to facilitate management and sharing
6.newman, reporting
Make sure the Nodejs is installed on the machine and then install the Newman via NPM:
NPM Install Newman-g
After installing Newman, you can run collection directly from the command line:
Newman run Mycollection.json
Take the exported environment variable file run 10 times:
Newman run MYCOLLECTION.JSON-E myenv.json-n 10
Generate a fixed-format report (the following command generates JSON,HTML,JUNIT reports in different formats):
Newman run Mycollection.json-e Myenv.json--reporterscli,json,html,junit
7. Xmysql
There are a number of interface tests to be combined with database validation, JMeter has a dedicated JDBC connection module, postman but not, but it is not completely not. For MySQL databases there is a one command to generate REST API for any MySQL database gadget xmysql very amazing and useful:
Installation: NPM Install Xmysql-g
Use: xmysql-h localhost-u mysqluser-p mysqlpassword-d databaseName
Then open: http://localhost:3000 can see a bunch of JSON in the database above, find the corresponding table you want to check, and then a GET request in postman to query the table all the data, You can add the appropriate parsing script in test to determine whether the expected data is included in the results found:
8. About adding cookies
Newman as a Nodejs module can be easily put into a JS project, for example, I test the product, the way the cookie is constructed is very complex, can only be obtained by simulating the way of landing, If I wrote a simple script via python to get a cookie and then deposit it into the exported Postman environment variable JSON file, run the case in collection by Newman JS script, Paste Newman JS Some of the scripts are as follows (Generate Html,junit format report for integration with Jenkins)
var Newman = require ("Newman"); Newman.run ({ collection:require ('./testadvance.postman_collection.json '), Environment:require ('./testfeatured.postman_environment.json '), reporters:[' CLI ', ' html ', ' JUnit ']}). On (' Start ', function (err, args) {//on start of Run, log to console Console.log (' Running a collection ... ');}). On (' Do ', function (err, summary) { if (err | | summary.error) { console.error (' collection run encountered an Erro R. '); } else { Console.log (' collection run completed. '); }},process.exit);
About Postman+xmysql+nodejs's practice sharing