BDD Testing Framework (Cucumber integration)

Add Feature Files

For the best performance, please clean up the Katalon workspace frequently. Navigate to File > Clean up.

Features File is located within 'Include/'features' folder from your project folder and can be seen from Tests Explorer:

The content of Features File will follow BDD conventions (_Given, When, The_n). When creating a new Features File, there will be an option to 'Generate sample Feature template' which will generate a sample template for your Features File. This will ensure that the created Features File matches with BDD convention so that you will reduce efforts in creating Features File in the correct format. 

Let's look at an example of Katalon Demo Cura System (http://demoaut.katalon.com). We want to test the Login feature with a valid and invalid credential so the content will be something like this:

Tags are a great way to organize Features and Scenarios. Read more...

Sample Features File

#Author: your.email@your.domain.com
#Keywords Summary :
#Feature: List of scenarios.
#Scenario: Business rule through list of steps with arguments.
#Given: Some precondition step
#When: Some key actions
#Then: To observe outcomes or validation
#And,But: To enumerate more Given,When,Then steps
#Scenario Outline: List of steps for data-driven as an Examples and <placeholder>
#Examples: Container for s table
#Background: List of steps run before each of the scenarios
#""" (Doc Strings)
#| (Data Tables)
#@ (Tags/Labels):To group Scenarios
#<> (placeholder)
#""
## (Comments)
#Sample Feature Definition Template
@Login
Feature: Login Feature
  
  As a user, I want to login to Cura System
  so that I can make an appointment.

  @Valid
  Scenario Outline: Login with a valid credential
    Given I navigate to Cura System homepage
    When I click Make Appointment button
    And I enter username <username> and password <password>
    And I click Log in button 
	Then I should be able to login successfully

    Examples: 
      | username | password           |
      | John Doe | ThisIsNotAPassword |

  @InValid
  Scenario Outline: Login with an invalid credential
    Given I navigate to Cura System homepage
    When I click Make Appointment button
    And I enter an invalid username <username> and password <password>
    And I click Log in button
	Then I should NOT be able to login successfully

    Examples: 
      | username | password           |
      | Jane Doe | ThisIsNotAPassword |

Maintain Features File

Katalon Studio code inspection will detect and highlight any missing Step Definitions in Features File to help the user create the required step definitions.

There will be cases the current Features File meet one of the following maintenance difficulties:

  • The current format is not organized properly.
  • Figure out which Step Definitions is mapped with current Gherkin step.
  • Recalculate steps in the Features file when there are changes in Step Definitions.

Above difficulties have been handled directly from the context menu of Feature File editor.

Pretty Format

Re-do the format.

Find Step

Find relevant step of current Gherkin step in existing Step Definitions files.

Recalculate steps

Recalculate steps in the Feature file when there are changes in Step Definitions.

Define Steps

Each Gherkin step in the Features file needs to be defined as a set of programming code so that the machine can execute the actions of these steps. These Step Definitions can be implemented in Keyword folder by leveraging the Script Mode. Katalon Studio built-in keywords can also be re-used in step definition files as well. When Katalon Studio executes any Features files in the test case, it will also look for the matching step definitions in the source folder.

Step Definitions can be written in any Cucumber-supported programming languages including Groovy and Java.

For example, let's take the Gherkin scenarios from Features File above and define the steps:

Step Definitions

class MyStepDefinition {

	/**
	 * The step definitions below match with Katalon sample Gherkin steps
	 */

	@Given("I navigate to Cura System homepage")
	def I_navigate_to_Cura_System_homepage() {

		WebUI.openBrowser("http://demoaut.katalon.com")
		//WebUI.waitForPageLoad(30)
	}

	@When("I click Make Appointment button")
	def I_click_makeAppointment_button() {

		WebUI.click(findTestObject('Page_CURA Healthcare Service/a_Make Appointment'))
	}
 
	@And("I enter username (.*) and password (.*)")
	def I_enter_valid_username_password(String username, String password) {

		WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_userName'), username)
		WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_password'), password)
	}
 
	@And("I click Log in button")
	def I_click_login_btn() {

		WebUI.click(findTestObject('Page_CURA Healthcare Service/button_Login'))
	}
 
	@Then("I should be able to login successfully")
	def I_login_successfully() {

		WebUI.click(findTestObject('Page_CURA Healthcare Service/button_Login'))
		WebUI.verifyTextPresent('Make Appointment', false)
		WebUI.closeBrowser()
	}

	@And("I enter an invalid username (.*) and password (.*)")
	def I_enter_invalid_username_password(String username, String password) {
		
		WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_userName'), username)
		WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_password'), password)
	}

 
	@Then("I should NOT be able to login successfully")
	def I_login_unsuccessfully() {

		WebUI.verifyTextPresent('Login failed! Please ensure the username and password are valid.', false)
		WebUI.closeBrowser()
	}

}

From a Feature File

From Toolbar

Katalon Studio allows you to run the feature file instantly by itself to make sure it works properly. Open the desired Features file, click the Play button on the main toolbar.

In Test Cases

Katalon Studio supports Cucumber keywords along with the original built-in keywords. The user doesn't have to import Cucumber libraries into Katalon Studio.

To include Cucumber Feature file in Katalon Studio test case:

Execute a single Feature File (with or without tags)

Execute multiple Feature Files (with or without tags)

Execute using Cucumber Runner

Cucumber Reports

There is NO custom report for executing Feature File. Katalon Studio uses only generated Cucumber reports for Test Suite/Test Suite Collection execution level, in which the test cases contain the Cucumber Features file.

The generated Cucumber report of Test Suite/Test Suite Collection will be located in the same folder of Katalon Studio report's folder. In Katalon Studio Tests Explorer, right-click at the desired Report > Open Containing Folder. Katalon Studio will redirect you to the local folder where Cucumber Reports are stored. 

Katalon Studio supports three formats for Cucumber reports: JSON, XML, HTML.

Feedback