Tool application: Robot Framework->Test protocol-level interfaces

Experiment Introduction

This section of the experiment mainly explains how to use Robot Framework combined with commonly used keywords to complete the development of automated test scripts for protocol-level interfaces for the “Requirement Proposal” module in the Agileone system.

Purpose of the experiment

(1) Master the common keywords and usage of RF’s Requests library.

(2) Be able to skillfully use the Requests library to complete the development of interface-level automated test scripts.

Experimental Process

  1. Common keywords in the Requests library

Let’s first understand the common keywords of the Requests library:

(1) Create Session: Create an HTTP session connected to the server-side URL address.

(2) Get Request: Send a GET request, which also has a built-in keyword called “Get”, which is no longer recommended by the system.

(3) Post Request: Send a POST request. Similarly, it is no longer recommended to use the “Post” keyword.

(4) To JSon: Convert the response content into JSON data format.

(5) Delete All Sessions: Clear the current session.

What needs special attention here is that RF has automatically helped us maintain the Session and Cookie between the server and the client. We only need to specify an alias (Alias) for this connection when creating the session, and process each subsequent request. In the process, this alias is used to establish a relationship with the current Session.

Below, we still demonstrate its usage by logging in to Agileone and adding and modifying the demand proposal module.

2. First implement a simple GET request

Let’s explain the above code:

(1) Line 1: Create Session, used to create a connection session with the corresponding server address, and set the session alias to “agileone” for subsequent requests to maintain the session state.

(2) Line 2: Send a GET request to the home page and assign the response to the variable ${response}.

(3) Line 3: Make a simple assertion on the homepage. Here we use Python’s decode function to decode the response content. At the same time, to obtain the content of the response, you need to use the ${response.content} attribute instead of using ${response} directly. This is something that needs attention.

(4) Line 4: Output the response content to the log information for easy viewing during debugging. The reason is the same as when we use the System.out.println() method in Java to output content to the Console terminal.

Now I have also found a lot of testing friends and created a communication group to share technology, sharing a lot of technical documents and video tutorials we collected.
If you don’t want to experience the feeling of not being able to find resources when studying on your own, having no one to answer your questions, and persisting for a few days before giving up.
You can join us to communicate. And there are many technical experts who have made certain achievements in automation, performance, security, test development, etc.
Share their experience, and also share many live lectures and technical salons
You can learn for free! Focus on it! Open source! ! !
QQ group number: 110685036

3. Implement Agileone’s login and assertion

To implement Agileone login, the core thing is of course to send a POST request. In the RF framework, we use the “Post Request” keyword to send POST requests. There are three core parameters required to implement POST request processing:

(1) The Content-Type field value of the POST request must be customized in the header: application/x-www-form-urlencoded.

(2) The correct server-side receiving address for POST requests must be specified.

(3) The body data of the POST request must be explicitly specified.

For the specification of the header field and request body, we can directly specify it as a string, such as “username=admin & password=123456”, or we can use the keyword “Create Dictionary” to create a dictionary object and Each field is assigned a value individually, but the final result is still in string format. Other operations are similar to the processing of GET requests. Just get the response and process it. Now let’s take a look at how to use the “Post Request” keyword to implement login and assertion in the Agileone system:

The specific script is as follows:

Create Session agileone http://localhost/agileone
${headers} Create Dictionary Content-Type=application/x-www-form-urlencoded
${loginData} Create Dictionary username=admin password=admin savelogin=true
${respLogin} Post Request agileone /index.php/common/login data=${loginData} headers=${headers}
Should Contain ${respLogin.content} successful
Run Keyword If u'${respLogin.content}'==u'successful' Log Login successful...
...ELSE Log User login failed...

In the above code, we use “Create Dictionary” to create the dictionary data and assign it to the variables ${headers} and ${loginData}. Finally, when sending the POST request, we assign it to the parameters data and headers for use in the POST request. Although the dictionary data we see is processed field by field, in the end, the system will construct a complete request body, which is the same as the result if we directly write the string processing. Finally, we used RF’s own judgment statements “Run Keyword If” and “… ELSE” to implement a simple assertion.

4. Testing of new functions of requirement proposals

After we have completed the login operation, we are already very familiar with the usage of “Post Request”, so now we use native strings to send the request header and request body, and continue to use random numbers to generate random demand proposal titles. and content. The final code is as follows:

Create Session agileone http://localhost/agileone
${headers} Create Dictionary
Content-Type=application/x-www-form-urlencoded
${loginData} Create Dictionary username=admin password=admin
savelogin=true
${respLogin} Post Request agileone /index.php/common/login
data=${loginData} headers=${headers}
${random} Evaluate random.randint(10000,99999) random
${addData} Set Variable type=Requirement & amp;importance=Medium
 & amp;headline=This is the requirement title-${random}
 & amp;content=This is the required content-${random} & amp; & amp;processresult=
${respAdd} Post Request agileone /index.php/proposal/add data=${addData} headers=${headers}
Should Match Regexp ${respAdd.content} \d + 

Thinking Exercise

(1) If there is anything worthy of improvement in the above script, please try to optimize it.

(2) Please complete the automated test development of Agileone or other systems based on the above script examples.

Finally, I would like to thank everyone who has read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!

Software testing interview document

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.