2016-06-30 5 views
0

Ich möchte übertragen eine Liste als Parameter in meiner Bibliothek Schlüsselwort zu übertragen:Ich kann die Liste/Wörterbuch in meinem Test-Bibliothek in Roboter Rahmen

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

Und die @vargs Liste mit String und Liste kombiniert wird:

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

In meiner Bibliothek:

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__)) 

Sie sind immer:

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

Aber ich möchte das "Ziel" sollte "Liste" sein.

Antwort

1

Create Liste wird eine Liste von 3 Strings erstellen, egal was Sie nach dem Ziel setzen = unten.

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

Es sieht so aus, als ob Sie manuell versuchen, Schlüsselwortargumente zu verwenden. Aber Python und Robot Framework unterstützen sie, so dass es nicht nötig ist, auf '=' zu parsen und zu teilen. Ändern Sie Ihr Schlüsselwort, um Schlüsselwortargumente zu akzeptieren. Dann erstellen Sie anstelle einer Liste ein Wörterbuch.

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))) 

In Ihrem Test:

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

Ausgang:

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'> 

Alternativ können Sie auch nehmen haben ModifyDefaultValue ein dict als zweites Argument.

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))) 

In Ihren Daten:

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

Siehe auch: