2016-02-29 65 views
4

我是Robot FW的新手,我正處於學習階段。爲了嘗試調用外部庫,我做了一個非常簡單的功能並保存在tryingLibrary.py文件中。內容:簡單函數調用在Robot Framework中不起作用

def myAdding(x, y): 
    z = x + y 
    return z 

然後我又寫道以下RF測試

*** Settings *** 
Documentation Suite description 
Library   tryingLibrary.py 

*** Variables *** 
${x} 

*** Test Cases *** 
TestTest 
    ${x}= myAdding  30  26 

然而,當我檢查日誌文件,我發現${x} = 3026。我的意思是,我當然期待56不是3026

那麼可能是什麼問題?

+0

的參數添加爲字符串'「30」+「26」=「3026」' – Arman

+2

嘗試'def myAdding(x,y)中的'z = int(x)+ int(y)': ' 默認情況下機器人f/w將Unicode字符串作爲參數。您必須將其明確地轉換爲'int'或您可能想要使用的類型。 – malhar

回答

5

您可能希望看到這個documentation

doc文件明確指出,參數類型是Unicode字符串。有兩種方法來實現你想要的行爲

  1. 轉換它在Python功能這樣

    def myAdding(x, y): 
        z = int(x) + int(y) 
        return z 
    
  2. 使用它,如下所示,這裏是doc

    *** Test Cases *** 
    TestTest 
         ${x}= myAdding  ${30}  ${26}