A brief analysis of the use of RobotFramework tools | JD Logistics Technology Team

1 Introduction

In recent years, more and more companies have begun to design and lay out automated tests. Automation, as the name suggests, is a process that converts human-driven testing behavior into machine execution, and is often used in regression testing. On the market There are also many open source automated testing tools and theoretical knowledge. What I want to talk about today is RobotFramework;

I also came into contact with the RobotFramework tool by chance, and I thought the form was very novel, and I was attracted immediately. RobotFramework is a functional automation testing framework written in python. It has good scalability, supports keyword drive, can test multiple types of clients or interfaces at the same time, and can perform distributed test execution. Let’s get to the point!

2 Tool Analysis

1. After we install the tool, we will see a small icon on our desktop. We will rely on it when writing use cases in the future (any interested friends can privately chat with me about the installation process, so I won’t go into details here) ):

2. When we double-click this icon, we will enter a "pleasant" editing interface;

  • The project editing area will display the projects, use cases and keyword resources we have created; the keywords here can bring a lot of convenience to our future use cases, and are suitable for writing general logic, which is convenient for us to encounter when writing use cases. The same logic is used to call;
  • Use cases can be written through the script editing area and table editing area;
    • When the mouse is positioned on a certain case, the table editing area will be displayed: just like the script editing area, one is realized by writing scripts, and the other is realized by writing excel tables; -

    • Script editing area: Whether through table editing or script editing, the corresponding script will be generated in the script editing area.

  • When the mouse is positioned on the project, the case and Resource files we used to write the use cases will be displayed on the right side;
  • The use case execution area is displayed on the right side of the Run section. Through this section we can execute our use cases and view generated reports, logs, etc.;

3. Tool applicable scenarios:
Personally, I think it is more suitable for interface automation testing scenarios;

4. Tools support Jenkins platform integration.
Jenkins is a very powerful open source project for continuous integration and continuous delivery. It can handle almost any type of automatic build or continuous integration, so it must be able to be combined with RF for automated test deployment and scheduling. The specific implementation steps are roughly as follows:

  • Download jenkins
  • Add node
  • Install RF plug-in
  • Configure job to run tests

Note: This sharing of specific practices will not be carried out yet;

Advantages and Disadvantages Analysis

Advantage:

  • The automated testing process is simplified by using the Keyword Driven Testing (KDT) approach, making it easier for testers to create easy-to-read tests.
  • The test data syntax is simple and easy to use.
  • The ecosystem is rich. Consists of various general testing libraries and tools developed as independent projects.
  • Highly scalable.

Disadvantages:

  • Only supports python2. version;
  • The interface responds slowly and often freezes;
  • Sometimes exceptions occur when importing test libraries;

3 Keyword introduction

1. During the process of writing the case, some keywords were sorted out. Regarding variables, the details are as follows:

  • Set Suite Variable Variables set with this keyword are available everywhere within the scope of the currently executing test suite
  • Set Global Variable usage scope: Variables defined with this keyword can be used in all test suites.
  • Set Test Variable Usage Scope: Variables set using this keyword are available everywhere within the scope of the currently executing test case
  • Set Variable usage range: This keyword is mainly used to set scalar variables. Additionally, it can be used to convert a scalar variable containing a list into a list variable or multiple scalar variables. It is recommended to use Create List when creating a new list. Variables created with this keyword are only available within the scope in which they are created

2. Summary of excellibrary method:

  • Open Excel Open Excel file
  • Get Row Count Get the number of rows
  • Get Column Count Get the number of columns
  • Get Row Values ​​Get the values ​​of a certain row
  • Get Column Values ​​Get the value of a certain column
  • Read Cell Data By Coordinates Get value by column row number
  • Read Cell Data By Name Read cell data by name

3.Run Keyword If

  • Function explanation: If the given judgment condition is met, the given keyword will be executed.
  • Function structure example:
    • Run Keyword If other keywords to determine conditions
    • … ELSE IF other keywords for judgment conditions
    • … ELSE other keywords for judging conditions

