You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by danimni <da...@gmail.com> on 2011/03/14 16:53:40 UTC

Setting CSV file name as a variable

Hi,
I have a script that receives two CSV files.
First file contains some general information and the second file contains
list of all user's LoginID.
I would like to the second CSV input file to be set by he first CSV input
file.
for example:
one parameter of the first CSV file is the file name of the second CSV (my
script uses each run different LoginIDs).
I tried to it by setting the 'File Name' field, in the 'CSV Data Set Config'
Config eEement the following:
${LOGINID_CSVFILENAME}

Is it possible?

Thanks,
Dan.

--
View this message in context: http://jmeter.512774.n5.nabble.com/Setting-CSV-file-name-as-a-variable-tp3556572p3556572.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Setting CSV file name as a variable

Posted by Deepak Shetty <sh...@gmail.com>.
>I would to run the same test, each time for different LoginID CSV file.
This is different from the problem you originally specified. If you are
running through ant just pass in a property that represents the name of the
file and read that property.

Your original question implied a nested set of files within the same test.

regards
deepak

On Tue, Mar 15, 2011 at 3:18 AM, danimni <da...@gmail.com> wrote:

> Thanks, deepak and Kodera for your replies.. :)
>
> Kodera, the number of users is not my problem. my problem is the content of
> the login IDs.
> I have this script that gets the LoginIDs from CSV file. I would to run the
> same test, each time for different LoginID CSV file.
>
> For example, CSV1 contains the following:
> Superadmin, John, Mark, Josh, Michael.
>
> and for the same script, I have CSV2 with the following:
> Superadmin, George, Mike, Bob, Sharon.
>
> thanks again.
>
> Dan.
>
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/Setting-CSV-file-name-as-a-variable-tp3556572p3695937.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: Setting CSV file name as a variable

Posted by danimni <da...@gmail.com>.
Thanks, deepak and Kodera for your replies.. :)

Kodera, the number of users is not my problem. my problem is the content of
the login IDs.
I have this script that gets the LoginIDs from CSV file. I would to run the
same test, each time for different LoginID CSV file.

For example, CSV1 contains the following:
Superadmin, John, Mark, Josh, Michael.

and for the same script, I have CSV2 with the following:
Superadmin, George, Mike, Bob, Sharon.

thanks again.

Dan.


--
View this message in context: http://jmeter.512774.n5.nabble.com/Setting-CSV-file-name-as-a-variable-tp3556572p3695937.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Setting CSV file name as a variable

Posted by apurv30 <ap...@gmail.com>.
Hello Dan,

I have written a program that can read from a text file with values written
as..
no_of_threads=45

The code parses the line, splits the strings and stores the value in a
variable  and parses it into an interger..

It also has the regex pattern required to do a search replacement. I did it
for an xml file including quotes.
If you want .csv file you can check source forge for code that reads from
file, and to replace u can use below code.

The sample code is copy pasted below..

import java.util.*;
import java.io.*;
import java.util.regex.*;
import java.io.IOException;

****** to read code from file *******
String target = "";
String path = "values.txt";
String[] s = null;

