As a code novice, this is how I became an automation master!

Preface

robotframework (referred to as robot)

Robot is an automated testing tool that can implement automated interface testing and UI automated testing.

Its main features are:

  1. Completion of test cases driven by keyword
  2. The test case format can be txt/html, etc., in non-code form, and Chinese is supported .
  3. Implemented by python, open source.

There are two important concepts here that you need to master first:

Keywords, libraries

simply put:

The keyword is that the functions that have been implemented can be used directly.

The library is: keywords are stored in categories according to functional areas.

Let’s take the example of a shopping mall to illustrate. Please look at the following 2 pictures:




In the picture, the mall provides five major functional areas (libraries in robot). In each functional area, there are many specific functions (keywords in robot).

When we go shopping (ps: take your money with you), we go to different function libraries and use different functions according to our own needs.

Then, each specific function in the picture (such as H&M) is a function that has been implemented and can be used directly, that is, a keyword in Robot .

Suppose I enter this mall now, what I want to do is as follows:

Step 1: Go to the skin care products area (library) and buy MAC lipstick (use a certain function)

Step 2: Go to the dining area (library) to eat Mozi Barbecue (use a certain function)

Step 3: Go to the leisure area (library) cinema to watch Nezha: The Devil Boy Comes to the World (use a certain function)

What I want to do can be considered as a test case in robot. This use case is divided into three steps, each step uses an existing function.

To sum it up:

Arcade == RobotFramework

Catering/Leisure/Service/Skin Care Products/Accessories== Library

Chef Fei/Cinema/adidas/MAC == Keywords

Therefore, there are very rich libraries in robotframework, and each library has a corresponding set of keywords.

Robot test case = combine keywords according to business needs

Robot environment construction

1. python environment + robotframework third-party library:

Since robotframework is implemented in python and is a python third-party library, the python version needs to be installed.

robotframework perfectly supports python2 and python3. It is recommended to install python3.7+, the encoding processing is very friendly.

2. Install tools for writing use cases

There are many tools for writing robot use cases, including ride, notepad++, sublime, eclipse, etc. .

No matter which tool is used, the syntax for robot scripts is the same and can be opened in any other tool.

Friends who use ride, please note: the ride tool now also supports python2 and python3, but the compatibility needs to be investigated.

Personally, I prefer to use eclipse. The experience of keyword display, highlighting, automatic prompts, etc. is very friendly.
 

Robot - Easily implement automation use cases

Take web automation as an example to demonstrate the usage of robotframework. Use case writing tool used: eclipse+RED plug-in.

The automated web use cases to be implemented are as follows:

prefix

Open Google Chrome and visit: http://www.lemfix.com/

step

1. Click the login link in the upper right corner

Element positioning: //a[text()="Login"]

2. Enter username: XXXXX

Element positioning: id=user_login

3. Enter password: 123456789

Element positioning: id=user_password

4. Click the login button

Element positioning: //input[@name="commit"]

affirmation

Login failed, prompting that the account or password is incorrect.

Element positioning: id=navbar-user-menu

Question: How does robotframework realize web automation?

Answer: Keywords! !

In robotframework, when you want to do anything, the first thing that comes to mind is keywords.

Find the keywords for web page operations, and then use them.

Step one: Install SeleniumLibrary, which has the ability to automate web operations.

In robotframework, the **SeleniumLibrary (not included with robot, needs to be installed)** library provides operation keywords (functions) for web pages.

  1. 安装SeleniumLibrary:pip install --upgrade robotframework-seleniumlibrary

Step 2: Create a Robot project and introduce the SeleniumLibrary library.

1. Create a robot project:

In eclipse, File -> New -> Robot Project (if it is not displayed, go to the Other option to find it)

2) Create robot test cases:




3) Import SeleniumLibrary into the robot project (keywords can be used only after importing).

Note: The library name cannot be wrong and is case sensitive.

  1. Introduction method: In the robot script, in the settings area, introduce external resources. The script is as follows:
*** Settings ***

Library    SeleniumLibrary 
  1. When imported, there will be a red wavy line under the library name, as shown in the figure below. Select it and press Ctrl+1

  1. After pressing Ctrl +1, there will be a prompt as shown below, double-click:

  1. After the above operation, the red.xml file of the robot project will be automatically opened and the file can be saved.

  1. After saving successfully, you can see the existence of the third-party library in the robot project. The specific effect is shown in the figure below:

Step 3: Use the keywords in SeleniumLibrary to complete the web use case

Summarize

From the simple example above, you can see that using ready-made keywords, automated use case implementation is achieved without using a single line of code.

In robotframework, as long as you master the usage of keywords, you can do automated testing easily!

Of course, if we master more testing ideas and framework design ideas, we can better use this tool to complete automated testing work.

Doubt: Do I still need to learn code?

Since tools like robotframework can implement automated testing, is it not necessary to learn code?

the answer is negative.

  1. Tools are not omnipotent and always have limitations. Many times, its existing functions are not fully suitable for our test projects.
工具解决不了的问题,我们需要对它做扩展或另行处理。还好,robot本身支持python/java语言对它做扩展。
  1. If you only use tools, the limitations of the tools are your limitations. Master the code and you can do more.
工作当中,除了写用例之外,我们还要完成领导的各个小需求。比如自动收集数据?比如定制化的报告?
同时,也需要各种小手段来提高测试效率。
  1. In the future, what about developing a universal testing platform that can adapt to company testing projects? ?

Therefore, you need to know the tools, and even more so, you need to know the code.

Guess you like

Origin blog.csdn.net/a448335587/article/details/132630132