JBehave MostUsefulConfiguration [ 2024 ]
JBehave MostUsefulConfiguration
In this post, we will discuss JBehave’s MostUsefulConfiguration. This configuration works for most situations. Most of the elements are configured with this configuration. However, we can change these configuration elements if we don’t like the default ones. It extends from an abstract class, Configuration.
Configuration Abstract class
The Configuration class is used by the Embedder and the in the Embeddable implementations to customize it’s runtime properties. It implements a Builder pattern so that each element of the configuration can be specified individually, and read well. All elements have default values, which the use methods can override. The use methods allow to override the dependencies one by one.
Class Diagram
More Information here:
If we need custom based components, we can extend Configuration to provide custom components.
For example:
public class CustomConfiguration extends Configuration { … }
Another example is SeleniumConfiguration. It extends Configuration to provide Selenium-based components. It can be used for both Selenium and WebDriver API as shown below.
public class SeleniumConfiguration extends Configuration {…
We may need to override the parent class method.
Sample code snippet
@Override public Configuration configuration() { return new SeleniumConfiguration() .useWebDriverProvider(driverProvider) .useSeleniumContext(seleniumContext).useFailureStrategy( new FailingUponPendingStep()) .useStoryControls(new StoryControls().doResetStateBeforeScenario(false) .doIgnoreMetaFiltersIfGivenStory(true)) .useStoryLoader(new LoadFromClasspath(this.getClass().getClassLoader())) .useStoryReporterBuilder(new MyStoryReporter() .withCodeLocation(CodeLocations.codeLocationFromPath(getClassPath())) .withDefaultFormats() .withFormats(Format.CONSOLE, Format.HTML)); }
JBehave Tutorials on this website can be found at:
https://www.testingdocs.com/jbehave-framework-tutorial/
For more details on the JBehave framework, visit the official JBehave website at:
http://jbehave.org