我无法将 list/dictionary 传输到机器人框架中的测试库中
I cannot transfer the list/dictionary into my test library in robot framework
我想将一个列表作为参数传输到我的库关键字中:
ModifyDefaultValue
${DataJson} ModifyDefaultValue ${DataJson} @{vargs}
@vargs 列表与字符串和列表相结合:
@{vargs} Create List NO=1227003021 requestType=0 destination=@{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'>
但我想 "destination" 应该是 "list"。
Create list 将创建一个包含 3 个字符串的列表,无论您在下面的 destination= 后面放什么。
Create List NO=1227003021 requestType=0 destination=@{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
另请参阅:
我想将一个列表作为参数传输到我的库关键字中:
ModifyDefaultValue
${DataJson} ModifyDefaultValue ${DataJson} @{vargs}
@vargs 列表与字符串和列表相结合:
@{vargs} Create List NO=1227003021 requestType=0 destination=@{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'>
但我想 "destination" 应该是 "list"。
Create list 将创建一个包含 3 个字符串的列表,无论您在下面的 destination= 后面放什么。
Create List NO=1227003021 requestType=0 destination=@{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
另请参阅: