Charles grabs the package and turns it into interface automation test case

Posted by saami123 on Wed, 06 May 2020 16:46:24 +0200

We can get the json file to be parsed and convert it to json for saving by using Charles to grab the package and transfer the interface automation test case. So let's read it.

First of all, let's look at the last document,


  "config": {

  "name": "testcase description",

  "variables": {}


  "teststeps": [


  "name": "/openapi/api/v2",

  "request": {

  "url": "",

  "method": "POST",

  "headers": {

  "Content-Type": "application/json",

  "User-Agent": "PostmanRuntime/7.15.2",

  "Postman-Token": "8a096b5c-425a-4cfc-bf52-75ef38f5ba76"


  "json": {

  "reqType": 0,

  "perception": {

  "inputText": {

  "text": "Nearby hotels"


  "inputImage": {

  "url": "imageUrl"


  "selfInfo": {

  "location": {

  "city": "Beijing",

  "province": "Beijing",

  "street": "Information road"




  "userInfo": {

  "apiKey": "",

  "userId": ""




  "validate": [


  "eq": [






  "eq": [


  "text/plain; charset=UTF-8"







We have got the json file. We can read it out and use the json module to force the conversion directly. Because we use python, the parsing of json is the best. If for software testing, interface testing, automation testing, interview experience exchange. If you are interested, you can add software test exchange: 1085991341, and there will be technical exchanges with peers.

Let's read out the file first, and then load it with json.loads. The specific code is as follows

   import  json

  def openfile(filepath):



  for i in de.readlines():


  return json.loads(rslut)

In this way, we can get the dict after json transformation. Then we can parse the corresponding file according to the dictionary,

What we need to get is the interface, method, request header, parameter, assertion code, etc.

Then we can read the corresponding dictionary directly. Let me show you my ideas.

   def readjson(json):







  return interface,method,headers,parapme,assertcode

This returns all the data we want, and then we can read it directly and store it in our test cases. In today's platform, we usually store it in the database. Then we need to design the corresponding database for storage, and many of them can be put into Excel. We can directly add them to the corresponding Excel.

I hope the above content can help you. If you have any friends who have been helped, please comment

Topics: Programming JSON Database Excel Python