Interface automated testing tool, Postman detailed explanation

 1. Concept

1. Postman is a powerful Chrome plug-in for webpage debugging and sending HTTP requests. Postman is divided into two versions: Postman native app and Postman Chrome app. Currently, the Chrome app has stopped maintenance, and this version is not officially recommended.
2. Official website download address: http://www.getpostman.com

3: Official documents: http://www.getpostman.com/docs

2. Basic testing process

1. The first step: Create a new interface set and manage all interfaces

2. Step 2: Create a new interface request

3. Step 3: Fill in the corresponding parameters and add assertions

4. Step 4: Run the interface set

5. Step 5: Get the use case results

3. Interface request method

1. Get request: click on Params, enter parameters and value, you can enter more than one, and it will be displayed on the URL link in real time

2. POST request:
1) Parameter format

2) Binary file submission:

3) You can directly use shortcuts to import body or params data

4. Set variables and test sandbox

1. Environment variables


 1) Step 1: Create an Environment variable


 2) The second step: call the Environment variable, the call parameter method is: { {variable name}}


2. Global variables


1) Create a Globals variable


 2) Call the Globals variable


  3. Test sandbox
    1) The Postman test sandbox actually combines JS scripts to complete the functions in the test, and realizes some test operations before and after the request is initiated.
    2) Commonly used functions: pre request scripts (pre request scripts) set request pre-operations such as setting variables, etc.
         After the request, assert the status code, response header, response body and other information.


5. Assertion
1. Concept: Assertion is the judgment of the expected result and the actual result, if the expected == actual, it will pass; expected! =Pass then fail
  2. Postman's assertion is written in JavaScript language, written in the tests tab, run in the sandbox
  3. Common assertions: please refer to: https://www.cnblogs.com/suim1218/p/8931159. html
    1) Get an environment variable (get environment variable)
    2) Get a global variable (get a global variable)
    3) Response body: contains string (check whether the response body contains a string)
    4) Response body: is equal to a string (Check whether the response body is equal to a string)
  4. Json assertion
    1) Write a JS statement: judge whether the city value in the returned result is correct
var variable name = JSON.parse(responseBody); tests["title"] = variable name. key name === "value"
 


var variable name = JSON.parse(responseBody); tests["title"] = variable name.list name[0].key name=== "value" to

 determine whether the value of the first element data in the data list is correct


2) Call postman method
      a, judge whether the city value in the returned result is correct


b. Determine whether the value of the first element data in the data list is correct


 5. Parameterized assertion: basic format: data. variable name


6. Test set and data drive
1. Use of test set: In order to manage the execution of interface requests more conveniently, the test operation can be completed through the postman test set (collection). Each test request can be regarded as a test case (testcase ),
collections can manage multiple test cases to execute at one time. Through save, the request can be saved to collections for use.


 2. Data-driven: When the Postman script needs to be run multiple times in a data-driven manner, the interface test data can be managed through csv files or json format files to facilitate use case management and execution.
    In the interface request, parameters are obtained using variable names, and then when creating data files, use these variable names to edit test data. In the test sandbox, parameters are read in the form of data.parameter name.


3. When multiple Postman scripts need to be run in a data-driven manner, the interface test data can be managed through csv files or json format files to facilitate use case management and execution.
    1) Create test data: After creating a csv format file, edit it through notepad++ or excel.
      Note: The file needs to use UTF-8 encoding. After creating the csv file, use the convert to UTF-8 encoding function in the encoding menu in notepad++ to convert the file to UTF-8 encoding for use.
         The first line in the file must be the variable name used by the interface request, and each subsequent line is filled with the variable value used in this execution.


2) Use the test data file
      Select the edited test data file in the data option in the collection runner, and preview can view the file preview to ensure that the read content of the file is correct.


7. Postman continuous integration
1. Install nodejs
    1) Download address: http://nodejs.cn/download/
    2) After installation, confirm that the directory where node is located has been added to the environment variable, otherwise add it manually. Confirm that the node environment has been successfully built through the node v and npm v commands in cmd


 2. Install newman: Execute the postman test script through newman and generate a test report
    1) npm install -g newman --registry= https://registry.npm.taobao.org


 2) newman -v to view the version and check whether the installation is successful
  3. Install the html report: npm install -g newman-reporter-html


 4. Newman executes the test
    1) Export the test set from Postman


 2) Newman executes the Json file exported by collection
      Enter the Json file name exported by newman run in the command line to run the test set through the Newman command line


5. Common Newman parameters
    1) -e, --environment:
     When using an environment variable file or url, first export the environment variable through the export function in the environment variable, and then use the following command to quote.


 2) -g, --global: use a global variable file or url
     similar to an environment variable, before using it, export the global variable file first, and then use g to specify the file to use
    3) -d, --iteration-data: specify the used data driven document


 4) -n: Specify the number of test set iterations


6. Newman generates test reports
    In the test reports provided by Newman, the commonly used formats include cli, json and html, and the format can be specified by the -r or --reporter command 1) The
    cli format is a report template presented on the cmd client , newman uses this format by default.
    2) The json format can export the report in json format, set it through -r json, and add the --reporter-json-export parameter to specify the path to generate the report.


    3) The html format can export the report in html format, set it through -r html, and add the --reporter-html-export parameter to specify the path to generate the report.
      Before using it, you need to complete the installation through npm install -g newman-reporter-html.


  7. Timing task execution script
    After realizing the command line operation of newman on the test set, you can write the ba script and set it as a windows timing task to complete the timing operation of the test script.
    1) Write bat scripts
    2) Set up timed tasks
     Right-click on the computer to manage, and create a timed task configuration and execution in the task scheduler in the pop-up menu.


8. Jenkins continuous integration
    1) After creating a free-style project, in the build trigger, configure the timing build option and specify the task to be executed regularly.
     The five parameters represent the cycle dimensions of the time-sharing day, month, and week respectively.


    2) When building, add a build step and choose to execute the windows batch command, and write the Newman command. Note
      : If Jenkins outputs Chinese garbled characters, add a variable JAVA_TOOL_OPTIONS value to Dfile.encoding=UTF 8 in the environment variable, restart Jenkins


Finally: In order to give back to the die-hard fans, I have compiled a complete software testing video learning tutorial for you. If you need it, you can get it for free【保证100%免费】

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.

Guess you like

Origin blog.csdn.net/jiangjunsss/article/details/131534996