Automated testing - RobotFramework

Keywords: Python Django jmeter Robot

Automated testing - RobotFramework framework

brief introduction

Is a general open source automation framework for acceptance testing, acceptance test driven development (ATDD) and robotic process automation (RPA). It has an easy-to-use table test data syntax and uses a keyword driven test method. Its test function can be extended through the test library implemented in Python or Java. Users can use the same syntax as creating test cases to create new higher-level keywords from existing keywords [keyword driven]

Update Log
- 15 Oct 2021  v4.1.2
- 08 Sep 2021  v4.1.1
- 19 Jul 2021  v4.1
- 25 May 2021  v4.0.3
- 11 May 2021  v4.0.2
- 09 Apr 2021  v4.0.1
- 11 Mar 2021  v4.0
- 02 Sep 2020  v3.2.2
- 30 Jul 2020  v3.2.1
.......
Related links
# Before selecting a frame:

That frame works well?
Which frame is popular?
Which framework is more suitable for your current team?
What about the framework ecosystem? Is the documentation comprehensive? Can you get some help when you encounter problems?
Is the framework flexible? Support custom scenarios?
Is there a certain threshold for the use of the frame?

# Go back to the starting point and choose the best framework suitable for your team with your original intention (to solve the current problems and future planning)

# (all the bottom layers of the framework refer to the basic unit test pieces: unintest / pytest / TestNG / JUnit. If the wheels must be self-made, the design / cycle / universality / stability of the wheels should be considered.)

# The following is the current situation of my current use of the RobotFramework framework, which involves secondary development. First, I will briefly introduce it here
# Reasons for secondary development:

1.Associate test cases with version iteration tests: by creating test plans->Check the test case method to be covered for association
2.Make automated test cases easy to refer to/Browsing is more intuitive than abstract scripting
3.By traditional jenkins Migrate to the platform in an integrated manner. (convenient for unified management of multiple projects)/Use case filtering/Multi environment configuration file switching, etc.)
  • test plan
  • Use case management
  • Use case details
Well, no more nonsense. Let's get to the subject

Framework comparison - Github (ecosystem / framework popularity / framework update frequency, etc.)
# RobotFramework
# Httprunner
# Jmeter
Frame comparison - function
frameLatest versiondevelopment language Support languageContinuous integrationDevelopment difficultyperformance testing Data separationPromotion thresholdOther features
Robot Framework4.1.2pythonpython/javayeshighI won't support itsupportlowThe built-in wx GUI can support interface or command operation and web UI automation selenium library
HttpRunner3.1.6pythonpythonyesinsupportsupporthighScripted, complete and easy to read report output
Jmeter5.4.1javajavayeshighsupportsupportlowMore inclined to interface performance; It is difficult to maintain and manage use cases for functional testing

Robot Framework - modular architecture

Robot Framework - source code structure

Robot framework environment installation

Because python2.7 has stopped updating and is no longer under maintenance, most relevant open source projects and libraries no longer support python2.x, so Python 3.6 + robot framework 3.2.2 is used to build the environment here

Start:

  • pip install -r requirements.txt

requirements.txt

requests
robotframework==3.2.2
Pypubsub==3.3.0
wxPython==4.0.3
robotframework-ride
robotframework-requests

Robot framework common library

  • Standard library
  • Builtin: contains frequently needed keywords. No import required
  • Dialogs: provides a way to pause test execution and input from the user.
  • Collections: provides a set of keyword processing Python lists and dictionaries.
  • Other OperatingSystem, Remote, String, Telnet
  • expanded memory bank
  • Android library: all test libraries required for android automation. Calabash Android is used internally
  • iOS library: all test libraries required for iOS automation. Calabash iOS service is used internally
  • appium Library: Android and iOS test libraries. appium is used internally
  • HTTP library (Requests): a library for HTTP testing that uses the request tool internally
  • Selenium 2 Library: Web test library using selenium 2
  • Other

