-
Notifications
You must be signed in to change notification settings - Fork 40
Properties injection
Properties are really useful when we want to provide some data in code without the code itself. Bobcat supports convenient properties handling. Let's assume that we want to store homepage URL in some property and use it then in our test. In order to do that, we should add .properties
file with defined data there. Create pages.properties
file under /src/main/config/common
directory with the following contents:
homepage.url=http://localhost:8080/index.html
Now we'll see how to obtain the value of this particular property in code in two different ways.
To retrieve a property from the property files, you use Guice's @Inject
annotation with additional @Named
annotation.
As a parameter for @Named
annotation, you use name of the property, as stated in the property file.
Here is an example:
import com.google.inject.Inject;
import com.google.inject.name.Named;
//..
@Inject
@Named("homepage.url")
private String homepageUrl;
//..
It is also possible to inject Properties instance. This instance is initialized by Bobcat and contains all the properties that Bobcat found in the property files. Example:
@Test
public class MyTest{
// ...
@Inject
private Properties properties;
// ...
}
Example usage:
public void myTestCase() {
//..
String homepageUrl = (String) properties.get("homepage.url");
bobcatWait.withTimeout(Timeouts.MEDIUM).until(
ExpectedConditions.urlToBe(homepageUrl));
//..
}
The following code is responsible for getting property object of given key:
properties.get("homepage.url")
As this property is a String, class cast is safe.
- Configuring Bobcat
- Selenium enhancements
- Cucumber enhancements
- Traffic analyzer
- Email support
- Reporting
- Cloud integration
- Mobile integration
- Executing tests on different environments
- Working with multiple threads
- Tips and tricks
- Authoring tutorial - Classic
- AEM Classic Authoring Advanced usage
- Siteadmin
- Sidekick
- Aem Component
- Working with author pages
- Working with Publish pages
- Advanced component interactions
- Working with Context Menu
- Using Aem Content Tree
- Aem Content Finder
- Storing component configurations
- Working with packages
- Jcr Support
- Authoring tutorial - Touch UI
- Adding and editing a component
- Sites management tutorial