I tried best couldn't find a complete instructions on how to config a properties file with Maven,Testng.
Here are what I did and the exception I got:
- from TestNG for suite, added
content of the config file: user=testuser password=pswd
- pom.xml src/test/resources true
in code: @BeforeTest @Parameters(value = { "config-file" }) public void initFramework(String configfile) throws Exception {
InputStream stream = Config.class.getResourceAsStream("/config.properties"); Properties properties = new Properties(); try { properties.load(stream); String user = properties.getProperty("user"); String password = properties.getProperty("password"); System.out.println("\nGot User FirstName+LastName shows as:"+ user +"\n" + password + "==========="); } catch (IOException e) { e.printStackTrace(); // You will have to take some action here... }}
Here is what I got when compile:
org.testng.TestNGException: Parameter 'config-file' is required by @Configuration on method initFramework but has not been marked @Optional or defined
Question: I think I got all options mixed but really wanted a working way to read the parameter for Java/Selenium/TestNG/Maven.