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

ScenarioContext

kkarolk edited this page Jul 22, 2016 · 5 revisions

Scenario context

In some cases you may want to share some state between scenario steps but only in a particular scenario context. This is when ScenarioContext comes with help. ScenarioContext is a communication channel between scenario steps. It was implemented as a HashMap where one step is storing information for other steps. Let's consider that we have scenario steps implementation in two different classes. If we want to share some information between two classes we can just inject ScenarioContext in both classes:

@ScenarioScoped
public class AuthorPageSteps {

@Inject
private ScenarioContext scenarioContext;
//...
  @When("^I build a \"([^\"]*)\" configuration with ComponentConfigBuilder$")
  public void iBuildAConfigurationWithComponentConfigBuilder(String configName) {
    List<ConfigurationEntry> config = new ComponentConfigBuilder()
        .setTab("Tab1")
        .add("text field", "Text Field", "textfield")
        .add("path field", "Path Field", "Node1/Node2/Node3")
        .build();

    scenarioContext.add(configName, config);
  }
//...
}
@ScenarioScoped
public class AuthorPageStepsSidekick {

@Inject
private ScenarioContext scenarioContext;
//...
  @When("^I use the \"([^\"]*)\" configuration from JSON$")
  public void iUseTheConfigurationFromJSON(String configName) {
    ComponentConfig config = new JsonToComponentConfig().readConfig(configName);
    scenarioContext.add(configName, config.getConfig());
  }
//...
}

As you can see ScenarioContext class has built-in helpers for getting String's and List's and other types. If you want to learn more about ComponentConfigBuilder and different ways if storing component configurations please refer to Storing component configurations tutorial.

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