Verisoft Wiki

To integrate Spring-Cucumber with your infrastructure repository, follow these steps:

The Infrastructure has two dictionaries:

  1. For API testing
  2. For UI testing

In order to run Cucumber scripts with the verisoft infrastructure, steps 1-7 must be performed
To create a dictionary for a specific project beyond the dictionaries in the infrastructure, steps 8-10 must also be added

Configuration:
Step 1: Add Dependency
Step 2: Implement Base Dictionary
Step 3: Configure Spring Beans
Step 4: Create Spring Configuration for Cucumber
Write and run tests:
Step 5: Create Feature File (in test/resources/Features)
Step 6: Create JUnit Test File
Step 7: Run JUnit Test Class
Extend the dictionary with your own steps:
Step 8: add a interface with your functions
Step 9:  implement it with step defintions using "bridge" design pattern
Step 10:  Implement your extra-steps in the dictionary implementation class

Step 1: Add Dependency
Ensure you have the following dependency in your pom.xml:

<dependency>
    <groupId>co.verisoft</groupId>
    <artifactId>Selenium4-Junit5</artifactId>
    <version>latest</version>            
</dependency>

 Step 2: Implement Base Dictionary

Implementation for each dictionary

UI:

public class BaseUIDictionaryImpl implements BaseDictionary,ExtendedActions{

    @Override
    public void userOnPage(String pageName) {
        System.out.println("Implementation of function userOnPage");
    }
    
    @Override
    public void uploadDriver() {
        System.out.println("Implementation of function uploadDriver");
    }
    //override all of the dictionary functions
}

API:

public class BaseAPIDictionaryImpl implements APIDictionary{

    @Override
    public void initCertificates(String s, String s1) {
        System.out.println("implement method initCertificates");
    }

    @Override
    public void setHeaders(Map<String, String> map) {
        System.out.println("implement method setHeaders");
    }
    //override all of the dictionary functions
}

Step 3: Configure Spring Beans
Create “CucumberSpringConfig.java” for Spring bean configuration:

package co.verisoft.fw.cucumber;
import org.springframework.context.annotation.*;

@Configuration
public class CucumberSpringConfig {
    
    @Bean
    @Profile("UI")
    public BaseDictionary baseUIDictionaryImpl() {return new BaseUIDictionaryImpl();}

    @Bean
    @Profile("API")
    public APIDictionary baseAPIDictionaryImpl() {return new BaseAPIDictionaryImpl();}
}

 Step 4: Create Spring Configuration for Cucumber
Create “CucumberSpringConfiguration.java”: (the context configuration class name is the spring beans class)

package co.verisoft.fw.cucumber;
import io.cucumber.spring.CucumberContextConfiguration;
import org.springframework.test.context.ContextConfiguration;

@CucumberContextConfiguration
@ContextConfiguration(classes = CucumberSpringConfig.class)
public class CucumberSpringConfiguration {}

Step 5: Create Feature File (in test/resources/Features)
Create a “feature” file, for example, “exampleScenario.feature”:

Feature: exampleScenario

  Scenario: example scenario test
    Given user on "login" page
    When user taps on "login" button
    Then user should see the title "Welcome Home"

attach the sign ":" to the previous word otherwise the test will not run

   
 Step 6: Create JUnit Test File
Create a JUnit test file, “ExampleTest.java”:

@ExtentReport
public class ExampleCucumberTest extends CucumberBaseTest {

    @Test
    public void exampleTest1() { executeTest(new Scenario("example of UI scenario test"),new FeatureFile("exampleCucumber"),new Dictionary("UI"));}

    @Test
    public void exampleTest2() { executeTest(new Scenario("example of UI scenario test"),new FeatureFile("exampleCucumber"));}

    @Test
    public void exampleTest3() {executeTest(new Scenario("example scenario that use with mix of dictionaries test"));}

    @Test
    public void exampleTest4() { executeTest(new Scenario("example scenario API test"),new FeatureFile("exampleCucumber"), new Dictionary("API"));}
}

 Step 7: Run JUnit Test Class
Run the JUnit test class “ExampleTest” (for example) to execute the tests with the infrastructure setup.
 
Test Execution Options
You have 8 options to execute the test:

The function An example of use
public void executeTest(Scenario scenarioName, FeatureFile featureFileName, Dictionary dictionaryImplementationProfile, PackageName packageName) executeTest(new Scenario("Successful login"),new FeatureFile("login"), new Dictionary("implementation2"), new PackageName("co.verisoft.fw.cucumber1"))
public void executeTest(Scenario scenarioName, FeatureFile featureFile,Dictionary dictionaryImplementationProfile) executeTest(new Scenario("Successful login"),new FeatureFile("login"), new Dictionary("implementation2"));
public void executeTest(Scenario scenarioName, FeatureFile featureFile,PackageName packageName) executeTest(new Scenario("Successful login"),new FeatureFile("login"), new PackageName("co.verisoft.fw.cucumber1"));
public void executeTest(Scenario scenarioName,Dictionary dictionaryImplementationProfile, PackageName packageName) executeTest(new Scenario("Successful process of taking a digital loan"), new Dictionary("implementation2"), new PackageName("co.verisoft.fw.cucumber1"))
public void executeTest(Scenario scenarioName, Dictionary dictionaryImplementationProfile) executeTest(new Scenario("Successful process of taking a digital loan"), new Dictionary("implementation2"));
public void executeTest(Scenario scenarioName, PackageName packageName) executeTest(new Scenario("Successful process of taking a digital loan"), new PackageName("co.verisoft.fw.cucumber1"));
public void executeTest(Scenario scenarioName, FeatureFile featureFile ) executeTest(new Scenario("Successful login"), new FeatureFile("login"));
public void executeTest(Scenario scenarioName) executeTest(new Scenario("Successful process of taking a digital loan"));

Defaults:

For Dictionary:
Configure the “application.properties” as needed, for example:
dictionary.implementation.profile = baseUIDictionaryImpl

For Package Name: (of the dictionary and dictionary implementation)
co.verisoft.fw.cucumber

For Feature File Name
The Junit class name, for example- for "TransferTest.java" the default feature file is "transfer.feature"

For Extending the dictionary with your own steps:
 
Step 8: add a interface with your functions

package co.verisoft.fw.cucumber;

public interface ExtendedActions {
    void performAction(String actionId);
}

Step 9:  implement it with step defintions using "bridge" design pattern

package co.verisoft.fw.cucumber;

import io.cucumber.java.en.When;
import org.springframework.beans.factory.annotation.Autowired;

public class DictionarySteps implements ExtendedActions {

private final ExtendedActions extendedActions;

 @Autowired
public DictionarySteps(ExtendedActions extendedActions) {
 this.extendedActions = extendedActions;
}

 @When("I perform an extended action {string}")
public void performAction(String action) {
 extendedActions.performAction(action);
}}

Step 10:  Implement your extra-steps in the dictionary implementation class

public class BaseDictionaryImpl implements BaseDictionary, ExtendedActions{
//implement the base dictionary functions
//...
@Override
public void performAction(String actionId) {
    System.out.println("implement method perform action");
}}

This setup ensures your tests run seamlessly with the specified scenario, implementation, feature file, and package configurations.