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`

Baseline storages

Baseline storage is a source of the baseline images used to perform visual checks in visual testing plugin

In order to create and register own baselines storages the following steps should be done

  1. Create a new class that implements org.vividus.visual.engine.BaselineStorage:

    Example 9. /src/main/java/com/mycompany/visual/engine/AzureBaselineStorage.java
    package com.mycompany.visual.engine;
    
    import org.vividus.visual.engine.BaselineStorage;
    
    public class AzureBaselineStorage implements BaselineStorage
    {
        @Override
        public Optional<Screenshot> getBaseline(String baselineName) throws IOException
        {
            // gets the baseline screenshot
        }
    
        @Override
        public void saveBaseline(Screenshot toSave, String baselineName) throws IOException
        {
            // saves the baseline screenshot
        }
    
    }
  2. Register Spring bean where id is the name of the baseline storage which will be used in visual testing plugin:

    Example 10. /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="azure" class="com.mycompany.visual.engine.AzureBaselineStorage"/>
    
    </beans>