vlatko606
vlatko606

Reputation: 1149

Jmeter - how to write specific variable to CSV file to specific row/column

My csv file looks like:

TC_name, username, password, excpecedCode
ad_test_master_successful_login,username,Test123!,200

What is the easiest way to so i can write to csv to specific row/column, and example to overwrite Test123! with variable fetched from user defined variables?

I know i can read value using JSR223 Pre/post processor with ex:

def line10 = new File('C:/Users/test/Desktop/testData/login.csv').readLines().get(1).split(",")[2]
log.warn("csv as-> " + line10);

Upvotes: 0

Views: 829

Answers (1)

Dmitri T
Dmitri T

Reputation: 168082

There is no such concept as "cell" in CSV files, if you're looking for the code which will replace one string with another, you can do something like:

def file = new File('test.csv')
def text = file.text.replaceAll('Test123!', vars.get('foo'))
file.text = text

If you're looking for a better option you can consider using GroovyCSV library (you will need to download it and place in JMeter Classpath followed by JMeter restart) or consider switching to Excel file where you will have full control via Apache POI library like it's described in How to Implement Data Driven Testing in your JMeter Test article

Upvotes: 1

Related Questions