Common keywords of Robot framework

  • Set Variable creates a string variable (BuiltIn Library)
  • Create Dictionary create dictionary variable (BuiltIn Library)
  • Create List variable (BuiltIn Library)
  • Get Length get the length of the list (BuiltIn Library)
  • Should Be Equal As Strings assertion strings (BuiltIn Library)
  • should match (BuiltIn Library)
  • Log printing (BuiltIn Library)

Common library documents

Robot framework custom keywords

# Custom library: naming rules: the file name must be consistent with the class name  
# User defined keyword: it complies with pep8 specification and can be called by keyword. The underscore can be omitted, such as HTTP_ get   -> case : http get

> simple: Customize a keyword: http get
import requests
def http_get(url, data):
    """
    http get Get specified url Content and compare with the expected results
    :param url:
    :param data Expected results
    """
    response = requests.get(url=url)
    if response.status_code == 200:
        if response.text == data:
            print('The results are the same')
        else:
            raise Exception('Different results, original data:%s  Validation data:%s' % (response.text, data))
    else:
        raise Exception('request was aborted code: %s Details:%s' % (response.status_code, url))

Use case writing

# There are two ways to write use cases
1.Built in frame GUI Editor writing Ride (Use the same feeling jemter)
2.Editor writing Pycharm/Idea    (rf The government provides a variety of support plug-ins plugs: Robot Framework support/Run Robot Framework TestCase Etc.)


# It is recommended to use the editor to write use cases (faster and more convenient)

Use case writing - > editor
*** Settings ***
Library           ../../rf/content_keyword.py  # Custom library
Library           ../../rf/db_operate.py    # Custom library
Library           ../../rf/source_keyword.py    # Custom library

# Use case set description
Documentation   xxx channel-Order splitting logic check

# Data cleaning
Suite Setup        CLEAR FILES    # clear

*** Variables ***

*** Test Cases ***
# xx channel order splitting logic check
# 1. Order splitting - inventory meets the scenario
# 2. Order lot number setting check
# 3. Order splitting - receipt write check
# 4. Order status synchronization check
# xxx

Check order split-The inventory is satisfied
    [Documentation]    Check order split-The inventory meets the scenario
    #Custom variable    #keyword    #parameter
    ${headers}  Create Dictionary    Content-Type=application/json
    ${params}    Set Variable   id=1
    ${data}    Create Dictionary    url=${url}  params=${params}   headers=${headers}
    ${rlt}    HTTP GET   data=${data}
    ${expect}    Set Variable   {"code":"0000", "data":{"count":6}}  # The expected value format is consistent with the interface response format, and there can be fewer content fields
    validate    rlt=${rlt}    expect=${expect}  # The returned result is validated against the expected interface
    log to console      ${rlt}[data][data][0][suite_id]
    ${data1}    Extract    data=${rlt}      key=data  #Single layer data structure extraction
    log to console   ${data1}
    ${iteration}     Json Path    data=${rlt}    path=$.data.data[0].iteration  #Specify extraction: multi tier data structure extraction

Use case writing - > ride GUI
# ride operation

> ride.py Storage path:  \Python36-32\Scripts\ride.py
> * Command start python ride.py
> * .bat Script startup python ride.py

# ride shortcut key
> - **F5** View keywords corresponding to dependent Libraries
> - **Ctrl + Alt + space** Complete the keywords and display the instructions for the corresponding keywords
> - other.... (If you are interested, you can find out,The above shortcut keys are helpful in case writing)

  • Use custom keywords
HttpRunner use case writing yml format

api registration

case writing

Robot framework -> Report html
Log html

jenkins integrated Robot framework

  • Robot framework plug-in installation
  • Build configuration

Robot framework plug-in installation

Robot framework build result details 1

Details of Robot framework construction results 2

pycharm to write robot framework

  • Plug in installation: IntelliBot, Robot Framework Support, robot files
  • Quick debugging configuration: as shown below:

Posted by man12_patil3 on Thu, 25 Nov 2021 23:40:51 -0800