try {
            File file = new File(path);
            BufferedReader br = new BufferedReader(
                                new InputStreamReader(
                                new FileInputStream(file)));                 

            br.mark(200); // specify a large enough = total no of characters
in file
           
            target = "no_of_users";
            while((line = br.readLine()) != null){           
                    if(line.indexOf(target) != -1){
                    br.reset();
                    break;                   
                    }
                }
                s = line.split("\\=");           
                no_of_users = s[1];   

} catch(IOException e){
                    System.out.println("Error: Unable to Load Values from
file check Values.txt " + e.getMessage());
                }


******* for text replacement in a file  including pattern matching
***********

try{         
            File file = new File(test_file);           
            // Read the entire contents of jmeter file
            BufferedReader reader = new BufferedReader( new FileReader
(file));
            line  = null;
            StringBuilder stringBuilder = new StringBuilder();
            String ls = System.getProperty("line.separator");
            while( ( line = reader.readLine() ) != null ) {
                stringBuilder.append( line );
                stringBuilder.append( ls );
            }
            reader.close();

// Replace Number of Threads
            Pattern pattern =
Pattern.compile("ThreadGroup.num_threads\\\">[0-9]*");         
            Matcher matcher = pattern.matcher(stringBuilder);
            String output =
matcher.replaceAll("ThreadGroup.num_threads\\\">" + no_of_users + "");

/* 
the code replace the value in the string 
"ThreadGroup.num_threads">any_integer_value
with the value specified in the variable - no_of_users
for random text u can specify [a-z]*[A-Z]*[0-9]*
*/


BufferedWriter out = new BufferedWriter(new FileWriter(test_file));
            out.write(output);
            out.close();           
        }
        catch(Exception e)
        {
            System.out.println("Error : " + e.getMessage());
            e.printStackTrace();           
        }


Cheers,
Apoorv Kodera

--
View this message in context: http://jmeter.512774.n5.nabble.com/Setting-CSV-file-name-as-a-variable-tp3556572p3673800.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Setting CSV file name as a variable

Posted by Deepak Shetty <sh...@gmail.com>.
not possible directly
I think you can Use function CSV read/StringFromFile for the second data
file  and CSV DataSetConfig for the first one - should work not verified

regards
deepak

On Mon, Mar 14, 2011 at 8:53 AM, danimni <da...@gmail.com> wrote:

> Hi,
> I have a script that receives two CSV files.
> First file contains some general information and the second file contains
> list of all user's LoginID.
> I would like to the second CSV input file to be set by he first CSV input
> file.
> for example:
> one parameter of the first CSV file is the file name of the second CSV (my
> script uses each run different LoginIDs).
> I tried to it by setting the 'File Name' field, in the 'CSV Data Set
> Config'
> Config eEement the following:
> ${LOGINID_CSVFILENAME}
>
> Is it possible?
>
> Thanks,
> Dan.
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/Setting-CSV-file-name-as-a-variable-tp3556572p3556572.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: Setting CSV file name as a variable

Posted by apurv30 <ap...@gmail.com>.
Hello Dan,

I have written code for a variation of the same, but i use .txt files
instead of csv.. 
Check if it helps you..

I have written a program that can read from a text file with values written
as..
no_of_threads=45

The code parses the line, splits the strings and stores the value in a
variable  and parses it into an interger..

It also has the regex pattern required to do a search replacement. I did it
for an xml file including quotes.
If you want .csv file you can check source forge for code that reads from
file, and to replace u can use below code. Instead of .txt you can fiddle
for .csv 

The sample code is copy pasted below..

import java.util.*;
import java.io.*;
import java.util.regex.*;
import java.io.IOException;

****** to read code from file *******
String target = "";
String path = "values.txt";
String[] s = null;

try {
            File file = new File(path);
            BufferedReader br = new BufferedReader(
                                new InputStreamReader(
                                new FileInputStream(file)));                 

            br.mark(200); // specify a number equal to total no. of
characters in file
           
            target = "no_of_users";
            while((line = br.readLine()) != null){           
                    if(line.indexOf(target) != -1){
                    br.reset();
                    break;                   
                    }
                }
                s = line.split("\\=");           
                no_of_users = s[1];   

} catch(IOException e){
                    System.out.println("Error: Unable to Load Values from
file check Values.txt " + e.getMessage());
                }


******* for text replacement in a file  including pattern matching
***********

try{         
            File file = new File(test_file);           
            // Read the entire contents of jmeter file
            BufferedReader reader = new BufferedReader( new FileReader
(file));
            line  = null;
            StringBuilder stringBuilder = new StringBuilder();
            String ls = System.getProperty("line.separator");
            while( ( line = reader.readLine() ) != null ) {
                stringBuilder.append( line );
                stringBuilder.append( ls );
            }
            reader.close();

// Replace Number of Threads
            Pattern pattern =
Pattern.compile("ThreadGroup.num_threads\\\">[0-9]*");         
            Matcher matcher = pattern.matcher(stringBuilder);
            String output =
matcher.replaceAll("ThreadGroup.num_threads\\\">" + no_of_users + "");

/*
 the code replaces the value between the text
<"ThreadGroup.num_threads">any_value
with the value specified in the variable no_of_users */

BufferedWriter out = new BufferedWriter(new FileWriter(test_file));
            out.write(output);
            out.close();           
        }
        catch(Exception e)
        {
            System.out.println("Error : " + e.getMessage());
            e.printStackTrace();           
        }


Cheers,
Apoorv Kodera

--
View this message in context: http://jmeter.512774.n5.nabble.com/Setting-CSV-file-name-as-a-variable-tp3556572p3673357.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org