Automate Gherkin tests

Create automated tests from your ALM Octane Gherkin tests, add them to an automation project and run them in your CI server builds.

Note: ALM Octane supports Cucumber-jvm 1.2.x only.

Gherkin automation process

The following components are involved in automating Gherkin tests:

Component What do I do here?
ALM Octane
  • Create Gherkin tests
  • Download test scripts to be uploaded to the IDE
  • View automated test run results and analyze them
Your IDE Add automation for the test, through a .feature file included in a JUnit Runner automation project.
Jenkins CI system Run the test as a part of a build/pipeline run

The entire process follows this flow:

Back to top

Prerequisites

Back to top

Create and download the Gherkin test

To work with a Gherkin test in your IDE, you must create the test.

To create and download the test:

  1. In ALM Octane, if necessary create and add scenarios to your Gherkin test. For details, see Create Gherkin tests.

  2. In the Scripts tab of the test, click the Download script button.

    The script is downloaded as a .feature file.

    Note: ALM Octane uses the Test ID tag to map the automation results. DO NOT DELETE the Test ID tag!

  3. Add the .feature file to your automation project.

Back to top

Add the OctaneCucumber runner class to your automation project

To generate a Cucumber-based test results file that the CI server sends to ALM Octane, add the octane-cucumber-jvm library to your automation project and use the OctaneCucumber class as the test runner for your test classes.

The octane-cucumber-jvm library is supported for use on Java environments only.

To add the Cucumber classes:

  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.55.7</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 until 12.53.21 12.53.19
    ALM Octane version 12.53.22 until 12.55.6 12.53.22
    ALM Octane versions 12.55.7 and higher 12.55.7
  2. In your JUnit Runner .java file, import the Octane Cucumber runner 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{
    
    }

Back to top

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, add an HPE Octane Cucumber test reporter step.

Note: If you add an HPE Octane Cucumber test reporter step, the CI server sends only the Gherkin test results to Octane. Test results from other automated tests are not sent as part of the build.

The post-build action instructs Jenkins to copy the test results XML files from the path specified in the post-build actions to the Jenkins job build folder. From this build folder, the results are copied to ALM Octane.

During the test run in the CI server, the OctaneCucumber runner generates a run results report called <test name>_OctaneGherkinResults.xml in a dedicated folder called gherkin_results.

Note: If you are using the octane-cucumber-jvm library version 12.53.19 and earlier, the file name of the results is called OctaneGherkinResults.xml.

If the post-build Cucumber test report step fails, the CI server fails the entire build.

Back to top

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. The Application Automation Tools 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.

Back to top

Run the pipeline

To send the results to ALM Octane, you must run the corresponding pipeline.

To run the pipeline:

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

    ALM Octane links the test results to the original Gherkin tests. ALM Octane uses the Test ID tags found at the top of the .feature file and the test script in ALM Octane ALM Octane assigns the test using these criteria:

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

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

    • If the test does not exist in ALM Octane, the system creates a new test in ALM Octane and maps the results to it.

  2. Analyze the results in ALM Octane

Back to top

Troubleshooting

This section contains troubleshooting suggestions for issues relating to running automated Gherkin tests.

I ran the automated test but I cannot see it in ALM Octane

  1. Check your code. Make sure that you are using correct syntax (Cucumber does not always indicate syntax errors). Run you test locally.
  2. If you were able to run the test locally, check that an XML was generated.

    Check that your POM file is defined properly and includes the octane-cucumber-jvm library along with the correct version and make sure that OctaneCucumber is defined as the runner in your test class. For details, see Add the OctaneCucumber runner class to your automation project. If both POM file and test class have been updated properly and an XML is not generated, contact your ALM Octane support representative.

  3. If the test runs locally, check that the test ran in your CI tool. Make sure the Application Automation Tools Jenkins plugin is installed and configured on the CI server. For details, see Install and configure the ALM Octane CI plugin on your CI server.
  4. Check the job's console to make sure the post build action found the XML. You can see it in the job console log:

    Micro Focus Octane Cucumber test reporter: Got result file content
    Micro Focus Octane Cucumber test reporter: Result file copied to …
  5. Check the plugin logs. They should display: 

    Successfully pushed test results of build [<build name>#<build number>]
  6. Check the server logs for errors. XSD validation errors are common.

I ran the test X times, but instead of seeing X runs in ALM Octane under a single test, I see X tests with one run each

Check that the test script in the .feature file includes the test ID (TID) generated by ALM Octane. The test ID is required for mapping automation results. If the TID is missing, download the test script and implement it again.

Back to top

Next steps: