XCore has support for testing in a multitude of environments and browsers.

Making use of Properties files can help get the job done.

JTAF.properties

strategy=profiles/strategies/Regression.strategy.xml
target=profiles/targets/qa.properties
client=profiles/clients/firefox.properties

JTAF.properties holds properties specific to the current test run. A strategy property is always defined. You can declare any other properties you'd like - it's our convention to make these values the file paths of other property files. For example, one could have a target property declared to specify a config holding environment-specific variables; a client property could be declared to access client/browser-specific variables.

These additional properties files could be opened in whatever Property Reader you'd prefer - for example, the built-in java.util.Properties class.

If one needed environment-specific variables like the application url and the corresponding database credentials for that environment, they could manage them in a configuration file named qa.properties in the profiles/targets directory.

profiles/targets/qa.properties
applicationUrl=http://myapp.qa.myco.com/
myDatabase.driver=oracle.jdbc.OracleDriver
myDatabase.url=jdbc:oracle:thin:@databaseserver.qa.myco.com:1521:DBQ
myDatabase.username=johnsmith
myDatabase.password=secret123
		

A built-in method of grabbing the target configuration file name is provided by the JTAFPropertyManager.


Command Class

Assume a class exists that opens up a URL passed to it. The example below shows how an environment-specific URL can be opened, given the configuration described above.

package org.myorg.example.commands.main;

import org.myorg.example.PageOpener;

import org.finra.jtaf.core.model.exceptions.NameFormatException;
import org.finra.jtaf.core.model.execution.IInvocationContext;
import org.finra.jtaf.core.model.invocationtarget.Command;

import java.util.Properties;

/**
 * Opens the application
 */
public class OpenApplicationCmd extends Command {

	public OpenApplicationCmd(String name) throws NameFormatException {
		super(name);
	}

	@Override
	protected void execute(IInvocationContext ctx) throws Throwable {
		PageOpener po = new PageOpener();
		Properties target = new Properties();
		InputStream inputStream = getClass().getClassLoader().getResourceAsStream(JTAFPropertyManager.getInstance().getProperty("target"));
		target.load(inputStream);
		po.openPage(target.getProperty("applicationUrl"));
	}
}