Forum Discussion

Jakemorley's avatar
Jakemorley
Occasional Contributor
5 years ago

How to remove data from a csv file

Help please!

 

I am tying to create a keyword test which uses a variable from a csv file. The csv file contains serial numbers / ecodes however once an ecode has been used I want to remove it from the csv file so the next time I use the variable it doesnt try to use one that is no longer available. 

 

does anyone know a way where I can remove the first row of data from the csv file after I have used it in my test?

 

I use this variable in numerous different tests too

 

  • hkim5's avatar
    hkim5
    5 years ago

    one last suggestion would be to use a persistent project level variable as an integer value;

    you can reference that value as an index, save a table(or column of those serial codes etc.) as another variable, and access one index value at a time, with an additional last step being incrementing the persisten project level variable. 

    now you can edit what you are typing in/setting text/etc.


     

    and when you click into that value panel, you can select your table variable, then select the cell, column (the names or serial numbesr etc.) and then the rows (project index variable)

     

    and then finally, you increment the value of the project index variable by 1, using a little code.

    drag that script routine in as your last step in your keyword test, and now, everytime you run your test, this test will use the next "row" of the table variable storing whatever information you have, to type it in as you need.

  • How are you choosing which value to use from the .csv file?  Are you just iterating through the rows?

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Marsha_R question is relevant because we need to know how you are reading in the values in the first place.  Are you using the Data Driven operations of keyword tests?  In that case, using the CSV file is a read-only, forward moving loop.  To do what you want, you'll need to be able to write to the CSV which means you'll need to engage the CSV file using an aqFile method to open and write to the file.

      • Marsha_R's avatar
        Marsha_R
        Moderator

        And if you use that data-driven loop, there's no need to delete values, so if you aren't doing that, you should consider it.  

    • Jakemorley's avatar
      Jakemorley
      Occasional Contributor
      Yeah just using the next one on the list just like it does when creating a data loop however I want to either remove the ones which have been used or remember which line is next when I restart the test or use the same variable on another test.

      Hope that makes sense?
      • Marsha_R's avatar
        Marsha_R
        Moderator

        Well, no, it doesn't yet, lol

         

        Explain some more about your testing please.  Deleting data isn't usually done.  Maybe we can help you redesign your test.