Image of What is Cucumber Framework

What is Cucumber Framework? | BDD Tool for Test Automation

Table of Contents

Cucumber is a popular testing tool used in Behavior-Driven Development (BDD). It helps to create tests that are easy to understand, even for non-technical stakeholders, such as business owners. Cucumber uses simple, readable language that can be understood by everyone involved in the project. It can also be used to test mobile applications.

Mobile Automation Testing with Cucumber and Appium:-

Setting Up the Environment:-

  1. Install Maven:- Maven will be used to handle the dependencies.
  2. Install Appium:- Appium is the tool that interacts with mobile applications for automation. Open your terminal (or command prompt on Windows) and run the following command:
  • npm install -g appium
  1. Install Cucumber:- Add the necessary Cucumber dependencies to your Maven project by editing your pom.xml.

Step 1: Mobile Automation Testing using Appium and Cucumber

  • Write Feature Files :- Cucumber operates to interpret the written files written in Gherkin ‘syntax. A feature file describes the app in simple English.
  • Write Step Definitions :- Step definitions link the Gherkin scenarios to the code. In our example, we need to interact with the elements on the mobile app, like clicking buttons or typing text.
  • Set Up Cucumber Test Runner :- Then we need to create a runner test class to start the tests. Runner class connects functional files and phase definitions together.

Step 2: Integrating Cucumber Tests with Jenkins

  • Set Up Jenkins Pipeline( Mac)
  1. Install Jenkins on your server or use a cloud-based Jenkins service.
  • Install the latest LTS version: brew install jenkins-lts
  • Start the Jenkins service: brew services start jenkins-lts
  • Restart the Jenkins service: brew services restart jenkins-lts
  • Update the Jenkins version: brew upgrade jenkins-lts
  1. Install the Maven plugin in Jenkins.
  2. Create a new Jenkins job and configure it to run Cucumber tests.
  • Pipeline:- The pipeline block is the main part of your Jenkins pipeline. It sets up the overall structure and includes all the settings, agents, tools, stages, and steps needed to run the pipeline.
  • Agent:- The agent block tells Jenkins where to run the pipeline or its stages. It could be a specific computer, a Docker container, or any available worker.
  • Tools:- The tools block lists the tools needed to run the pipeline, like Maven or JDK. It makes sure the correct version of these tools is available when running the pipeline.
  • Stages:- The stages block holds all the individual steps in the pipeline. Each stage is a specific part of the pipeline, like compiling the code, testing it, or deploying it.In this case, there’s only one stage called ‘Run Tests’.
  • Stage:- A stage is a specific step in the pipeline. It breaks the pipeline into smaller parts that Jenkins runs one by one.In this case, the only stage is ‘Run Tests’.
  • Steps:- The steps block contains the actions that need to be done in each stage. Each step is a command that Jenkins runs.
    In this example, there are two steps:
  • sh ‘ls’: This command lists the files in the current directory. It’s just for showing something.
  • sh ‘mvn -f /Users/ds/Documents/BDD_Automation/pom.xml test’: This 
  • Script:- The script block lets you write Groovy code. It can include commands, logic, or control actions. You can also run shell commands or make decisions in the script block.
  • Sh:- The sh step runs shell commands on the machine where Jenkins is running. It’s used to execute commands in Unix/Linux environments.
    In this case:
  • sh ‘ls’: Lists the files in the current directory.
  • sh ‘mvn -f /Users/ds/Documents/BDD_Automation/pom.xml test’: Runs the Maven build and executes the tests based on the pom.xml file.

Related Blogs

Related Blogs