cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove data from a csv file

SOLVED
Highlighted
Occasional Contributor

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Staff

Re: How to remove data from a csv file

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

image.png

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. 

image.png

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


image.png

 

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)

image.png

 

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

image.png

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.

Best,
Justin Kim

View solution in original post

8 REPLIES 8
Community Hero

Re: How to remove data from a csv file

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

Highlighted
Community Hero

Re: How to remove data from a csv file

@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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Community Hero

Re: How to remove data from a csv file

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.  

Highlighted
Occasional Contributor

Re: How to remove data from a csv file

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?
Highlighted
Community Hero

Re: How to remove data from a csv file

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.  

Highlighted
Occasional Contributor

Re: How to remove data from a csv file

Okay, so I work for a hire company.

 

My main aim is to automate the regression testing process.

 

Orders are created and then they need to be picked and dispatched.

 

Because the items are fleeted, when picking the items you need to enter an ecode/serial number ( this is what is contained in the .csv file)

 

Once I have picked an item I want to remove that ecode/serial niumber from the .csv file so that the next time I come to picking an item I am using a new ecode/serial number. 

 

A dataloop will not work for me in this scenario as I am not picking multiple orders until the data runs out I just need a new ecode/serial number for whenever I run the test. Ideally I would be able to use the same .csv file across multiple different tests within the same project.

 

so I have a .csv containing ecode/serial numbers of availible stock, once I have used the first ecode/serial number on the list I want to remove it from the .csv file so that it is not used again. 

 

 

any better? 

Highlighted
Community Hero

Re: How to remove data from a csv file

OK... a suggestion...  Rather than altering your source CSV file, create another one that all it contains is a list of the encodes/serials that were used.  Every time you use an encode, just write it out to the next line in that new file.

 

So, then, at the start of your automation, you read BOTH files into your automation into temporary variables.  Then, when you go to use an encode, first check to see if it has already been used. If so, skip and try the next one.  If you ever need to reset, simply empty that "used" file and you'll start over.

Now... that said...  A more "complete" suggestion.

 

Sanitize your test environment before every regression run.  Basically, reset all the databases, etc., back to a baseline starting point.  That way, each time you run it, you can use the same encode/serial each time and you won't have to worry about maintaining a list.  Basically, you're setting up your environment then to always have the same conditions.  It has the added benefit of predictability...that any comparisons you do, etc., can be against a fixed baseline rather than being a moving target of sorts.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Staff

Re: How to remove data from a csv file

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

image.png

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. 

image.png

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


image.png

 

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)

image.png

 

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

image.png

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.

Best,
Justin Kim

View solution in original post