Postman interface test learning


foreword

Advantages of postman tool: It can quickly construct requests and provide a comparison function of response results, which is convenient for writing test cases. Put the written test cases in the test set and batch test cases. You can set the number of iterations, set environment variables, and view test results.


1. Send a get request

1. New request

get : get resource
post : create/update resource
put : update resource
delete : delete resource

2. Fill in the request method get , fill in the request url (which host, which resource)

insert image description here

3. Carry request parameters (fill in Params): para_key = para_value , view in args

insert image description here

  • url : Uniform Resource Locator, used to specify the location of the resource. Composition: Protocol type: https, service address, port: http(80), https(443), path, request parameter: & connection
  • JSON: JavaScript Object Notation, is a lightweight data interchange format that can be read by any programming language and passed as a data format.
    • struct:
      object format:
      { "key1": "value1", "key2": "value2" } array format: [ "item1", "item2" ] contains types: string, numeric, boolean







2. Send a post request

1. Add form format request parameters body —>form data —>Add parameters, view in form

insert image description here

2. Add the json format request parameter body —> raw (original format) —> JSON , and the test in the back is selected as json, and view it in json

insert image description here

3. Add the file format request parameter body—>doem-data—>file , view in file

insert image description here

3. Header information

1. Universal head

  • date : the time when the message was sent
  • pragma: whether to cache or not, including implementation-specific instructions, commonly used: pragma: no-cache
  • connection: connection status
  • cache-control: specifies the caching mechanism followed by requests and responses

2. Request header

  • accept : information that tells the web server what medium it accepts
  • authorization: authorization certificate for http authorization
  • user-agent: Details of the type of browser the http client is running

3. Response header

  • age : estimated time from origin server to proxy cache formation, /s , non-negative
  • location: the new address to redirect to
  • server: web server software name
  • refresh: Indicates how long after the browser refreshes the document, /s
  • retry-after: if the entity is temporarily unavailable, notify the client to try again after the specified time
  • vary: tell downstream proxies whether to use cached responses or request from origin servers
  • warning: warns about possible problems with the entity
  • www - authenticate: the authorization method that the client requesting entity should use

4. Entity head

  • content - type: request information corresponding to the entity;

  • content-encoding: the encoding method of the document
    insert image description here

  • Set cookie request, store, add, delete, modify
    insert image description here
    insert image description here

5. Add assertions

  • Assertion: It is to judge whether the actual result is consistent with the expected result; if it is consistent, it will return pass; if it is inconsistent, it will return fall
  • Assertion idea: The interface request is successful, and the business logic is verified
  • Add assertion: (Tests panel)
    • Validation response status code
      insert image description here
      insert image description here

    • Verify that the response contains content
      insert image description here
      insert image description here

    • Verify that the response header information contains a certain key
      insert image description here

    • Verify that the response time is less than a certain value
      insert image description here

6. Create environment variables and reference variables

  • postman can set multiple sets of environment variables, and each environment can have multiple environment variables

  • Environment variable settings, you can switch the environment
    

  • Postman can only set one set of global variables, which apply to the entire postman.
    insert image description here
    insert image description here

  • Global variable reference: { {variable name}}

7. Create and run the test set

1. Add a request to the test set

  • The already written interface use cases are saved to the test set
    insert image description here
    insert image description here

  • Run the test set
    insert image description here

    • iterations: number of use case iterations, delay: execution interval ms,

8. Data-driven

1. What is data-driven? Write with assertions

  • The same test script uses different test data, and the change of the data drives the execution of the automated test, which eventually leads to the change of the test result.

  • Data save format:

    • csv:
      name,age,expect
      cc,18,cc
      cao,19,cao
    • json:
      insert image description here
  • post request:
    insert image description here

9. Use dynamic parameters

  • Make the value different for each request,

1. Timestamp: { {$timestamp}}

2. Random number: { {$randomInt}}, generate 1~1000 random integers

3. Random string: { {$guid}}

4. Random Email: { {$randomEmail}}

5. Random Username: { {$randomUserName}}, English

insert image description here

10. Interface Association

  • The next interface will use the response data of the previous interface,

1. Return the token value in the post

insert image description here

2. Write a script in test to extract the token value in the response, and store the token value in an environment variable or global variable

insert image description here

3. Associate the interface call variable (add token to the header information of the next post)

insert image description here

Guess you like

Origin blog.csdn.net/ccyzq/article/details/123250585