Postman Advanced Chapter (2)-console console (view interface logs, debug code)

After entering the postman advanced chapter, sometimes you need to use the console console to view the log. In the previous article in this series, getting started with pre-request script and implementing parameters using random numbers when debugging the script, we briefly introduced the console entrance and viewing the script print log. , but the role of console goes beyond that, which will be introduced in detail in this article.

1. How to open the console

  1. Click the "console" button at the bottom , and the console will expand in the lower part of the postman interface.
    Bottom "console" button
  2. On the top menu bar, select "view" , then select "show Postman Console" in the drop-down menu or use the shortcut Alt+Ctrl+C. The console opened from this entrance is in window mode.
    Insert image description here
    console window

2. Introduction to the functions of each button on the console

	窗口模式与底部展开模式下的console功能基本相同,按钮介绍以底部展开模式下的console为例。

1. Switch window mode

  • The button is located in the upper right corner of the console. There is no button to switch the console in window mode. Only consoles expanded from the bottom "console" button have this button.
  • Click on the console window.
    Switch to windowed mode

    2. Log clear button

  • After clicking, clear the console and print the log.
    Log clear button

3. Set the log display level

  • Click "All Logs" in the upper right corner to expand all log levels. From top to bottom, they are "Log", "Info", "Warning", and "Error". All are selected by default. If you uncheck the log level, the console will also filter the logs of the corresponding level accordingly.
    (The second half of the article will introduce how to output different levels of logs to the console in the script)
    Set log display level

4. Display timestamp

  • Click the "···" button in the upper right corner and check "Show timestamps". All logs (including logs that have been printed before checking) will display the printing time.
    Show timestamp

4. Hide interface requests

  • Each postman request will print the interface log on the console, which contains complete information about this interface.
    Interface logs
  • But sometimes you just want to focus on watching the script log printing, you can choose to hide the interface request log.
  • Click the "···" button in the upper right corner and check "Hide Network". All interface logs (including interface logs that have been printed before checking) will be hidden.
    Hide interface request

3. Log content printed by the console

1. Interface request log

  • It is mentioned in the hidden interface log above: Postman will print the interface log on the console every time it makes a request, which contains complete information about this interface.
    Interface request log
  • Because when requesting the interface in postman, you only need to fill in part of the information. The remaining information is automatically completed by postman.
  • For example: when setting the URL, you can leave it blank and use the http protocol. At this time, postman will automatically add "http://" when making a request, but this will not be reflected in the interface editing interface. At this time, you can use the log View the specific information requested by the interface.
  • Because the interface log printed in the console is the final parameter when postman requests the interface, you can also see the result after the script modifies the interface parameters here.
    postman will automatically add http

-Click "Show law log" in the upper right corner and the log will be displayed in source format. Click "Show pretty log" again to switch back to the original style.
Show law log

-If the interface content is too long, the prompt "The console only shows bodies smaller than 10 KB inline. To view the complete body, inspect it by clicking" will be displayed, such as "Response Body" in the picture above -Click the button as shown in the picture,
postman A page will pop up to display the excessively long content separately.
Insert image description here
Insert image description here

2. Script log printing

  • After the pre-request script was introduced in the previous article in this series , a Test Script will be introduced. These two scripts can output logs to the console no matter where they are run.
  • The code to enter the log is as follows:
console.log("这是log级别的日志")
console.info("这是info级别的日志")
console.warn("这是warning级别的日志")
console.error("这是error级别的日志")

The output style of the log is as follows:
Log output style
There is also a debug level log in console mode, and this level of log will not be output on the console.

console.debug("这是debug级别的日志")

debug level logs

Postman series article directory:
https://blog.csdn.net/weixin_40883833/article/details/126452017
———————————————————————————— ——————
The sample files used in the postman series of articles have been uploaded to the public account I operate [Essential Skills for Software Testing]
Insert image description here
If necessary, you can click on the article to issue a QR code and go to get it~
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_40883833/article/details/126559118