Sorry, you need to enable JavaScript to visit this website.

Integrating BDD Framework (Cucumber) with HCL OneTest UI

Integrating BDD Framework (Cucumber) with HCL OneTest UI
February 14, 2019

Introduction

HCL OneTest UI is an automated functional testing and regression testing tool and cucumber is a testing framework that supports Behaviour Driven Development (BDD). Cucumber enables us to define application behaviour in a meaningful English text by using simple grammar defined by a structured language called Gherkin. Through this blog, we will learn how to create automation test suite by using cucumber framework and HCL OneTest UI capabilities.

Prerequisites

To perform the steps mentioned in this blog, you must have installed HCL OneTest UI 9.2.1 or later and gained some basic knowledge of HCL OneTest UI.

For more information, see Introduction to functional testing and cucumber executable specifications.

Benefits of creating automation test suite using Cucumber and HCL OneTest UI

HCL OneTest UI is a simple record and playback testing tool. The user need not have any coding skills. The Behaviour Driven Development (BDD) approach can be achieved seamlessly by using the cucumber framework along with HCL OneTest UI capabilities.

New Blog Alert from OneTest: Integrating BDD Framework (Cucumber) with HCL OneTest UI

Testers can easily implement step definitions by using HCL OneTest UI and Testers need not write any code for implementation

HCL OneTest UI is capable of testing framework both native and web applications. So, users can create automation test suite to test native and web applications by using HCL OneTest UI cucumber integration.

Automation suite maintenance and debugging is easy through HCL OneTest UI cucumber integration.

All the business stakeholders can understand the tests under run by glancing at the feature files and they can play around with feature file creations and the implementations are also easily understood with HCL OneTest UI cucumber integration.

Pre-setup of cucumber dependencies required for HCL OneTest UI -Cucumber Integration

The following cucumber jars are required to create a cucumber framework-based automation test suite:

  • cucumber-core
  • cucumber-html
  • cucumber-java
  • cucumber-jvm-deps
  • gherkin

These cucumber jars can be added as dependencies to HCL OneTest UI project by following either of the following methods.

Method A:

Follow the instructions to download the cucumber jars from Maven online repository.

  1. Go to Maven online repository: https://search.maven.org/

    Click here to view the screenshot

  2. Download the cucumber jars from the repository.

    Search for ‘cucumber-core’ and download the jar that has GroupId as ‘info.cukes’.

    Click here to view the screenshot

    Repeat step 2 and download all of the required cucumber jars that are listed in the same way.

  3. Place all the downloaded jars in HCL OneTest UI customization folder.

    Click here to view the screenshot

Method B:

We can add cucumber dependencies directly to HCL OneTest UI projects by running the following pom_dependency_cucumber.xml file. Before running this file, you must have installed Maven in your machine and MAVEN_HOME should be declared in the environment variables.

Link for pom_dependency_cucumber file

This file fetches all the cucumber dependencies from the Maven repository and adds them to HCL OneTest UI.

You must execute the following command from command prompt to run the pom_dependency_cucumber.xml file:

mvn -f "" dependency:copy-dependencies -DoutputDirectory="" -Dmdep.stripVersion=true

Examples for Windows and Linux commands

Windows:

mvn -f "C:\Users\Desktop\ pom_dependency_cucumber.xml" dependency:copy-dependencies -DoutputDirectory="C:\ProgramData\HCL\HOTUI\customization" -Dmdep.stripVersion=true

Linux:

mvn -f "/home/user/Desktop/ pom_dependency_cucumber.xml" dependency:copy-dependencies -DoutputDirectory=" /etc/opt/HCL/HOTUI/customization" -Dmdep.stripVersion=true

Creating cucumber framework-based automation test suite using HCL OneTest UI capabilities

Let’s consider that we have a business scenario that needs to be tested and assume that testers don’t have any technical or coding skill. In such cases, our HCL OneTest UI cucumber framework comes in handy.

Let’s consider a scenario in which a user logs in to the app and selects a product and places the order.

Now, let’s automate this scenario using HCL OneTest UI cucumber integration. The application used in this example is ClassicsJavaA that is shipped along with HCL OneTest UI.

Step 1: Create a feature file

Listing 1. Feature file

  1. Feature: Place order for a product
  2. Scenario: User places the order with correct details
  3. Given user selects the product
  4. When user logs in to the app
  5. And fill in the order details
  6. Then place the order

Step 2: Create a runner script

The next step is to create a runner script to run the feature file.

Create an empty HCL OneTest UI script and make it a runner script by adding Functional Tester cucumber options.

Listing 2. Runner Script

 

package Runner;
import resources.Runner.Runner_orderHelper;
import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.SAP.*;
import com.rational.test.ft.object.interfaces.WPF.*;
import com.rational.test.ft.object.interfaces.dojo.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.object.interfaces.flex.*;
import com.rational.test.ft.object.interfaces.generichtmlsubdomain.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;
import com.ibm.rational.test.ft.object.interfaces.sapwebportal.*;
@FTCucumberOptions(cucumberOptions =
{
//"--glue", "",
//"--plugin", "pretty",
//"--monochrome",
//"--dry-run",
//"--tags", "",
//"--strict",
"Features\\orderTest.feature"
})
public class Runner_order extends Runner_orderHelper
{
/**
* Script Name : Runner_order
* Generated : Mar 16, 2018 12:04:14 AM
* Description : Functional Test Script
* Original Host : WinNT Version 6.1 Build 7601 (S)
*
* @since 2018/03/16
* @author sravankumarreddy.k
*/
public void testMain(Object[] args)
{
// TODO Insert code here
}
}

 

