I have a Java project containing junit tests that need to be run in different test environments (Dev, Staging, etc.) through Jenkins.
How to set up building a project in different environments and how to pass the url, username and password for maven?
Can I use maven 3 profiles to read the environment URL, username and password from the properties file?
Edit: I added profiles to Project POM:
<profiles> <profile> <id>Integration</id> </profile> <profile> <id>Staging</id> </profile> <profile> <id>PP1</id> </profile> <profile> <id>PP2</id> </profile> <profile> <id>PP3</id> </profile> </profiles>
How do I pass the url, username and password to these profiles?
Currently, tests get test environment details from the properties file:
public class BoGeneralTest extends TestCase { protected WebDriver driver; protected BoHomePage boHomePage; protected static Properties systemProps; String url = systemProps.getProperty("Url"); String username = systemProps.getProperty("Username"); String password = systemProps.getProperty("Password"); int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements")); static { systemProps = new Properties(); try { systemProps.load(new FileReader(new File("src/test/resources/environment.properties"))); } catch (Exception e) { e.printStackTrace(); } }
Edit 2:
Change made in test runner class:
public class BoGeneralTest extends TestCase { protected WebDriver driver; protected BoHomePage boHomePage; protected static Properties systemProps; String url = systemProps.getProperty("Url"); String username = systemProps.getProperty("Username"); String password = systemProps.getProperty("Password"); int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements")); String regUsername = RandomStringUtils.randomAlphabetic(5); final static String appConfigPath = System.getProperty("appConfig"); static { systemProps = new Properties(); try { systemProps.load(new FileReader(new File(appConfigPath))); } catch (Exception e) { e.printStackTrace(); } }
source share