Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Your specification is made using Gherkin (i.e. Given, When, That) statements in Scenario(s) or Scenario Outline(s), eventually complemented with a Background. Implementation of each Gherkin statement (i.e. "step") is done in code; the Cucumber framework finds the code based on regular or cucumber expressions.


Note
iconfalse
titleSource-code for this tutorial
typeInfo

Code is available in GiHub; the repo contains some auxiliary scripts.

Usage scenarios

Cucumber is used in diverse scenarios. Next you may find some usage patterns, even though Cucumber usage is mostly recommended only if you are adopting BDD.

...

  • use one of the available CI/CD plugins (e.g. see details of Integration with Jenkins)
  • use the REST API directly (more info here)
    • Code Block
      languagebash
      titleexample of a shell script to export/generate .features from Xray
      collapsetrue
      #!/bin/bash
       
      token=$(curl -H "Content-Type: application/json" -X POST --data @"cloud_auth.json" https://xray.cloud.xpand-itgetxray.comapp/api/v1v2/authenticate| tr -d '"')
      curl -H "Content-Type: application/json" -X GET -H "Authorization: Bearer $token" "https://xray.cloud.xpand-itgetxray.comapp/api/v1v2/export/cucumber?keys=CALC-640;CALC-641" -o features.zip
       
      rm -rf features/*.feature
      unzip -o features.zip -d features
  • ... or even use the UI (e.g. from a Test issue)

...

After being exported, the created .feature(s) will contain references to the Test issue key, eventually prefixed (e.g. "TEST_") depending on an Xray global setting, and the covered "requirement" issue key,  if that's the case. The naming of these files is detailed in Export Generate Cucumber Features.

Code Block
titlefeatures/2_CALC-640.feature
collapsetrue
@REQ_CALC-640
Feature: As a user, I can calculate the sum of 2 numbers
	#As a user, I can calculate the sum of 2 numbers

	#simple integer addition
	@TEST_CALC-642
	Scenario: simple integer addition
		Given I have entered 1 into the calculator
		And I have entered 2 into the calculator
		When I press add
		Then the result should be 3 on the screen

	#negative integer addition
	@TEST_CALC-643
	Scenario: negative integer addition
		Given I have entered -1 into the calculator
		And I have entered 2 into the calculator
		When I press add
		Then the result should be 1 on the screen

	#sum of two positive numbers
	@TEST_CALC-644
	Scenario Outline: sum of two positive numbers
		Given I have entered <input_1> into the calculator
		And I have entered <input_2> into the calculator
		When I press <button>
		Then the result should be <output> on the screen
		
		  Examples:
		    | input_1 | input_2 | button | output |
		    | 20      | 30      | add    | 50     |
		    | 2       | 5       | add    | 7      |
		    | 0       | 40      | add    | 40     |
		    | 4       | 50      | add    | 54     |
		    | 5       | 50      | add    | 55     |

...

Code Block
languagebash
titleexample of a Bash script to import results using the standard Cucumber endpoint
collapsetrue
#!/bin/bash
 
BASE_URL=https://xray.cloud.xpand-itgetxray.comapp
token=$(curl -H "Content-Type: application/json" -X POST --data @"cloud_auth.json" "$BASE_URL/api/v1v2/authenticate"| tr -d '"')
curl -H "Content-Type: application/json" -X POST -H "Authorization: Bearer $token"  --data @"merged-test-results.json" "$BASE_URL/api/v1v2/import/execution/cucumber"

...

Code Block
languagebash
titleexample of a shell script to import/synchronize .features to Jira and Xray
collapsetrue
#!/bin/bash
BASE_URL=https://xray.cloud.xpand-itgetxray.comapp
PROJECT=CALC

rm -f features.zip
zip -r features.zip src/test/resources/calculator/ -i \*.feature

token=$(curl -H "Content-Type: application/json" -X POST --data @"cloud_auth.json" "$BASE_URL/api/v1v2/authenticate"| tr -d '"')
curl -H "Content-Type: multipart/form-data" -H "Authorization: Bearer $token"  -F "file=@features.zip" "$BASE_URL/api/v1v2/import/feature?projectKey=$PROJECT"

...

  • use one of the available CI/CD plugins (e.g. see details of Integration with Jenkins)
  • use the REST API directly (more info here)
    • Code Block
      languagebash
      titleexample of a shell script to export/generate .features from Xray
      collapsetrue
      #!/bin/bash
       
      token=$(curl -H "Content-Type: application/json" -X POST --data @"cloud_auth.json" https://xray.cloud.xpand-itgetxray.comapp/api/v1v2/authenticate| tr -d '"')
      curl -H "Content-Type: application/json" -X GET -H "Authorization: Bearer $token" "https://xray.cloud.xpand-itgetxray.comapp/api/v1v2/export/cucumber?keys=CALC-640;CALC-641" -o features.zip
       
      rm -rf features/*.feature
      unzip -o features.zip -d features
  • ... or even use the UI (e.g. from a Test issue)

...

After being exported, the created .feature(s) will contain references to the Test issue key, eventually prefixed (e.g. "TEST_") depending on an Xray global setting, and the covered "requirement" issue key,  if that's the case. The naming of these files is detailed in Export Generate Cucumber Features.

Code Block
titlefeatures/2_CALC-640.feature
collapsetrue
@REQ_CALC-640
Feature: As a user, I can calculate the sum of 2 numbers
	#As a user, I can calculate the sum of 2 numbers

	#simple integer addition
	@TEST_CALC-642
	Scenario: simple integer addition
		Given I have entered 1 into the calculator
		And I have entered 2 into the calculator
		When I press add
		Then the result should be 3 on the screen

	#negative integer addition
	@TEST_CALC-643
	Scenario: negative integer addition
		Given I have entered -1 into the calculator
		And I have entered 2 into the calculator
		When I press add
		Then the result should be 1 on the screen

	#sum of two positive numbers
	@TEST_CALC-644
	Scenario Outline: sum of two positive numbers
		Given I have entered <input_1> into the calculator
		And I have entered <input_2> into the calculator
		When I press <button>
		Then the result should be <output> on the screen
		
		  Examples:
		    | input_1 | input_2 | button | output |
		    | 20      | 30      | add    | 50     |
		    | 2       | 5       | add    | 7      |
		    | 0       | 40      | add    | 40     |
		    | 4       | 50      | add    | 54     |
		    | 5       | 50      | add    | 55     |

...

Code Block
languagebash
titleexample of a Bash script to import results using the standard Cucumber endpoint
collapsetrue
#!/bin/bash
 
BASE_URL=https://xray.cloud.xpand-itgetxray.comapp
token=$(curl -H "Content-Type: application/json" -X POST --data @"cloud_auth.json" "$BASE_URL/api/v1v2/authenticate"| tr -d '"')
curl -H "Content-Type: application/json" -X POST -H "Authorization: Bearer $token"  --data @"merged-test-results.json" "$BASE_URL/api/v1v2/import/execution/cucumber"

...