4.Strip String removes leading and trailing whitespace characters
5.Remove String deletes the specified string

6. About time
${time} get current date #Get the current time
${time_stamp} convert date ${time} epoch #Convert to original timestamp
${time_stamp2} evaluate int(round(${time_stamp}*1000)) # Convert to millisecond timestamp

4 Case sharing

Based on our past experience, to put it simply, writing use cases can be roughly divided into several steps:

  • Create a project;
  • Add the case we want to implement under this project;
  • Realize this case and add the soul of the case;
  • Execute this case;
  • View case results;

good! So let’s try to write a use case based on the above ideas! Here I will take the warehousing order interface of our commonly used relatively simple international supply chain fulfillment scheduling system as an example:

1) First, let’s create a project: In File—>New Project, a pop-up window will appear. We can start it according to our own preferences. What we create here is the storage order. Let’s call it “testIn” for the time being. Don’t forget The most important thing is that we need to select Directory as the type;

In this way, our project is created;

2) Create case:

In Robot we first need to create a testSuite, because in Robot the cases are all hung under the Suite. Right-click on the project -> New Suite. Here you need to enter a name of the Suite. Here we call it "test_Instock";

After the Suite is created, we can create a case under the Suite. In test_Instock—>New Test Case, we can call the case name "Instock order issued successfully"

3. As of now, our preliminary creation work is over. We need to start writing the soul of the case. Here we can edit it directly in the form; the writing process is the same as the process of writing use cases in Python. We need Verification of interface information, input parameters, and return parameters;

Because we have many other similar interfaces, here we can implement the sending post request part and the verification return parameter part separately in the form of keywords: test Instock—>New User Keyword, create a keyword, and name it "Send post request" ” and “Verify return parameters”!
In this way, we can take a look again. The use case with keywords separated has changed from one large file to three small files, which makes it easier for us to view the use case process:

Keyword extraction case:

"Send post request" keyword part

"Verify return parameters" keyword part

When the soul of our case is fully realized, we can execute it and see, wow! The execution reported an error

Here we can see the obvious error report, so we don’t need to check it in the Report. If our error report cannot be clearly seen, we need to go to the Report to check the specific error information. The Report will mark the line where the error is reported, so It is convenient to locate the problem. Let’s get back to the topic. When we saw this error, we did not find the primary key of get current date, so let’s introduce this library (the specific explanation of the introduction of the library has already been mentioned above)

5. After the introduction is completed, we execute it again, and our case passes smoothly.

6. The following is the above use case content displayed in the script editor:

5 Summary of Problems

In the process of writing cases, we will encounter many problems of one kind or another. I have also summarized some for your reference:

1) When sending a post request, a type conversion error is reported:

A total of four parameters were requested and an error was reported. . .

Solution:
First try, put all parameters in a dictionary, No! :

The second attempt was to take out the parameters and assign values ​​separately, but found that it didn’t work! ! :

The third attempt is to write the value in string format to ${data}, and then assign ${data} to the data of the post request, but it doesn’t work! ! :

The fourth attempt is to directly assign the string value to the data of the post request, Emma, ​​passed:

2.cmd input pip list error:

Solution: Generally, the above prompt will appear in version 9.0.X, and the output format needs to be defined;

pip list —format=legacy error no longer exists

Author: JD Logistics Kang Yongchao

Source: JD Cloud Developer Community Ziyuanqishuo Tech Please indicate the source when reprinting

Broadcom announces the termination of the existing VMware partner program deepin-IDE version update, replacing the old look with a new look Zhou Hongyi: Hongmeng native will definitely succeed WAVE SUMMIT welcomes its tenth session, Wen Xinyiyan will have the latest disclosure! Yakult Company confirms that 95 G data was leaked The most popular license among programming languages ​​in 2023 "2023 China Open Source Developer Report" officially released Julia 1.10 officially released Fedora 40 plans to unify /usr/bin and /usr/sbin Rust 1.75.0 release
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4090830/blog/10456189