Plugins

Plugins are extensible and flexible mechanism for development. New plugin can be developed by 3rd party team and integrated.

The plugin configuration should be placed at the /src/main/resources/spring.xml path relatively to the project root.

Example 1. /src/main/resources/spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd"
       default-lazy-init="true">

    <!-- plugin bean definitions -->

</beans>

Table Transformers

In order to create and register own table transformer the following steps should be done.

  1. Create a new class that implements org.jbehave.core.model.TableTransformers.TableTransformer:

    Example 2. /src/main/java/com/mycompany/transformer/MyTableTransformer.java
    package com.mycompany.transformer;
    
    import org.jbehave.core.model.TableTransformers.TableTransformer;
    
    public class MyTableTransformer implements TableTransformer
    {
        @Override
        public String transform(String tableAsString, TableParsers tableParsers, TableProperties properties)
        {
            String transformedTable = ...; // Table transformation logic
            // ...
            return transformedTable;
        }
    }
  2. Register Spring bean where id is the name of the transformer which will be used to refer it in tests:

    Example 3. /src/main/resources/spring.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="MY_TRANSFORMER" class="com.mycompany.transformer.MyTableTransformer"/>
    
    </beans>
  3. Use new transformer in tests:

    Example 4. /src/main/resources/story/MyStory.story
    Scenario: Use the custom tramsfomer to modify ExamplesTable
    Given ...
    When ...
    Then ...
    Examples:
    {transformer=MY_TRANSFORMER}
    |header |
    |value 1|
    |value 2|

It’s recommended to stick to the following naming conventions:

  • SCREAMING_SNAKE_CASE for transfomer names:

    {transformer=MY_TRANSFORMER}
  • lowerCamelCase for transformer parameters:

    {transformer=MY_TRANSFORMER, transformerParameter=value}
  • kebab-case with dot . as a separator for transformer bean properties:

    transformer.my-transformer.my-property=value

    Pay attention to the property format:

    transformer.<custom-transform-name>.<property-name>=<property-value>

Dynamic variables

In order to create and register own dynamic variable the following steps should be done.

  1. Create a new class that implements org.vividus.variable.DynamicVariable:

    Example 5. /src/main/java/com/mycompany/variable/MyDynamicVariable.java
    package com.mycompany.variable;
    
    import org.vividus.variable.DynamicVariable;
    import org.vividus.variable.DynamicVariableCalculationResult;
    
    public class MyDynamicVariable implements DynamicVariable
    {
        @Override
        public DynamicVariableCalculationResult calculateValue()
        {
            try
            {
                String value = ...; // Variable value calcualtion
                return DynamicVariableCalculationResult.withValue(value);
            }
            catch (MyException e)
            {
                return DynamicVariableCalculationResult.withError(e.getMessage());
            }
        }
    }
  2. Register Spring bean where id is the name of the dynamic variable which will be used to refer it in tests:

    Example 6. /src/main/resources/spring.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
    
        <bean id="my-dynamic-varibale" class="com.mycompany.variable.MyDynamicVariable"/>
    
    </beans>
  3. Use new variable in tests:

    Example 7. /src/main/resources/story/MyStory.story
    Scenario: Validate with help of the custom dynamic variable
    Then `${my-dynamic-varibale}` is equal to `my app specific value`

    Keep in mind the alias for the dynamic variable with name in lower camel case will be available out of the box:

    Example 8. /src/main/resources/story/MyStory.story
    Scenario: Validate with help of the custom dynamic variable
    Then `${myDynamicVaribale}` is equal to `my app specific value`