Sawitree Cha
Sawitree Cha

Reputation: 199

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)

Upvotes: 1

Views: 1942

Answers (2)

gaurav gaud
gaurav gaud

Reputation: 1

Here no need to use CSV library.

If we want to create new csv file with new data always then we can use Create File keyword from OperatingSystem library

Create File filename.csv content=content_added_in_csvFile

e.g. Create File ${CURDIR}/Demo.csv content=675432561

If we want to add multiple data in CSV then

Create File ${CURDIR}/Demo.csv content=68868686,85757464,5757474

Here when we will run this code then old file will be replace by new file with provided content .

Hope It will resolve this issue

Upvotes: 0

forkdbloke
forkdbloke

Reputation: 1565

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.

Upvotes: 1

Related Questions