use*_*950 2 python robotframework
我有2个类的Python模块。每个类都有一组定义的函数或方法。我们如何从ROBOT框架的类中调用特定方法。我正在尝试下面的方法,但是它给出了以下错误。有人可以帮我解决这里的问题。Python模块和机器人文件在同一路径中。我尝试将库语句更改为CheckCode.employee WITH_NAME xyz。这没有帮助。谢谢。
ERRORS
==============
[ WARN ] Imported library '/homes/user/New/CheckCode.py' contains no keywords.
==============================================================================
CheckCode :: Checking small built in code
==============================================================================
Verify we can call a particular class from a Python Module in Robot | FAIL |
No keyword with name 'my_code.employee.staff info' found.
------------------------------------------------------------------------------
CheckCode :: Checking small built in code | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Python Module File output
******************************
import re
import collections
import math
class person():
def __init__(self,first,last):
self.firstname = first
self.lastname = last
def emp_name(self):
return self.firstname + " " + self.lastname
class employee(person):
def __init__(self,first,last,empId):
person.__init__(self,first,last)
self.staffId = empId
def staff_info(self):
return self.Name() + " " + self.staffId
ROBOT FILE
******************************
*** Settings ***
Documentation Checking small built in code
Library BuiltIn
Library Collections
Library CheckCode.py WITH NAME my_code
*** Test Cases ***
Verify we can call a particular class from a Python Module in Robot
Log Hello World
${var} = my_code.employee.staff info Maggi Nestle 20000
*** Keywords ***
Init
Set Log Level DEBUG
Run Code Online (Sandbox Code Playgroud)
Robot不会自动创建库文件中的类的实例,只有一个例外:如果名称与不带.py扩展名的文件名匹配,它将自动创建类的实例。例如,如果您的文件CheckCode.py定义了一个名为的类CheckCode,robot将自动创建一个实例,并使用该实例将每个方法公开为关键字。
如果要在文件中创建某个类的实例,则必须创建一个执行该操作的关键字。例如:
# CheckCode.py
class person()
...
...
def create_person(first, last):
return person(first, last)
Run Code Online (Sandbox Code Playgroud)
然后可以像这样使用它:
*** Settings ***
Library CheckCode.py
*** Test Cases ***
Example
${person}= create person Maggi Nestle
Should be equal as strings ${person.emp_name()} Maggi Nestle
Run Code Online (Sandbox Code Playgroud)
您还可以使用Call Method关键字在对象上调用方法:
${name}= Call method ${person} emp_name
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14381 次 |
| 最近记录: |