机器人框架-如何在行列表中获取值

时间:2018-11-07 11:42:33

标签: arrays list robotframework

我正在从机器人框架运行查询以从数据库中获取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', )的回馈,我该如何摆脱()字符并得到值呢?

1 个答案:

答案 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