我有一个Python模块,它有两个类。每个类都定义了一组函数或方法。如何从ROBOT框架中的类调用特定方法。不过,我正在尝试下面的方法,它给出了以下错误。有人能帮我解决这个问题吗。Python模块和Robot文件位于同一路径中。我已尝试将library语句更改为CheckCode.employee,名称为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
Robot不会自动创建库文件中类的实例,但有一个例外:如果名称与不带
.py
扩展名的文件名匹配,它将自动创建类的实例。例如,如果文件CheckCode.py
定义了一个名为CheckCode
的类,robot将自动创建一个实例,并使用该实例将每个方法公开为关键字。如果要在文件中创建某个类的实例,则必须创建一个这样做的关键字。例如:
你可以这样使用它:
还可以使用Call Method关键字调用对象上的方法:
从ROBOT框架中的python模块调用特定方法
机器人文件
Python文件hello.py
听起来您可能正在使用物理路径导入库。要从同一模块导入两个库,必须按如下名称导入它们:
或动态:
为了像这样导入,您需要在Python路径上获取模块。请参阅this section以获取有关该操作的帮助。
从用户指南中的Using physical path to library:
相关问题 更多 >
编程相关推荐