Automate Gherkin tests

In ALM Octane, you can designate Gherkin tests for automation. This allows you to download the test script as a .feature file in a JUnit TestRunner project and use the feature files to create Cucumber tests.

Gherkin automation process

You use several components to automate Gherkin tests:

Component Purpose
ALM Octane Save the test, test scripts, and analyze the results
Your IDE Implement automation for the feature file as part of a JUnit Runner project
Jenkins CI system Runs the test as a part of a build/pipeline run

Prerequisites

Before you can run Gherkin tests automatically as part of your CI process, you need to ensure that the appropriate plugins are installed and you are using the correct versions of the plugins and environments.

  • Make sure that the ALM Octane CI plugin is properly installed and configured on the CI server. For details, see Integrate with your CI server.

  • Gherkin tests use the Cucumber library. Use the JUnit Runner to run the Cucumber-JVM library. For details, see https://cucumber.io/docs/reference/jvm#junit-runner.

  • Use the following versions of the tools specified below:

    Cucumber-JVM 1.2.4 or higher
    JUnit Runner 4.12 or higher
    Java Runtime Environment (JRE) 1.8.0_91
    Java compile warning level 1.8

Add the Octane-JVM class to your Cucumber tests

For the CI server to generate a report after the test runs, you must add the Octane-JVM class in your project. This enables the CI server to find and locate the report after the build job and test run are complete.

  1. In your project, add this dependency in your POM file:

    <dependencies>
        <dependency>
            <groupId>com.hpe.alm.octane</groupId>
            <artifactId>octane-cucumber-jvm</artifactId>
            <version>12.53.8</version>
        </dependency>
    </dependencies>

    Enter a <version> tag based on the version of ALM Octane you are using:

    ALM Octane version <version> tag
    ALM Octane versions 12.53.8 until 12.53.15 12.53.8
    ALM Octane versions 12.53.16 until 12.53.18 12.53.16
    ALM Octane version 12.53.19 and higher 12.53.19
  2. In your JUnit Runner .java file, import the octane-cucumber-jvm class:

    import com.hpe.alm.octane.OctaneCucumber;
  3. In the JUnit Runner .java file, change the cucumber.class to OctaneCucumber.class:

    Package feature.manualRunner;
    
    import com.hpe.alm.octane.OctaneCucumber;
    import cucumber.api.CucumberOptions;
    import org.junit.runner.RunWith;
    
    @RunWith(OctaneCucumber.class)
    @CucumberOptions(plugin={"junit:junitResult.xml"},
        features="src/test/resources/feature/manualRunner") 
    public class ManualRunnerTest{
    
    }

Create a build job in Jenkins

In your Jenkins build job configuration, add a build step that runs the test.

In the post-build actions section, you need to add multiple steps:

  • A Publish JUnit test result report action. This enables Jenkins to find the appropriate results file for use in ALM Octane.

  • A HPE Octane Cucumber test reporter step. This step enables you to specify the folders where the XML files containing the report are found. When the pipeline containing the build job runs, ALM Octane searches the specified folders for these XML files.

As part of the build job in Jenkins, the results from the Publish JUnit test run result are ignored by the HPE ALM Octane CI plugin - only the HPE Octane Cucumber test report step results are passed to ALM Octane later during the pipeline run.

Add the build job to a pipeline

Ensure that your build project or build job that runs the test is included in an ALM Octane pipeline. When you run the pipeline, Jenkins generates the test results, and the Jenkins plugin reads the results file and sends the details to ALM Octane.

For details on creating and working with pipelines, see Create and configure pipelines and Create and configure pipelines in the Jenkins UI.

Back to top

Run the pipeline

  1. In ALM Octane or in the CI server, run the pipeline.

    As part of the process, the CI server sends the results, using the HPE ALM Octane CI Plugin.

    ALM Octane links the test results to the original Gherkin tests, according to the Test ID tags found at the top of the .feature file and the test script in ALM Octane, depending on these criteria:

    • If the test already exists in ALM Octane and the Test ID tag is included in the .feature file, the mapping is done by the Test ID tag.

    • If the Test ID tag is not included in the .feature file, the mapping is done by the .feature script path.

    • If the test does not exist in ALM Octane, the system will automatically create a new test in ALM Octane and will map the results to it.

    If the test results come in to ALM Octane as a separate file, this is a sign that the OctaneGherkinResults xml file could not be found.

  2. Analyze the results in ALM Octane. Analyze the coverage of your features, the latest run results, and the automation status of the Gherkin tests.

Back to top

Next steps: