concept

What is the RobotFramework?

Robot Framework is a functional automation testing Framework written in Python. With good scalability, support keyword driven, can test multiple types of clients or interfaces at the same time, can carry out distributed test execution. It is mainly used for acceptance testing and Acceptance test-driven development (ATDD) with many rounds.

features

1. Save test cases as text files (TXT or TSV files), and use tabs to separate data. You can easily edit test cases using any text editor, or EXCEL. You can also create use cases in HTML format.

2. Support the use of variables in test cases, including IF statements and FOR loop statements.

3. The “label” function can be used to classify and selectively execute test cases.

4. Support keyword driven, data driven and behavior driven.

5. Using existing keywords, testers can create their own keywords to form higher-level behaviors.

6. Test execution reports and logs are in HTML format and easy to read.

7. The Robot Framework is not an automated testing tool like QTP. It is an automated testing framework, or an automated testing platform.

8. Provides a listening interface for testing execution events, and can customize the script in the interface. For example, a script in the “start_test” interface is executed before a use case is executed; After the use case execution is complete, the script in the “end_test” interface is executed. Testers can customize scripts for start_test and end_test interfaces.

9. Provides command line interface and OUTPUT in XML format. It can be combined with version management tools for continuous integration.

10.Robot Framework identifies and manipulates objects under test through test libraries. There are many own or third-party open source test libraries. For example, test the Web client using the “selenium2Library” library. In addition, you can also test Java client, Win32 client, SSH protocol character terminal and so on.

11. Testers can use Python and Java to create their own test libraries.

12. Provides remote test execution interface, which can carry out distributed test execution.

The above content is from Baidu Baike

RF Environment Installation

The installation of the environment requires version matching. The version configured on my computer is valid for testing.

1. Install PYTHon3.7.6 and configure environment variables.

2. Open the DOS window as administrator:

PIP install RobotFramework ==4.1

Uninstall to PIP Uninstall RobotFramework

3, install RIDE in DOS window, RIDE is a development tool for robotframework:

PIP install RobotFramework -ride==1.7.4.1

Uninstall: PIP uninstall RobotFramework -ride

The following dialog box will be displayed during installation. Do you want to create a desktop shortcut? Click Yes.

4. Install wxPython

Wxpython is a well-known GUI library for Python, and this must be installed because RIDE is developed on this library.

PIP install wxPython = = 4.0.4

Selenium2Library install

RF selenium Library can be regarded as the RF version of Selenium library, Selenium (WebDriver) can be considered as a set of Web-based specifications (API), so RF, APPIum and other testing tools can locate and operate pages based on this API.

pip install robotframework-selenium2library

6. Double-click the icon to open it, or enter ride. Py in the DOS window to open it, as shown below.

Problems encountered during installation

Flash back or startup error as shown below:

Will be.. Python37 \Lib\site-packages\robotide\application in the application.py fileself._initial_locale = wx.Locale(wx.LANGUAGE_ARABIC)toself._initial_locale = wx.Locale(wx.LANGUAGE_ENGLISH)

In case of other problems, please turn to warm-hearted netizens, most of the problems can be solved.

The use of RF

1. New projects

Click [File] → [New Project], fill in the Project name, path and type (File or folder) in the pop-up box, and create a New folder here.

2. Create test suites

Right-click on the folder and choose [New Suite]. In the dialog box that is displayed, fill in the name of the test Suite and select File as the type.

3. Create test cases

Right-click on the Test suite, choose [New Test Case], and fill in the name of the Test Case in the pop-up box.

4. Create a resource file

Right-click the folder, choose [New Resource], fill in the name in the pop-up box, and select TXT format. Generally, it stores service keyword resources and is the carrier of user-defined keywords. You can create user-defined keywords in resource files.

5. Page operation introduction

[1] Edit TAB page of test suite, as shown in the figure below1. Settings Settings2. Import: Import external files

Library: Import external Library. Black indicates success, red indicates failure.

Resource: Imports Resource files, such as service keywords.

3. Define internal variables

Adding variables, adding a list collection, and adding a dictionary are not used as much as the Library and Resource functions that import external files.

4. Metadata

[2] Test case page

RF common class library

1, standard library: do not need to install, direct use, RF comes with.

Buitini (Test Library)

Collections

DateTime (time library)

Screenshots

D:\software\python37\Lib\site-packages\robot\libraries

2. Extension library: The PIP installation library is required

Web test automation: SeleniumLibrary Selenium2Library, Selenium2Library for Java, etc.

API interface automation: RequestsLibrary

APP automated testing: AppiumLibrary

Installation method:

pip install robotframework-seleniumlibrary

