[英]how to read csv values using robot framework
How to read particular value based on key using robotframework 如何使用robotframework基于密钥读取特定值
I am trying to read particular value from csv by passing the key parameter 我试图通过传递key参数从csv读取特定值
file.csv-> has below items
Param_Name,Param_Value
res_name,res123
id_name,123
robotfile.csv->
ReadCSV
[Arguments] ${paramname}
@{list}= read csv file to list ${CURDIR}${/}file.csv
${dict1}= Set Variable ${list}
:FOR ${node} IN @{dict1}
\ Log To Console ${node[1]}['${paramname'}]
${Read_Name}= ReadCSV res_name
expected:res123 Actual: None 预期:res123实际:无
I created the following example based on your needs. 我根据您的需要创建了以下示例。 The keyword will first create a list with a
res_name
and id_name
(you can substitute your own way of fetching a CSV list here) and then returns the wanted field value to you and prints it. 关键字将首先创建一个带有
res_name
和id_name
的列表(您可以在此处替换您自己的获取CSV列表的方式),然后将所需的字段值返回给您并进行打印。
*** Settings ***
Library String
*** Keywords ***
ReadCSV
[Arguments] ${FIELD}
@{LIST}= Create List res_name,res123 id_name,123
:FOR ${ITEM} IN @{LIST}
\ @{FIELDS}= Split String ${ITEM} ,
\ Return From Keyword If '${FIELDS[0]}' == '${FIELD}' ${FIELDS[1]}
[return]
*** Test Cases ***
Read CSV values
${NAME}= ReadCSV res_name
Log To Console res_name: ${NAME}
${ID}= ReadCSV id_name
Log To Console id_name: ${ID}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.