How to test the data sent by the interface in xml format?

what is xml

xml is a language very similar to html, which adopts a certain format to display data. for example:
insert image description here

This example very vividly indicates:

Here is a note
The note is for you
The note is from me
The title is: Reminder and
the text is: See you at 8 o'clock tonight

The difference between xml and html

The original intention of xml design is to transmit data, and the focus is on data;
the original intention of html design is to display data, and the focus is on display;
the combination of html and css can show very beautiful effects, and xml does not aim at this.

Why is there xml in the interface?

The role of xml is very similar to json. Through json, the role of xml can be replaced:
insert image description here

Previously, interfaces usually used xml to transfer data. Now, most interfaces use json for data transfer, and xml has been neglected. The main reasons are:

The data transmission volume of json is small, and various attributes are often used in xml, and there are many redundant information;

json supports common formats such as numbers, Booleans, null, arrays, and objects, and xml is all text;
json parsing is more convenient.
However, there are still some companies that use xml for their interfaces, such as the well-known WeChat, many of which still use xml. The reason is that xml still has some advantages in some specific areas:

Readability has a slight advantage;
for UI pages, it is more convenient to use attributes to transmit page data, such as
Android applications.
historical advantage. XML developed earlier than json, and many experienced programmers prefer xml, and Java
programmers tend to like xml (now there are very few). Many APIs of WeChat still use xml,
perhaps for these reasons.
The difference between xml and json, in the final analysis, is that they express data in different ways. xml uses a tree structure, and json corresponds to a hash map.

Use tools to test the xml data interface
Sending data in xml format through the interface is almost the same as sending json, just change the format to xml. Use the postman interface testing tool to send the following xml data to the interface https://httpbin.org/post:
insert image description here
Fill in the postman data:
insert image description here

You can view the sent data by capturing packets with fiddler:

insert image description here
View the returned results through postman:
insert image description here

From the example above:

Sending in xml format only needs to modify the format of the request header.
The format of the request header is Content-Type: application/xml.
Use the python programming language to test the xml data interface.

Using the requests library of the python language can easily send data in xml format, just change the request header format to application/xml:
insert image description here

The xml data is stored in the file.
If the test data is not passed directly in the code, but stored in the form of a file, use the open function in python to read it directly.

Corresponding code:
insert image description here


              [The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled]


1. From entry to mastery of Python programming

2. Interface automation project actual combat 

3. Actual Combat of Web Automation Project


4. Actual Combat of App Automation Project 

5. Resume of first-tier manufacturers


6. Test and develop DevOps system 

7. Commonly used automated testing tools

Eight, JMeter performance test 

9. Summary (little surprise at the end)

life is long so add oil. Every effort will not be let down, as long as you persevere, there will be rewards in the end. Cherish your time and pursue your dreams. Don't forget the original intention, forge ahead. Your future is in your hands!

Life is short, time is precious, we cannot predict what will happen in the future, but we can grasp the present moment. Cherish every day and work hard to make yourself stronger and better. Firm belief, persistent pursuit, success will eventually belong to you!

Only by constantly challenging yourself can you constantly surpass yourself. Persist in pursuing your dreams and move forward bravely, and you will find that the process of struggle is so beautiful and worthwhile. Believe in yourself, you can do it! 

Guess you like

Origin blog.csdn.net/nhb687095/article/details/131937706