Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Properties injection

Mikołaj Mański edited this page Jul 13, 2016 · 9 revisions

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.

Named properties

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;
//..
 

Injecting Properties class

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.

Getting started with Bobcat

  1. Getting started

AEM Related Features

  1. Authoring tutorial - Classic
  1. AEM Classic Authoring Advanced usage
  1. Authoring tutorial - Touch UI
Clone this wiki locally