pip install robotframework-requests

pip install robotframework-appiumlibrary

Location of the extension library: D: software\python37\Lib\site-packages\

Note: the package must be the same as the folder name, including case.

The use of RF common keywords

Shortcut:

1. Search keyword: F5

2. Autocomplete keyword: CTRL + Shift + space

When we encounter unfamiliar keywords, we can look for their use in the following page.

A profound

Comment 1. Print Log This is a print statement Comment 2. ${a} Set Variable 100 Log ${a} Comment 3. ${times} Get Time Log ${times} Comment 4 Sleep 3 Comment 5. String join ${STR} Catenate Oracle mysql SQLServer Log ${STR} Comment 6. Create List ${list1} Create List Function Test Automation Test performance test Log ${list1} @{list2} Create List Function test Automation test performance test Log Many @{list2} Comment 7. ${dic} Get Dictionary keys ${dic} Log ${dic} Comment ${dic ${keys} Comment 7.2 Obtain the Dictionary value ${values} Get Dictionary values ${dic} Log ${values} Comment 7.3 Use the key value ${key_value} Get From Dictionary ${dic} name Log ${key_value} Comment 8. ${random_number} Evaluate random.randint(1,101) modules=random Log ${random_number} ${times} Evaluate time.time() modules=time Log ${times} Comment 9. Import Library E:/pythonProject/test.py ${a} Evaluate int(10) ${b} Evaluate int(20) ${return_result} sum ${a} ${b} Log ${return_result} Comment 10. IF ${age} Set Variable 22 Run Keyword IF ${age}>30 Log ELSE IF 18<=${age}<=30 ELSE Log minor Comment 11. FOR FOR ${a} IN oracle mysql sqlServer Log ${a} END Comment FOR @{list3} Create List Oracle mysql Sqlserver FOR ${a} IN @{list3} Log ${a} END Comment FOR ${a} IN RANGE 1 11 Run Keyword If ${a}==5 Exit For Loop Log ${a} ENDCopy the code

The result of the above code:

20210831 08:28:34.827: INFO: This is a print statement 20210831 08:28:34.828: INFO: ${a} = 100 20210831 08:28:34.828: INFO: 100 20210831 08:28:34.829: INFO: ${times} = 2021-08-31 08:28:34 20210831 08:28:34.830: INFO: 2021-08-31 08:28:34 20210831 08:28:37.837: INFO: Slept 3 seconds 20210831 08:28:37.839: INFO: ${STR} = Oracle mysql SQLServer 20210831 08:28:37.839: INFO: Slept 3 seconds 20210831 08:28:37.839: INFO: Oracle Mysql SQLServer 20210831 08:28:37.840: INFO: ${list1} = [' Function Test ', 'Automated Test ',' Performance Test '] 20210831 08:28:37.840: INFO: [' functional Tests ', 'Automated Tests ',' Performance Tests '] 20210831 08:28:37.841: INFO: @ {list2} = [function test | | automatic performance test] 20210831 08:28:37. 841: INFO: functional test 20210831 08:28:37. 841: the INFO: Automatic Test 20210831 08:28:37.841: INFO: Performance test 20210831 08:28:37.842: INFO: ${dic} = {'name': 'zhang3 ', 'age': '18'} 20210831 08:28:37.843: INFO: {'name': 'zhang SAN ', 'age': '18'} 20210831 08:28:37.844: INFO: ${keys} = ['age', 'name'] 20210831 08:28:37.844: INFO: ['age', 'name'] 20210831 08:28:37.845: INFO: ${values} = ['18', 'zhang3 '] 20210831 08:28:37.846: INFO: ['18',' zhang3 '] 20210831 08:28:37.847: INFO: ${key_value} = Zhangsan 20210831 08:28:37.847: INFO: Zhangsan 20210831 08:28:37.848: INFO: ${random_number} = 101 20210831 08:28:37.848: INFO: 101 20210831 08:28:37.849: INFO: ${times} = 1630369717.848543 20210831 08:28:37.849: INFO: 1630369717.848543 20210831 08:28:37.859: INFO: ${a} = 10 20210831 08:28:37.860: INFO: ${b} = 20 20210831 08:28:37.860: INFO: ${return_result} = 30 20210831 08:28:37.861: INFO: 30 20210831 08:28:37.861: INFO: ${age} = 22 20210831 08:28:37.862:info: Oracle 20210831 08:28:37.864: INFO: Mysql 20210831 08:28:37.865: INFO: SQLServer 20210831 08:28:37.866: INFO: @ {list3} = [oracle | mysql | is essentially] 20210831 08:28:37. 867: INFO: oracle 20210831 08:28:37. 868: the INFO: Mysql 20210831 08:28:37.869: INFO: SQLServer 20210831 08:28:37.871:info: 1 20210831 08:28:37.872: INFO: 2 20210831 08:28:37.873:info :3 20210831 08:28:37.875:info: 4 20210831 08:28:37.876: INFO: Coinage for loop Altogether. Ending test: TestDemo.RF test 1.TestSuit1.TestCase1Copy the code

Prepare the environment for UI automation testing

PIP install RobotFramework – SeleniumLibrary PIP install RobotFramework – seleniumLibrary PIP install RobotFramework – seleniumLibrary

2. Download Chrome.

3, download chromedriver (note: chromedriver must be compatible with chrome), then put chromedriver.exe in python.

4, import SeleniumLibrary in RF test suite;

Keyword for browser operations

Comment Open Browser Open Browser https://www.baidu.com Chrome Comment Set Browser Implicit Wait 5 sleep 2 Comment Zooms in Maximize Browser Window sleep 2 Comment Set Window Size 1024 768 sleep 2 ${width} ${height} Get Window Size Sleep 2 Comment Return To the previous step Go Back sleep 2 Comment Redirects To the Page Go To https://www.baidu.com Comment Refresh the Reload Page sleep 2 Comment Obtain title ${title} Get title Log ${title} sleep 2 Comment Obtain path ${loc} Get Location Log ${loc} sleep 2 Comment obtain path ${loc} Get Location Log ${loc} sleep 2 Comment Close the BrowserCopy the code

Element localization

There are eight ways to locate elements: ID,name, link_TEXT,partial_link_text,xpath, CSS,class_name,tag_name

Prerequisite: The element must be unique

Here are some simple ways to locate by ID, name, link

In addition to the above positioning methods, there are two more powerful positioning methods: xpath and CSS

We now want to locate the following text box:

Xpath :(the elements located below are all part of the elements of baidu home page)

1. Locate by absolute path, which is rarely used.

2. Locate the file using a relative path: //form/span/input

3. Positioning by element attributes://input[@autocomplete="off"]or//input[@autocomplete="off" and @class="s_ipt"]

4. Positioning through some attributes://input[starts-with(@autocomplete,"of")]or//input[contains(@autocomplete,"of")]

//a[text()=” news “]

CSS :(the elements located below are part of the elements of baidu’s home page)

1. Locate by absolute path, which is rarely used.

2. Locate by ID or Class: #ID or.class

3. Positioning by element attributes:

Attribute positioning: Input [autoComplete =”off”]

Input [autoComplete =”off”][class=”s_ipt”]

4. Positioning through some attributes:

Input [autocomplete^=”of”)]

