I have a case where in the Login class I want to know which type of browser I am using. What is the mobile server address. What is the version of browser and other settings defined in twist.Properties
I am using the default system web browser instantiated by the twist. Twist version is 2.4.0.12621
Please let me know how to implement this or procedure for the same.
Thanks,
Sarita.
Comment
You can autowire the "Environment" to your fixture and get your os and enviroment level properties from it. For example, if you have a Context (or Fixture), naming "Login", you can do like below to get environmental properties like os.arch, os.name etc:
public class Login {
@Autowired
org.springframework.core.env.Environment env;
public void setUp() throws Exception {
System.out.println(env.getProperty("os.arch"));
}
public void tearDown() throws Exception {
}
}
If you are looking to get the properties declared in twist.properties, then you have to do a little bit more. Following is an approach where we have a custom PropertyPlaceholderConfigurer which binds the properties at the context xml level, as well provide a way to read the same properties when it is referred elsewhere.
** Declare your Custom property placeholder first like the class below (e.g. com.test.CustomPropertyPlaceHolderConfigurer)
------------------------------------------------------------------------------------------------------------------------------------
package com.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class CustomPropertyPlaceHolderConfigurer extends
PropertyPlaceholderConfigurer {
private int sysPropMode;
private Map<String, String> propertiesMap;
@Override
public void setSystemPropertiesMode(int systemPropertiesMode) {
super.setSystemPropertiesMode(systemPropertiesMode);
this.sysPropMode = systemPropertiesMode;
}
@Override
protected void processProperties(
ConfigurableListableBeanFactory beanFactoryToProcess,
Properties props) throws BeansException {
super.processProperties(beanFactoryToProcess, props);
propertiesMap = new HashMap<String, String>();
for (Object key : props.keySet()) {
String keyStr = key.toString();
String valueStr = resolvePlaceholder(keyStr, props, sysPropMode);
propertiesMap.put(keyStr, valueStr);
}
}
public String getPropertyValue(String name) {
return propertiesMap.get(name);
}
public List<String> getPropertyNames() {
ArrayList<String> propertyNames = new ArrayList<String>();
for (Object key : propertiesMap.keySet()) {
propertyNames.add(key.toString());
}
return propertyNames;
}
}
---------------------------------------------------------------------------------------------------
** change the applicationContext-suite.xml file to refer to your custom property placeholder like below (note, only thing that i have changed is the classname)
<bean class="com.test.CustomPropertyPlaceHolderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="locations">
<value>classpath:twist.properties</value>
</property>
</bean>
---------------------------------------------------------------------------------------------------
** now you can autowire the custom placeholder to your context or fixture. e.g. in your Login class
public class Login {
@Autowired
com.test.CustomPropertyPlaceHolderConfigurer propertyConfigurer;
public void setUp() throws Exception {
System.out.println(propertyConfigurer.getPropertyValue("twist.generate_local_report"));
for (String property : propertyConfigurer.getPropertyNames()) {
System.out.println(String.format("Property %s=%s", property, propertyConfigurer.getPropertyValue(property)));
}
}
public void tearDown() throws Exception {
}
}
---------------------------------------------------------------------------------------------------
Hope this works for you.
regards
We also have this case where we would like to specify configuration parameters. It would be great if we could have access to them by default without having to go thorough the described method.
Thanks,
Patrick
p.s. Things are going well with our initial testing using Twist. It seems like a quality product so far. Thank you guys.