我有一个Python模块有2个类。每个类都有一组定义的函数或方法。我们如何从ROBOT框架的类中调用特定的方法。我正在尝试下面的方法,但是,它给出了以下错误。有人可以帮助我解决这个问题。 Python模块和Robot文件位于相同的路径中。我尝试将库语句更改为CheckCode.employee WITH_NAME xyz。这没有帮助。谢谢。从ROBOT框架中的Python模块调用特定的方法
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
感谢您的回答。让我继续研究PYTHONPATH方法,并在有问题时再回来。 – user2905950
尽管我试图回答这个问题,但我建议你看看Bryan的答案。我同意他对代码结构的评估。 – ombre42