Input [autocomplete$=”ff”)]

Contains: input [autocomplete * = “of”)]

5. Locate by child elementdiv#s-top-left a:nth-child(3), id is the third A tag under S-top-left.

How do I deal with frame frames?

In practical projects, we will find that there is a frame frame in many cases, and elements in the frame cannot be directly positioned. They need to jump into the current frame first and then be positioned.

Jump into the frame shown above: Select frame menu-frame

If you want to locate elements that are not in the frame, you need to jump out of the current frame before performing the operation:Unselect Frame, as shown in the figure below:

Location of the drop-down list: The following toSelect From List By ValueFor example:

Locate one of a set of identical elements:

Processing warning box

There are three types of pop-up boxes: Alert, Confirm, and promptProcess the alert box in the figure aboveHandle Alert, if click “OK”, no parameters need to be passed. If click “Cancel”, the value will be:DISMISS.

The three-tier architecture of the project

1. What does three-tier architecture mean?

(1) Page element layer

(2) Business logic layer

(3) Test case layer

The business logic layer calls the page element layer, and the test case layer calls the business logic layer.

2, why stratification, where is the significance?

Implement centralized management of page elements, public methods, public data, business logic, and test cases.

Increase script reuse.

Increase script maintainability.

RF non-GUI mode (command line) running integrated with Jenkins

Command: pybot -d Path of test report Path of test case

Basic operation of Jenkins

1. Jenkins installation environment

(1) Install the JDK environment;

(2) Enter Jenkins official website, download the installation file, double click to install, and follow the steps;

2. Jenkins configuration

(1) Search for Robot Framework in plug-in Management and install it.(2) Create a free-style project(3) Set scheduled tasksCreate a Windows batch command5) Add Execute Groovy scriptSystem.setProperty("hudson.model.DirectoryBrowserSupport.CSP","") (6) Add post-construction operation steps

Afterword.

The basic features of the RobotFramework are introduced here and will be supplemented later.