Automate Gherkin tests

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

Gherkin automation process

The following components are involved in automating Gherkin tests.

Component Process
OpenText Core Software Delivery Platform
  • 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 or pipeline run

The components involved in automating Gherkin tests.

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 OpenText Core Software Delivery Platform 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 (using OpenText Core Software Delivery Platform or IDE plugin).

  2. Add the automation code.

  3. Commit changes.

  4. Perform pipeline runs in the CI.

  5. Results are imported to OpenText Core Software Delivery Platform.

  6. See results - status becomes Automated.

Back to top

Prerequisites

Make sure that the following prerequisites are met:

  • The Application Automation Tools plugin is installed and configured on the CI server. For details, see CI server integration.

  • Your automation project is set up as a Cucumber project.

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. If necessary, create and add scenarios to your Gherkin test. For details, see Create Gherkin tests.

  2. In the test's Script tab, click the Download script button .

    The script is downloaded as a .feature file.

    Note: Do not delete the Test ID tag; it is used to map the automation results.

  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 OpenText Core Software Delivery Platform versions earlier than 16.0.200. This method is limited to Cucumber-jvm up to version 4.8.1, and JBehave.

Beginning with OpenText Core Software Delivery Platform 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.

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

Integration Description
Cucumber To generate a Cucumber-based test results file that the CI server sends to OpenText Core Software Delivery Platform, 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 OpenText Core Software Delivery Platform plugin for CI reads these files and uploads the results back to OpenText Core Software Delivery Platform.

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 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 a OpenText Core Software Delivery Platform Cucumber test reporter step from the actions section.

Note:  

  • If you add a OpenText Core Software Delivery Platform 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. The results are copied from this build folder to OpenText Core Software Delivery Platform.

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 a 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 OpenText Core Software Delivery Platform.

For details on creating and working with pipelines, see Create and configure pipelines.

Back to top

Run the pipeline

To send the results to OpenText Core Software Delivery Platform, you must run the corresponding pipeline.

To run the pipeline:

  1. In OpenText Core Software Delivery Platform or in the CI server, run the pipeline.

    The test results are linked to the original Gherkin tests using the Test ID tags found at the top of the .feature file and the test script in OpenText Core Software Delivery Platform. The test is assigned using these criteria:

    • If the test already exists in OpenText Core Software Delivery Platform 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 OpenText Core Software Delivery Platform, a new test is created and the results are mapped to it.

  2. Analyze the results in OpenText Core Software Delivery Platform

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

Each Gherkin test is identified by its script feature's tag, if one exists. The tag exists if the Gherkin test was downloaded from OpenText Core Software Delivery Platform at some point. The script has a tag that contains the test ID and revision in a format like this: @TID4002REV0.2.0.

When OpenText Core Software Delivery Platform 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, a new automated Gherkin test entity is created.

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, and 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.

The details of the Gherkin automated run are stored 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.

Unable to see the automated test that I ran

  1. Check your code. Make sure that you are using the correct 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 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 CI server integration.
  4. Check the job's console log to make sure that the post-build action found the XML:

    OpenText Core Software Delivery Platform Cucumber test reporter: Got result file content
    OpenText Core Software Delivery Platform 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 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). 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: