Python interface automation (1)--what is an interface, interface advantages, types (detailed explanation)

Introduction

  I often hear people talk about interface testing and interface testing automation, but how much do you know about interfaces? Do you know what an interface is? What is it used for, and what should you pay attention to when testing? Frankly speaking, the author was not very clear before. Next, let's look at the definition of the interface.

definition 

       An interface generally refers to an abstraction that an entity provides itself to the outside world (it can be another entity), which is used to separate the external communication method from the internal operation, so that it can be modified internally without affecting the way other external entities interact with it.

  The interface between humans and information machines such as computers or between humans and programs is called a user interface. The interface between hardware components of information machines such as computers is called hardware interface. The interface between software components of information machines such as computers is called software interface.

  In computing, an interface is a shared boundary where two independent components of a computer system exchange information. This exchange can occur between computer software and hardware, external devices, or the person performing the operation, or a combination of them.

If you want to learn interface automation testing, here I recommend a set of videos for you. This video can be said to be the number one interface automation testing tutorial on the entire network at station B. At the same time, the number of online users has reached 1,000, and there are notes to collect and use. Technical exchanges of various great gods: click on the card at the bottom of the article

The most detailed collection of practical tutorials for automated testing of Python interfaces (the latest version in actual combat) taught by station B Including: 1. Why interface automation is needed, 2. The overall view of interface automation requests, 3. Interface automation, interface combat, etc. For more exciting videos, please pay attention to the UP account. https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337.search-card.all.click

Advantages of the interface

  1. Normative

  The interface is the specification. In the whole system design, many layers are involved. In order to make the calls between layers transparent, you only need to know the interface, and do your specific things according to this interface, and then it can be integrated into the whole system.

  There are many examples in life, such as plugs and sockets. There are standard specifications that tell you how many pins a plug should have, how many holes a socket should have, etc. Companies that make plugs and sockets make plugs and sockets according to this specification, and You don't need to go all over the world to try out a plug to see if it's right.

  2. Expansibility

  During the project development process, due to the frequent changes of customer needs, if the interface is not used, then we must constantly rewrite the existing business code. Rewriting the code may generate new bugs, and rewriting the code will also affect the class that calls the business, and may all need to be modified, affecting the stability of the system itself. In the end, the code may be messy and difficult to read,

  The person who takes over later cannot understand the code, and the maintenance work of the system is getting heavier and heavier, which may eventually lead to the failure of the project.

  3. The interface is a business logic in the project. Interface-oriented programming is to first extract the customer's business as an interface. The specific implementation of the business is done through the implementation class of the interface. When the customer's requirements change, it is only necessary to write a new implementation class of the business logic without rewriting the existing code, reducing the impact on the system. This makes the project more scalable.

Common Interface Types

  Interface refers to the interaction points between external systems and systems and between internal subsystems. Including external interface, internal interface, internal interface includes: upper layer service and lower layer service interface, same level interface.

  Common web interfaces: one is the http protocol interface, and the other is the web service interface (such as soup, rmi, rpc protocol). This article mainly introduces the http request interface.

  Common http request methods include: get (check), post (increase), in addition to put (change), delete (delete), etc. The two most commonly seen in daily work are get and post.

   GET: GET can be said to be the most common. Its essence is to send a request to obtain a certain resource on the server . Resources are returned to the client through a set of HTTP headers and rendering data (such as HTML text, or pictures or videos, etc.). Rendering data is never included in a GET request.

   POST: Submit data to the server. This method is widely used, and almost all commit operations are done by it. It is used to submit data to the specified resource for processing requests (for example: submitting forms and uploading files). The data package is included in the request body. The post request may result in the creation of new resources or the modification of existing resources.

   PUT: This method is relatively rare. HTML forms don't support this either. In essence, PUT and POST are very similar in that they both send data to the server, but there is an important difference between them. PUT usually specifies the storage location of resources, while POST does not. The storage location of POST data is determined by the server itself. The data sent by the client to the server replaces the content of the specified document.

   For example: such as a URL for submitting blog posts, /addBlog. If you use PUT, the submitted URL will be like this "/addBlog/ abc123 ", where abc123 is the address of this blog post. And if POST is used, the address will be notified to the client by the server after submission. Most blogs are like this these days. Obviously, the purposes of PUT and POST are different. Which one to use also depends on the current business scenario.

  DELETE: Delete a resource. Basically, this is rare, but there are still some places such as Amazon 's S3 cloud service that use this method to delete resources.

1) get interface

Format: The request number parameter is written after the URL, connected with "?", and connected with "&" between multiple parameters. For example: https://api.douban.com/v2/book/search?q='', this is a development API for Douban to query book information, q='', the parameters in the single quotes are the query parameters, such as querying " For information about the book The Little Prince, then q='Little Prince', use the postman tool to test it out, as shown in the figure below:

Scenario: The get interface is used to obtain information, mostly used to query data, such as the list query function, click the query button to call a get interface, and then return the information

Features: 1) The amount of requested data is small, 2) The parameters are exposed in the url address, so there are security risks

2) post interface

Description: Submit data (such as submitting a form, uploading a file) to the specified resource location to make a request, and post requests may lead to the creation of new resources

Scenario: Functions such as registration, uploading, and posting, such as users collecting, writing notes, and posting comments on a book on Douban.com

Features: Large amount of requested data, high security

For example, Douban's open API for posting comments, see the figure below:

3) put interface

Description: The put request is used to upload the latest content to the specified resource location

Scenario: For example, the user modifies the collection of a book, revises a note or revises a comment on the Douban website

For example, Douban's open API for modifying comments, see the figure below:

4) delete interface

Description: Request the server to delete the resource identified by the url in the request

Scenario: For example, the user cancels the collection of a book, deletes a note or deletes a comment on the Douban website

For example, Douban's open API for deleting comments, see the figure below:

Uncommon interface types (just understand)

    Uncommon HTTP request methods include: head, connect, options, and trace.

    head: HEAD is essentially the same as GET, the difference is that HEAD does not contain presentation data, but only HTTP header information. In other words, there is no specific content in the returned response, only the header is obtained. Some people may think that this method is useless, but it is not. Imagine a business scenario: To determine whether a certain resource exists, we usually use GET, but here the meaning of HEAD is more clear.

    connect: Reserved in the HTTP/1.1 protocol for a proxy server that can change the connection to a pipeline.

    options: This method is interesting, but rarely used. It is used to get the methods supported by the current URL. If the request is successful, it will include a header named "Allow" in the HTTP header, and the value is the supported method, such as "GET, POST". Allows clients to view server performance.

    trace: Echo the requests received by the server, mainly for testing and diagnosis.

Appendix (difference between get and post)

This question is often asked in interviews. To put it simply, we can go back to this difference from three aspects: method, size, security

1). Way

The method refers to the way the parameters are passed in. The GET method generally refers to obtaining data on the server. The parameters are directly followed by the URL and can be directly placed in the browser address bar. For example, the GET method is used to log in. The POST method means that the client submits form data to the server, so POST is submitted through a form. For example, the registration of new users on your web page, questionnaires and answers use the POST method.

2). Size

We already know that GET is directly entered in the address bar of the browser. Due to the limitation of the browser, the length of the entire URL can be very long, but it cannot exceed the size limit of 2049KB, and this POST has no size limit.

3). Security

Since the parameters of GET are directly spliced ​​in the address bar of the browser and exposed to the Internet, it is definitely not safe. POST is submitted through form data, which is relatively safer than the GET method.

Guess you like

Origin blog.csdn.net/caixiangting/article/details/131290707