0
username 1  abc
password 1  123
username 2  pqr
password 2  456
username 3  xyz
password 3  789

how to read .csv file values like .properties file, means whenever we give key name its should display value correspondence to that key in selenium?

when I enter username1 it should display abc. similarly,s for password1 it should display 123 in java

m2j
  • 1,152
  • 5
  • 18
  • 43

1 Answers1

0

Assuming Your CSV file is structured as ->

username 1, abc
password 1, 123
username 2, pqr
password 2, 456
username 3, xyz
password 3, 789

Use the following ->

BufferedReader br = new BufferedReader(new FileReader(new File("test.csv")));
String str="";
Map<String,String> map = new HashMap<String,String>();
while((str=br.readLine())!=null)
{
         map.put(str.split(",")[0],str.split(",")[1]);
}

This should give you the output.

Ajinkya Patil
  • 741
  • 1
  • 6
  • 17
  • suppose i am calling one method by name public void login (username1,password1) , then the code should automatically take the values of username 1 and password 1 that is stored in .csv file and execute the remaining code – Sandeep S.B Apr 11 '16 at 11:11
  • You can use get function of map to retrieve the values of your parameters passed in login function. – Ajinkya Patil Apr 11 '16 at 11:35