How to provide property file name dynamically in java -


hi using 2 property files. 1 application configuration , 1 object repository. going use these 2 properties through out application. each , every testcase initialising property , access files using property object. want initialise property in separate method in separate class.also want call method in class , access property files using initialised property object. don't know how this. please give me hand task done.thanks in advance

below code

public class propertiesexample {      public static void main(string[] args) {          webdriver driver = null;         string baseurl;         file file = new file("/home/vaav/workspace/propertiesexample/config.properties");         properties prop = new properties();         fileinputstream fileio = null;          try{             fileio = new fileinputstream(file);             prop.load(fileio);             fileio.close();         }catch(filenotfoundexception ex){             ex.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }          system.setproperty("webdriver.chrome.driver", "/home/vaav/workspace/propertiesexample/lib/chromedriver");         driver = new chromedriver();         baseurl = prop.getproperty("url");         driver.get(baseurl+"/");          driver.manage().window().maximize();         driver.manage().timeouts().pageloadtimeout(10, timeunit.seconds);         driver.manage().timeouts().implicitlywait(10, timeunit.seconds);          driver.findelement(by.xpath(prop.getproperty("login.btnadmin"))).click();         driver.findelement(by.id(prop.getproperty("login.txtusername"))).sendkeys(prop.getproperty("username"));         driver.findelement(by.id(prop.getproperty("login.txtpassword"))).sendkeys(prop.getproperty("password"));         driver.findelement(by.id(prop.getproperty("login.btnsignin"))).click();     }  } 

i want property related stuff in file , make reusability of code

pick default filename , location property file. e.g. "./config.properties" assume properties file in user.dir on startup. or load same file classpath via resource loader e.g.

    final inputstream stream =        this.getclass().getresourceasstream("config.properties"); properties.load(stream); 

but give option override default location via system property. system.

 string configlocation = system.getproperties().getproperty("properties.location"); 

if configlocation not null, use user specified location. otherwise use default.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -