2016-06-30 25 views
0

我想以一個列表作爲參數傳遞到我的圖書館關鍵字:我不能轉移列表/字典到我的測試庫機器人框架

ModifyDefaultValue 
    ${DataJson} ModifyDefaultValue ${DataJson} @{vargs} 

用繩子並列出@vargs列表組合:

@{vargs} Create List NO=1227003021 requestType=0 [email protected]{destinations} 

在我的圖書館:

def ModifyDefaultValue(self, dictOri, *vargs): 
    '''<br/> 
     *vargs: List Tyep and format is: var1=value1, var2=value2 
    ''' 
    logger.info("SmartComLibrary ModifyDefaultValue()", also_console=True) 
    for i in range(len(vargs)): 
     logger.info("\t----Type: %s" % str(vargs[i].split("=")[1].__class__)) 

他們總是:

20160630 22:11:07.501 : INFO :  ----Type: <type 'unicode'> 

但我想「目的地」應該是「名單」。

回答

1

創建列表將創建3個字符串的列表,無論您在destination = below之後放置什麼。

Create List NO=1227003021 requestType=0 [email protected]{destinations} 

看起來您正在手動嘗試使用關鍵字參數。但Python和Robot Framework支持它們,因此不需要解析和分割「=」等。將您的關鍵字更改爲接受關鍵字參數。然後,而不是建立一個列表,你建立一個字典。

def ModifyDefaultValue(self, dictOri, **kwargs): 
     logger.info("SmartComLibrary ModifyDefaultValue()", also_console=True) 
     for k, v in kwargs.items(): 
      logger.info("\t----Type: %s: %s" % (k, type(v))) 

在您的測試:

${destinations} Create List a b c 
&{kwargs} Create Dictionary NO=1227003021 requestType=0 destination=${destinations} 
ModifyDefaultValue asdf &{kwargs} # note the & here 

輸出:

20160630 12:12:41.923 : INFO :  ----Type: requestType: <type 'unicode'> 
20160630 12:12:41.923 : INFO :  ----Type: destination: <type 'list'> 
20160630 12:12:41.923 : INFO :  ----Type: NO: <type 'unicode'> 

或者,你也可以有ModifyDefaultValue採取的字典作爲第二個參數。

def ModifyDefaultValue(self, dictOri, args): 
    logger.info("SmartComLibrary ModifyDefaultValue()", also_console=True) 
    for k, v in args.items(): 
     logger.info("\t----Type: %s: %s" % (k, type(v))) 

在您的數據:

${destinations} Create List a b c 
&{args} Create Dictionary NO=1227003021 requestType=0 destination=${destinations} 
ModifyDefaultValue asdf ${args} # note the $ here 

參見:

相關問題