04-Robot Framework教程-用户自定义库(四)


1. 第一个不创建一个Python模块UserLibModule.py

class UserLibModule(object):
    def util_functioncode(self):
        return " This is from the User Library"

2. 添加Robot代码

*** Settings ***
Library    UserLibModule.py

3. 使用这个库

*** Settings ***
# 导入用户自定义库
Library   UserLibModule.py

*** Variables ***

*** Test Cases ***
HelloRobot
   [Documentation]    User define Library
   call User Library

*** Keywords ***
Call User Library
  # No underscore needed as in the python lib code above
  ${out}=   util functioncode
  Log To Console   ${out}

4. 运行结果

==============================================================================
Test                                                                          
==============================================================================
HelloRobot :: User define Library                                       This is from the User Library
HelloRobot :: User define Library                                     | PASS |
------------------------------------------------------------------------------
Test                                                                  | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================