我正在从机器人框架运行查询以从数据库中获取ID,该查询有效,但是我返回的值为'locationId': ['[('somekindofIdhere', )]
,我只需要somekindofIdhere
值,
我试图获取列表的第一个索引
Verify Location Details
@{Get_LocationId}= Query Select locationId From Location WHERE LocationName = '${Name}'
${Response_Location}= Rest.get http://sampleurl/sample/locations/@{Get_LocationId}[0]
但是这给了我('somekindofIdhere', )
的回馈,我该如何摆脱()
字符并得到值呢?
答案 0 :(得分:2)
查询返回列表列表-外部列表是查询返回的行的列表,内部列表是列的列表。即使查询在单行中返回单列,也是如此。您可以使用漫游器的嵌入式变量语法来引用所需的值:
${Response_Location}= Rest.get http://sampleurl/sample/locations/${Get_LocationId[0][0]}
这里是一个完整的例子,可以说明不同之处。我正在模拟@{Get_LocationId}
中的数据,以便测试不需要实际的数据库连接。
*** Test Cases ***
Example
# simulate a list of tuples as returned by a db query
${Get_LocationId}= evaluate [('somekindofIdhere',)]
should be equal as strings ${Get_LocationId} [('somekindofIdhere',)]
should be equal as strings @{Get_LocationId}[0] ('somekindofIdhere',)
should be equal as strings ${Get_LocationId[0]} ('somekindofIdhere',)
should be equal as strings ${Get_Locationid[0][0]} somekindofIdhere