1

How to read particular value based on key using robotframework

I am trying to read particular value from csv by passing the key parameter

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

1 Answer 1

2

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.

*** 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}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.