Step 3: Create step definitions

If user plays back the runner script as cucumber script by checking the ‘Run with Cucumber option’ in the Run Wizard( See Fig.1: Run with cucumber option in the Run Wizard), then user obtains code snippets for the unimplemented methods in HCL OneTest UI console.

Click here to view the screenshot

Fig.1: Run with cucumber option in the Run Wizard

Listing 3. Code snippets generated in the console

 

Feature: Place order for a product
Scenario: User places the order with correct details # Features/orderTest.feature:2
Given user selects the product
When user logs in to the app
And fill in the order details
Then place the order
1 Scenarios (1 undefined)
4 Steps (4 undefined)
0m0.000s
You can implement missing steps with the snippets below:
@Given("^user selects the product$")
public void user_selects_the_product() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^user logs in to the app$")
public void user_logs_in_to_the_app() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^fill in the order details$")
public void fill_in_the_order_details() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^place the order$")
public void place_the_order() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

 

You have to create another HCL OneTest UI empty script and paste these code snippets as shown in the below listing.

Listing 4. HCL OneTest UI script with unimplemented methods

 

package StepDefinitions;
import resources.StepDefinitions.StepDefinitions_orderTestHelper;
import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.SAP.*;
import com.rational.test.ft.object.interfaces.WPF.*;
import com.rational.test.ft.object.interfaces.dojo.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.object.interfaces.flex.*;
import com.rational.test.ft.object.interfaces.generichtmlsubdomain.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;
import com.ibm.rational.test.ft.object.interfaces.sapwebportal.*;
public class StepDefinitions_orderTest extends StepDefinitions_orderTestHelper
{
public void testMain(Object[] args)
{
// TODO Insert code here
}
@Given("^user selects the product$")
public void user_selects_the_product() throws Throwable {
//
Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^user logs in to the app$")
public void user_logs_in_to_the_app() throws Throwable {
//
Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^fill in the order details$")
public void fill_in_the_order_details() throws Throwable {
//
Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^place the order$")
public void place_the_order() throws Throwable {
//
Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
}

 

Step 4: Implement step definitions by inserting HCL OneTest UI code

Point the cursor to the method that you want implement. For example, in the following sample code, you can place the cursor at line number 29 and then by using the ‘Insert Recording in to Active Functional test script’ option, you can implement that particular method or step definition. Similarly, we can implement all step definitions.

Listing 5. HCL OneTest UI script with implemented methods

 

package StepDefinitions;
import resources.StepDefinitions.StepDefinitions_orderTestHelper;
import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.SAP.*;
import com.rational.test.ft.object.interfaces.WPF.*;
import com.rational.test.ft.object.interfaces.dojo.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.object.interfaces.flex.*;
import com.rational.test.ft.object.interfaces.generichtmlsubdomain.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import com.ibm.rational.test.ft.object.interfaces.sapwebportal.*;
public class StepDefinitions_orderTest extends StepDefinitions_orderTestHelper
{
public void testMain(Object[] args)
{
// TODO Insert code here
}
@Given("^user selects the product$")
public void user_selects_the_product() throws Throwable {
startApp("ClassicsJavaA");
sleep(1);
// Frame: ClassicsCD
tree2().click(atPath("Composers->Bach->Location(PLUS_MINUS)"));
tree2().click(atPath("Composers->Bach->Brandenburg Concertos Nos. 1 & 3"));
placeOrder().click();
sleep(2);
}
@When("^user logs in to the app$")
public void user_logs_in_to_the_app() throws Throwable {
// Frame: Member Logon
nameCombo().click();
nameCombo().click(atText("Rick Tumbler"));
password().click(atPoint(47,10));
memberLogon().inputChars("1234");
rememberPassword().clickToState(SELECTED);
sleep(1);
ok().click();
sleep(2);
}
@When("^fill in the order details$")
public void fill_in_the_order_details() throws Throwable {
// Frame: Place an Order
cardNumberIncludeTheSpaces().click(atPoint(26,9));
placeAnOrder().inputChars("1234123412341234");
expirationDate().click(atPoint(21,9));
placeAnOrder().inputChars("01/18");
sleep(2);
}
@Then("^place the order$")
public void place_the_order() throws Throwable {
// Frame: Place an Order
placeOrder2().click();
//
ok2().click();
// Frame: ClassicsCD
classicsCD(ANY,MAY_EXIT).close();
}
}

 

Framework structure

For easy maintenance and debugging, you can create the automation framework as follows:

  1. Create a Functional Test project.
  2. Create three test folders under the Functional Test project:
    • Features (Folder 1): Create all the feature files under this folder.
    • Step Definitions (Folder 2): Create the scripts that contains step implementations under this folder.
    • Runner (Folder 3): Create runner scripts that will run your features under this folder.

Click here to view the screenshot

A framework sample is embedded below.

Sample framework

To work with this sample framework, follow these instructions:

  1. Launch HCL OneTest UI 9.2.1 or later in a new workspace and create a Functional Test project named "Cucumber Sample Project".
  2. Go to Import as File > Import > Functional Test Project Items to import the downloaded sample framework into the newly created project.
  3. Right-click the Runner.Runner_order script and click Run.
  4. In the Run window, select ‘Run with Cucumber’ option and play back the script.

The playback log contains the test results.

Conclusion

In this blog, you have seen how HCL OneTest UI cucumber integration can be used to create a cucumber-based automation framework for a native application. The same approach can be used to write the framework for other domains that HCL OneTest UI supports.