For my program I want to read a key from a properties file and an associated List of values for the key.

Recently I was trying like that


public class DriverManager {
    public static WebDriver driver;
    String baseUrl;
    public Properties prop;

    public DriverManager() throws IOException {
        // Get baseUrl property
        File file = new File("config.properties");
        FileInputStream fileInput = null;
        try {
            fileInput = new FileInputStream(file);
        } catch (FileNotFoundException e) {
        //load properties file
        Map<String,List<String>>categoryMap = new Hashtable<String, List<String>>();

        Properties prop = new Properties();

        try {

            Set<Object> keys = prop.keySet();
            List<String> categoryList = new ArrayList<String>();
            for (Object key : keys) {
            System.out.println("Category Map :"+LoginSteps.categoryMap);

            keys = null;
            prop = null;

        } catch (Throwable e) {

property file:

nam=geo,george, sony

I want to do like this, but got some error in my code util package.


The path before the test method will be defined by data provider:

    Object[][] setData() {
        return new Object[][] {
                {"geo", "123"},
                {"geosony", "1"},
                {"geo", "0055"},
                {"", ""}

Rewrite the test method this way:

@Test(dataProvider = "setData")
    public void initDriver(String name, String password) {
        HomePage page = new LoginSteps().Login(name, password);
| improve this answer | |
  • I am keeping my test data in property file. I want to do multiple test data too how ? – user24314 Mar 6 '17 at 4:12
  • Data providers are for TestNG, but jUNit has something similar. The idea is you load the property data in the setData() function. Just loop and push the data into the object. For jUnit look at parameters here: stackoverflow.com/questions/19203730/… – Niels van Reijmersdal Mar 6 '17 at 8:13
  • @NielsvanReijmersdal Hai sir, I edit my post and I am using with array list to read mutilple test data in property file. can you please review ? – user24314 Mar 6 '17 at 8:45

Apache PropertyConfiguration support loading of keyValue with same keys.

Below method can return list of values for same key.

  • getList(key) and
  • getStringArray(key)
| improve this answer | |

I do not see you loading config.property file to your Property variable.



Properties prop = new Properties();

should resolve your error. Also, try to keep everything inside one try catch block.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy