Search code examples
pythoncsvrobotframework

How to update data to CSV file by specific field using Robot Framework


Now I use keyword

Append Data
  ${list}=    Create List    Test1    Test2
  ${data}=    create list    ${list}
  Append To Csv File    ${File_Path}    ${list}

but it cannot specific the data's position that I want to update, In my test case I have to update new data everytimes after finished case to use new data in next case. (I kept the test data is in CSV file)


Solution

  • Looks like you are already making use of CSVLibrary in this library you have only the following KWS, what we can notice from here is that, we do not have replace CSV line/file anything, hence, we need to come up with our own procedure.

    • Append To Csv File
    • Csv File From Associative
    • Empty Csv File
    • Read Csv File To Associative
    • Read Csv File To List

    APPROACH#1

    In my test case I have to update new data everytimes after finished case to use new data in next case.

    One of the ways which can be employed to solve your problem, is by converting all of the csv file data into list of dicts.

    • Read the cvs into list of dicts using Read Csv File To Associative
    • make a copy of the original list of dicts
    • Start of Testcase#1
    • make the modification to the list of dicts, just in case you would like to go back in time for a quick referral
    • End of Testcase#1
    • Start of Testcase#2
    • make and use the modified content of list of dists from Testcase#1
    • End of Testcase#2
    • So on for the rest of the test cases.