我有一個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