Automate Gherkin tests

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

Gherkin automation process

The following components are involved in automating Gherkin tests:

Component Process
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.
CI system Run the test as a part of a build/pipeline run

There are several different flows, depending on the stage of development and your role.

Stage and Role Flow
Admin

The following is a one-time flow for admins:

  1. Install the ALM Octane CI plugin.

  2. Create a build job that reports Gherkin test results.

  3. Create a pipeline.

Developer

Configure the automation project (octane-cucmber-jvm library and other settings).

Single Test Automation

The following is a single test automation flow that can be configured for each test run:

  1. Download the test (via ALM Octane or IDE plugin).

  2. Add the automation code.

  3. Commit changes.

  4. Perform pipeline runs in the CI.

  5. Results are imported to ALM Octane.

  6. See results in ALM Octane - status becomes Automated.

Back to top

Prerequisites

Ensure the following prerequisites are met:

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

Configure your project

Note: You can use the following procedure to enable BDD test result injection in ALM Octane versions earlier than 16.0.200. This method is limited to Cucumber-jvm up to version 4.8.1, and JBehave.

Beginning with ALM Octane version 16.0.200, there is a more advanced method that can be used to inject test results by all major BDD frameworks, which does not require any change to your code. For details, see Inject BDD test results to ALM Octane.

Depending on your integration, configure the following in your project:

  • Cucumber. 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 (supported for Java environments only). For configuration details, see octane-cucumber-jvm.

  • JBehave. Configure the octane-jbehave-gherkin-reporter in your project, as described in octane-jbehave-gherkin-reporter. When running the tests, the reporter outputs files with the results. The ALM Octane plugin for CI reads these files and uploads the results back to ALM Octane.

  • Azure DevOps Server. To enable injection of Gherkin test results from Azure DevOps Server, configure the octane-azure-devops-extension as described in octane-azure-devops-extension. For details, see "Displaying Cucumber Gherkin test results" in the file HowToInstall.docx.

Back to top

Create a build job in your CI

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

If required by your CI, add a post-build step to copy the test results to the job folder. For example, in Jenkins, add an ALM Octane Cucumber test reporter step from the actions section.

    Note:
  • If you add an ALM 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 CI Server must be configured with sufficient memory to inject large Cucumber test results. For example, for Jenkins, the minimum recommended memory is 2 GB.

The post-build action instructs the CI to copy the test results XML files from the path specified in the post-build actions to the 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, your CI 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

Unique Gherkin tests and test runs

Unique automated Gherkin tests and test runs are identified in the following manner:

Unique Gherkin tests

ALM Octane identifies each Gherkin test in ALM Octane by its script feature's tag, if one exists. The tag exists if the Gherkin test was downloaded from ALM Octane at some point. The script has a tag that contains the test ID and revision in a format like this: @TID4002REV0.2.0.

When ALM Octane receives a Gherkin test run, it checks these attributes to associate the run with a specific Gherkin test. If no existing Gherkin test matches the run, ALM Octane creates a new automated Gherkin test entity.

Unique Gherkin test runs

Each Gherkin test can have more than one run, each uniquely identified by test (which was uniquely identified by its tag or path), pipeline, suite run id, external run id. This is in addition to the fields that define a Last Run: Release, Milestone, Program, and Environment. For details, see Last runs.

ALM Octane stores the details of the Gherkin automated run for each unique combination of these attributes. Each run accumulates its own history of Previous Runs.

For example, if a Gherkin test was run on Chrome and Firefox in two different pipelines, the Gherkin test would have four Gherkin automated runs. Two of these runs would be considered last runs.

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 right syntax: Cucumber does not always indicate syntax errors. Run your 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 Configure your 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 plugin is installed and configured on the CI server. For details, see Install and configure the 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:

    ALM Octane Cucumber test reporter: Got result file content
    ALM 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.

Example: 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

See also: