Python interface automated testing (interface status)

  At the beginning of this section, we will introduce python interface automation testing. First, you need to set up a python development environment and download python from https://www.python.org/

Just install the version directly. It is recommended to download the python2.7.11 version. Of course, you can also download the latest version of python.

       Interface testing is a type of testing that tests the interfaces between system components. Interface testing is mainly used to detect interaction points between external systems and systems and between internal subsystems.

The focus of testing is to check the exchange, transmission and control management processes of data, as well as the mutual logical dependencies between systems, etc. This explanation comes from Baidu Encyclopedia.

       Of course, in order to better conduct interface testing, you need to understand the commonly used http status messages. For example, a successful request is 200 OK, but the http status message is other than this.

There are many other HTTP status messages. A simple understanding is that when the browser sends a request from the web server, the request may be successful, or the request may fail and return other errors.

error information, thereby returning HTTP status messages for various situations. For example, if you enter a search keyword on the Baidu homepage, successful search information may be returned, but the search may also fail.

Of course, this situation rarely occurs. After all, Baidu will not make such low-level errors. Common http status messages are listed below. This information comes from w3c.

website, see the following http status message:

    1xx: Information

information: describe:
100 Continue The server receives only part of the request, but once the server does not reject the request, the client should continue sending the rest of the request.
101 Switching Protocols Server conversion protocol: The server will comply with the client's request and convert it to another protocol.

    2xx: Success

information: describe:
200 OK Request successful (followed by response documents to GET and POST requests.)
201 Created The request is created and the new resource is created.
202 Accepted The request for processing was accepted, but processing was not completed.
203 Non-authoritative Information The document has been returned normally, but some response headers may be incorrect because a copy of the document was used.
204 No Content There are no new documents. The browser should continue to display the original document. This status code is useful if the user refreshes the page regularly and the servlet can determine that the user's document is current enough.
205 Reset Content There are no new documents. But the browser should reset what it displays. Used to force the browser to clear form input content.
206 Partial Content The client sends a GET request with a Range header and the server completes it.

    3xx: Redirect

information: describe:
300 Multiple Choices Multiple choices. Linked list. Users can select a link to reach their destination. A maximum of five addresses are allowed.
301 Moved Permanently The requested page has been moved to the new url.
302 Found The requested page has been temporarily moved to the new URL.
303 See Other The requested page can be found under another URL.
304 Not Modified The document was not modified as expected. The client has a buffered document and makes a conditional request (usually by providing an If-Modified-Since header to indicate that the client only wants documents that are newer than the specified date). The server tells the client that the original buffered document can continue to be used.
305 Use Proxy Documents requested by the client should be retrieved through the proxy server specified by the Location header.
306 Unused This code was used in a previous version. It is no longer in use, but the code is still retained.
307 Temporary Redirect The requested page has been temporarily moved to a new URL.

    4xx: Client error

information: describe:
400 Bad Request The server failed to understand the request.
401 Unauthorized The requested page requires a username and password.
402 Payment Required This code is not available yet.
403 Forbidden Access to the requested page is prohibited.
404 Not Found The server cannot find the requested page.
405 Method Not Allowed The method specified in the request is not allowed.
406 Not Acceptable The server-generated response was unacceptable to the client.
407 Proxy Authentication Required The user must first authenticate using a proxy server before the request will be processed.
408 Request Timeout The request exceeded the server's wait time.
409 Conflict The request could not be completed due to a conflict.
410 Gone The requested page is unavailable.
411 Length Required "Content-Length" is not defined. Without this content, the server will not accept the request.
412 Precondition Failed A precondition in the request was evaluated as failed by the server.
413 Request Entity Too Large The server will not accept the request because the requested entity is too large.
414 Request-url Too Long The server will not accept the request because the url is too long. This happens when a POST request is converted into a GET request with very long query information.
415 Unsupported Media Type The server will not accept the request because the media type is not supported.
416  The server cannot satisfy the Range header specified by the client in the request.
417 Expectation Failed

    5xx: Server error

information: describe:
500 Internal Server Error The request is not completed. The server encountered an unpredictable situation.
501 Not Implemented The request is not completed. The server does not support the requested functionality.
502 Bad Gateway The request is not completed. The server received an invalid response from the upstream server.
503 Service Unavailable The request is not completed. The server is temporarily overloaded or down.
504 Gateway Timeout Gateway timeout.
505 HTTP Version Not Supported The server does not support the HTTP protocol version specified in the request.

     For interface testing, it is generally divided into two situations, one based on http protocol and one based on web services protocol, but the most commonly used one is based on http protocol.

Interface testing, the most commonly used http methods are get and post, and of course put and delete requests. The process of interface testing is that the client (browser) sends a request to the server (service

Server side) requests a request. After the server gets the request, the response returns the response data to the client. The following describes several commonly used request methods in interface testing:

   GET: Get data from the specified resource

If you search for "selenium-python automated testing" on Baidu Reading, you will be returned to the "selenium-python automated testing" e-book written by me, requesting the address.

For: http://yuedu.baidu.com/search?word=selenium-python%E8%87%AA%E5%8A%A8%E5%8C%96%E6%

B5%8B%E8%AF%95, the method is GET, see the result returned after the request:

   POST: Data to be processed to the specified resource

For post requests, take Baidu login as an example to illustrate this process. The request address is: http://www.cyw.com/api/login/authorized.html,

The request method is POST, see the screenshot below:

   PUT: Upload the specified URL, usually a modification, which can be understood as an update in the database.

   DELETE: Delete the specified resource.

   在接口测试中,一般来说,post创建数据,get获取创建成功后的所有数据和指定的数据,put可以对创建成功后的数据

进行修改,delete是指定的资源。

   当然,接口自动化相比UI自动化来说,比较复杂,需要掌握的知识比较多,本人也是在学习中,感觉接口自动化测试,

首先需要了解http状态消息,http协议,http方法,当然还得了解python语言,毕竟接口自动化测试是以代码的方式进行,

并非工具的方式。

Python接口自动化测试零基础入门到精通(2023最新版)

Guess you like

Origin blog.csdn.net/ada4656/article/details/134209421