Skip to main content
Appic Softwares Logo - Custom Software and App Development Company
  • AI/ML
  • Services
  • Industries
  • Platform
  • Hire Talent
  • Our Company
  • Blog
Contact Us
Appic Softwares Logo - Custom Software and App Development Company
AI
  • AI Development
  • AI Agent
  • Micro SaaS Development
  • Finish Lovable/Cursor Website
  • AI Consulting
  • Enterprise AI Development
  • AI in Fintech
Generative AI
  • Generative AI Development
  • Generative AI Integration
  • LLM Development
  • Adaptive AI Development
  • Generative AI in Real Estate
ML
  • Machine Learning Development
  • ML Model Engineering
  • ML Ops Consulting
  • ML & Data Science Consulting
Custom App Development
  • Mobile App Development
  • Enterprise Mobile App Development
  • IPhone Mobile App Development
  • Ionic App Development
  • Wearable App Development
  • Android Mobile App Development
  • IoT App Development
Software Development Services
  • Software Development
  • Flutter App Development
  • No-Code / Low-Code
  • Angular App Development
  • FlutterFlow Development Company
  • PWA Development Company
  • Next.Js Development Company
  • Supabase Development Company
  • MVP Development
  • Web Development Company
  • Startup Software Development
Blockchain
  • Blockchain Development Services
  • Blockchain Consulting Services
  • Substrate Development
  • Polygon Blockchain Development
  • Hypeledger Blockchain Development Services
  • Golang Development
  • Cosmos Development
  • Solana Blockchain Development
  • Tezos Development
Web 3
  • Web3 Development
  • Rust Development
Maintenance And Support
  • Maintenance & Support
Integration Services
  • Digital Wallet Integration
  • Custom Chat Integration Service
  • Property Recommendation Engine
  • Real Estate Chatbot
  • Real Estate CRM
Astrology
  • Ready-Made Astrology App Development
  • Astrology API Integration App Development
  • Astrology App Development
  • Temple Management App Development
Finance
  • Finance App Development
  • Trading App Development
  • Insurance App Development
  • Mobile Banking App Development
  • Loan Lending App Development
  • Fintech App Development Company In Saudi Arabia
Education
  • LMS App Development
  • EdTech App Development
Real Estate
  • Real Estate App Development
  • Proptech App Development
  • Floor Plan App Development
  • Commercial Real Estate App Development
  • Real Estate Reporting App Development
  • Property Management App Development
  • Real Estate MLS App Development
  • Virtual Property App Development
Industrial Manufacturing and Recycling
  • Waste Management Software Development
On Demand
  • On Demand App Development
  • Laundry App Development
  • On Demand Home Services App Development
  • Salon App Development
  • Logistic App Development
  • Ticket Booking App Development
  • Media & Entertainment App Development
  • Events App Development
  • Restaurant App Development
  • Agriculture App Development
  • Travel App Development
  • Automotive App Development
  • Dating App Development
  • Car Service App Development
  • AI Skincare App Development
E-Commerce
  • Social Commerce App Development
  • Ecommerce App Development
  • Ecommerce App Development in Saudi Arabia
Pet Care
  • Pet Care App Development
  • Veterinary App Development
  • Pet Food Delivery App Development
  • Pet Tracking App Development
  • Pet Training App Development
  • Pet Social Networking App Development
  • Dog Walker App Development
  • Dog Park Tracker App Development
Health
  • Healthcare Software Development
  • Doctor on Demand App Development
  • Medicine Delivery App Development
  • Fitness App Development
DevOps
  • DevOps Services
  • DevOps Automation Services
  • DevOps Infrastructure Management
Adobe
  • Adobe Commerce Development
  • Adobe Cloud Development
  • Adobe Marketplace
  • Adobe B2B Marketplace
  • Adobe POS
  • Adobe Integration
Salesforce
  • Salesforce Development
  • Salesforce Implementation
  • Salesforce Integration
Microsoft
  • Power BI Development
Pega
  • Pega Development
  • Pega Consulting
Drupal
  • Drupal Development Services
  • Drupal Mobile App Development
  • Drupal Ecommerce Development
  • Drupal Migration & Upgradation
  • Drupal Consulting Company
  • Headless Drupal Development
Hire Developers
  • Hire Developer
  • Hire Software Development Team
  • Cost of Hiring Developers
  • Vetting Process
  • How We Hire
Hire Front-End Developers
  • Hire WeWeb Developer
  • Hire React Developer
  • Hire Flutter Flow Developer
  • Hire React Native Developer
  • Hire Flutter Developer in Saudi Arabia
Hire Back-End Developers
  • Hire Node.js Developer
  • FlutterFlow Firebase
  • GraphQL
  • Rowy
  • BuildShip Developer
Hire CMS Developers
  • Hire Wordpress Developer
  • Hire WooCommerce Developer
  • Hire Drupal Developer
  • PrestaShop
  • Shopify
  • Strapi
  • Hire Strapi Developer
Hire AI Engineers
  • Hire AI Engineers
  • Hire Generative AI Engineers
  • Hire Prompt Engineers
  • Hire AWS Bedrock Developer
Hire Digital Marketing Experts
  • Hire Digital Marketing Expert
  • Hire SEO Experts
  • Hire Digital Marketing For Real Estate
Company Information
  • Portfolio
  • Case Studies
  • Videos
  • About Us
  • Partner with Us
  • Client Testimonials
Blog
Contact Us
How To Test A Drupal Website With Behat?
Appic Softwares Logo - Custom Software and App Development Company
  • AI/ML
  • Services
  • Industries
  • Platform
  • Hire Talent
  • Our Company
  • Blog
Contact Us
Appic Softwares Logo - Custom Software and App Development Company
AI
  • AI Development
  • AI Agent
  • Micro SaaS Development
  • Finish Lovable/Cursor Website
  • AI Consulting
  • Enterprise AI Development
  • AI in Fintech
Generative AI
  • Generative AI Development
  • Generative AI Integration
  • LLM Development
  • Adaptive AI Development
  • Generative AI in Real Estate
ML
  • Machine Learning Development
  • ML Model Engineering
  • ML Ops Consulting
  • ML & Data Science Consulting
Custom App Development
  • Mobile App Development
  • Enterprise Mobile App Development
  • IPhone Mobile App Development
  • Ionic App Development
  • Wearable App Development
  • Android Mobile App Development
  • IoT App Development
Software Development Services
  • Software Development
  • Flutter App Development
  • No-Code / Low-Code
  • Angular App Development
  • FlutterFlow Development Company
  • PWA Development Company
  • Next.Js Development Company
  • Supabase Development Company
  • MVP Development
  • Web Development Company
  • Startup Software Development
Blockchain
  • Blockchain Development Services
  • Blockchain Consulting Services
  • Substrate Development
  • Polygon Blockchain Development
  • Hypeledger Blockchain Development Services
  • Golang Development
  • Cosmos Development
  • Solana Blockchain Development
  • Tezos Development
Web 3
  • Web3 Development
  • Rust Development
Maintenance And Support
  • Maintenance & Support
Integration Services
  • Digital Wallet Integration
  • Custom Chat Integration Service
  • Property Recommendation Engine
  • Real Estate Chatbot
  • Real Estate CRM
Astrology
  • Ready-Made Astrology App Development
  • Astrology API Integration App Development
  • Astrology App Development
  • Temple Management App Development
Finance
  • Finance App Development
  • Trading App Development
  • Insurance App Development
  • Mobile Banking App Development
  • Loan Lending App Development
  • Fintech App Development Company In Saudi Arabia
Education
  • LMS App Development
  • EdTech App Development
Real Estate
  • Real Estate App Development
  • Proptech App Development
  • Floor Plan App Development
  • Commercial Real Estate App Development
  • Real Estate Reporting App Development
  • Property Management App Development
  • Real Estate MLS App Development
  • Virtual Property App Development
Industrial Manufacturing and Recycling
  • Waste Management Software Development
On Demand
  • On Demand App Development
  • Laundry App Development
  • On Demand Home Services App Development
  • Salon App Development
  • Logistic App Development
  • Ticket Booking App Development
  • Media & Entertainment App Development
  • Events App Development
  • Restaurant App Development
  • Agriculture App Development
  • Travel App Development
  • Automotive App Development
  • Dating App Development
  • Car Service App Development
  • AI Skincare App Development
E-Commerce
  • Social Commerce App Development
  • Ecommerce App Development
  • Ecommerce App Development in Saudi Arabia
Pet Care
  • Pet Care App Development
  • Veterinary App Development
  • Pet Food Delivery App Development
  • Pet Tracking App Development
  • Pet Training App Development
  • Pet Social Networking App Development
  • Dog Walker App Development
  • Dog Park Tracker App Development
Health
  • Healthcare Software Development
  • Doctor on Demand App Development
  • Medicine Delivery App Development
  • Fitness App Development
DevOps
  • DevOps Services
  • DevOps Automation Services
  • DevOps Infrastructure Management
Adobe
  • Adobe Commerce Development
  • Adobe Cloud Development
  • Adobe Marketplace
  • Adobe B2B Marketplace
  • Adobe POS
  • Adobe Integration
Salesforce
  • Salesforce Development
  • Salesforce Implementation
  • Salesforce Integration
Microsoft
  • Power BI Development
Pega
  • Pega Development
  • Pega Consulting
Drupal
  • Drupal Development Services
  • Drupal Mobile App Development
  • Drupal Ecommerce Development
  • Drupal Migration & Upgradation
  • Drupal Consulting Company
  • Headless Drupal Development
Hire Developers
  • Hire Developer
  • Hire Software Development Team
  • Cost of Hiring Developers
  • Vetting Process
  • How We Hire
Hire Front-End Developers
  • Hire WeWeb Developer
  • Hire React Developer
  • Hire Flutter Flow Developer
  • Hire React Native Developer
  • Hire Flutter Developer in Saudi Arabia
Hire Back-End Developers
  • Hire Node.js Developer
  • FlutterFlow Firebase
  • GraphQL
  • Rowy
  • BuildShip Developer
Hire CMS Developers
  • Hire Wordpress Developer
  • Hire WooCommerce Developer
  • Hire Drupal Developer
  • PrestaShop
  • Shopify
  • Strapi
  • Hire Strapi Developer
Hire AI Engineers
  • Hire AI Engineers
  • Hire Generative AI Engineers
  • Hire Prompt Engineers
  • Hire AWS Bedrock Developer
Hire Digital Marketing Experts
  • Hire Digital Marketing Expert
  • Hire SEO Experts
  • Hire Digital Marketing For Real Estate
Company Information
  • Portfolio
  • Case Studies
  • Videos
  • About Us
  • Partner with Us
  • Client Testimonials
Blog
Contact Us
HomeBlogHow To Test A Drupal Website With Behat?

How To Test A Drupal Website With Behat?

Shubham Pareek
Sep 11, 2023
Back to Blog

Table of Contents

Loading headings…

Share this

Drupal Website

Table of Contents

  • Introduction to Behat
  • Understanding Gherkin
  • Exploring Mink
  • Installing and Implementing Behat in Drupal
  • Writing and Running Tests with Behat
  • Write Feature files

The ability to collaborate effectively and develop software is facilitated by the power of tales as well as clear and effective communication. The Behavior Driven Development (BDD) tools, which evolved out of agile methodology, make the most of this power to the best extent possible to automate the testing process. One of these BDD technologies is called Behat, a
nd it facilitates automated testing by making use of “ubiquitous language.” Let’s get more familiar with Behat, Mink, and Gherkin, as well as the process of implementing it in Drupal.

Introduction to Behat

Behat is an open-source PHP framework that was developed to automate testing through the utilization of Behavior Driven Development (BDD). By emphasizing constant communication and straightforward text storytelling, a BDD strategy guarantees the delivery of high-quality software. Using BDD, the tester will construct test cases using language that is readable by humans. Because of this, it is simple to get the entire team on the same page because everyone, starting with the product owner and working down to the developer, can comprehend the present scenario and receive continuous feedback on it

Understanding Gherkin

The Behat tool communicates with users via the Gherkin language, which is a domain-specific language that is also legible by businesspeople. Additionally, Gherkin acts as a living document, and reports can be generated to document each test run. This language is based primarily on whitespace, and its keywords are words from simple languages. The structure of the test case is determined by the use of line endings and indentation (using space or tab). Even if it is simple to write in and understand the language, the result should center on improving collaboration, efficiency, automation, and traceability. Test cases must be written intuitively, with a concentration on important aspects, while avoiding testing duplicate entries and employing correct syntax.

Exploring Mink

A test scenario with the online application can be simulated using Mink, which is a browser controller that is open source. After the test cases have been prepared, they need to be run and should simulate how users would behave. You may run the same test scenario on many browser emulators with Mink, including Goutte, Selenium, Chrome, Zombie, and many others. You will notice a requirement on Mink while installing the Behat Drupal extension; therefore, you need to ensure that you already have Mink installed on your system.

Installing and Implementing Behat in Drupal

Composer is the recommended method for installing Behat in a Drupal project, as this is the official method. Not only will it install Behat for you, but if an updated version is released in the future, it will also be able to effortlessly update you to the most recent version.

  • Within the folder containing the project, carry out the following command:
$ composer require behat/behat
  • Alternatively, you can include the required statement within your composer.json file.
  "require": {
                "behat/behat": "^3.0.0",
     “phpunit/phpunit”: “^5.0.0”
     }

•    Next, run composer install command in the terminal.
•    When it is done, you will also notice a new directory bin/ with a Behat file in it. This is the Behat executable and you will use it to run your tests and get debug information.
•    Next, create a file named behat.yml inside the root folder of the project. When Behat runs, it looks for a behat.yml file, which it uses for its configuration.

default:
  suites:
    default:
      contexts:
        - Drupal\DrupalExtension\Context\DrupalContext
  extensions:
    Behat\MinkExtension:
      goutte: ~
      base_url: http://example.org/  # Replace with your site's URL
    Drupal\DrupalExtension:
      blackbox: ~

Source: Specbee

Execute the following command to begin setting up the project:

vendor/bin/behat –init

Within the features folder, this will generate a folder called bootstrap/FeatureContext as the default context file.

Writing and Running Tests with Behat

Our objective is to summarize the tales in the most compelling manner possible. Under the features/ directory, the narratives are saved with the extension. feature, which indicates that they are written in the human-readable language Gherkin.

Imagine for a moment that you have been tasked with determining whether or not you can successfully add material to the Basic page content type on your website. To accomplish this, you will need access to the page so that you may fill in the blanks and save the information as an administrator.

Now, let’s get started on our very first tale:

Feature: Check basic page CT
 In order to create a page
 As an admin
 I want to access /node/add/page
 So that I can create a page

Scenario: Basic Page CT
 Given I am logged in as a user with the "administrator" role
 When I go to "/node/add/page"
 And I enter "Basic page title" for "edit-title-0-value"
 When I press "edit-submit"
 Then I should see "Basic page Basic page title has been created"

Source: Specbee

The name basic_page.feature is one option for this file. Each feature may contain several scenarios, which define the feature’s particular operation in a certain situation. Each scenario will have the following subdivisions:

  • Given describes the initial condition of the system in great detail.
  • When which refers to the activity performed by the user
  • Then explains what the user sees once they have performed a certain action.
  • And – to preserve the existing link within the scenario.

The distinctions between “Then,” “And,” and “But” are not particularly significant. These words are provided for your use so that your scenarios will sound more natural and will be easier to read.

Every feature file can be executed using the vendor/bin/behat program. If you wish to run a particular feature file, you need to execute the vendor/bin/behat features/basic_page.feature command. In addition to this, a single scenario can be executed by simply adding a line number to the location where the scenario is created, as follows: vendor/bin/behat features/basic_page.feature:11.

There are tools such as vendor/bin/behat -dl and vendor/bin/behat -di that offer the statement syntax along with examples. For example, you can use vendor/bin/behat -dl to obtain all of the statement syntax that is used in scenarios.

Write Feature files

Behat runs curl requests against URLs on your website, which makes the testing process quite fast, but also makes Behat lose the ability to test features that require Javascript. So, to test features we only need to do add @javascript tag before every scenario that requires Javascript, like this:

Feature: Check basic page CT
 In order to create a page
 As an admin
 I want to access /node/add/page
 So that I can create a page

@api @javascript
Scenario: Basic Page CT
 Given I am logged in as a user with the "administrator" role
 When I go to "/node/add/page"
 And I enter "Basic page title" for "edit-title-0-value"
 And I fill in wysiwyg on field "edit-body-0-value" with "Basic page content"
 When I press "edit-submit"
 Then I should see "Basic page Basic page title has been created"

Source: Specbee

Execute the vendor/bin/behat file to test this. Because each scenario needs to translate to a function, this will display the stages in the scenario that have not been defined.

test drupal with behat

Source: Specbee

You have two options: either copy the code snippet and paste it into the FeatureContext context file, or you may run the vendor/bin/behat –dry-run –append-snippets command.

After that, you’ll be able to jot down the definitions for the functions in the FeatureContext file as follows:

<?php

use Behat\Mink\Exception\ExpectationException;
use Drupal\DrupalExtension\Context\RawDrupalContext;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends RawDrupalContext {

  /**
   * The mink context.
   *
   * @var Drupal\DrupalExtension\Context\MinkContext
   */
  protected $minkContext;

  /**
   * Initializes context.
   *
   * Every scenario gets its own context instance.
   * You can also pass arbitrary arguments to the
   * context constructor through behat.yml.
   */
  public function __construct() {
  }

  /**
   * Fill in wysiwyg on field.
   *
   * @Then I fill in wysiwyg on field :locator with :value
   */
  public function iFillInWysiwygOnFieldWith($locator, $value) {
    $el = $this->getSession()->getPage()->findField($locator);
    if (empty($el)) {
      throw new ExpectationException('Could not find WYSIWYG with locator: ' . $locator, $this->getSession());
    }
    $fieldId = $el->getAttribute('id');
    if (empty($fieldId)) {
      throw new Exception('Could not find an id for field with locator: ' . $locator);
    }
    $this->getSession()
      ->executeScript("CKEDITOR.instances[\"$fieldId\"].setData(\"$value\");");
  }

}

Source: Specbee

Now that you’ve done that, execute the command vendor/bin/behat, and eve
ry scenario that was written should pass. The JS code that has been defined will act as a map for the scenario statement “And I fill in WYSIWYG on-field “edit-body-0-value” with “Basic page content.”

Conclusion

Now, in the end, we hope that through this post you were able to learn how to test your Drupal website with Behat. However, if you are looking for a Drupal development company, then you should check out Appic Sotwares. We have an experienced team of Drupal developers that will help you with your Drupal requirements.

You can even hire dedicated Drupal developers from us. So what are you waiting for?

Contact us now!

Related Articles

Tarot App Development
7/22/2026

Tarot App Development: Architecture, AI, and the Real Cost of Building a Platform Users Trust

Most tarot app guides talk about decks and animations. This one talks about architecture: why AI should interpret readings instead of generating them, what a five-layer platform actually costs to build, and the seven mistakes that quietly kill most tarot startups before they find product-market fit.
Read More
retail software development
6/25/2026

Retail Software Development: Cost, Process, Features & Complete Guide

Learn everything about Retail Software Development, including costs, process, features, timelines, and how to choose the right development partner. Discover why custom retail software helps businesses improve efficiency, enhance customer experiences, and achieve long-term growth with Appic Softwares.
Read More
Astrology ecommerce app
6/25/2026

Build an Astrology E-commerce App for Gemstones, Reports, and Remedies

Astrology application development is in very high demand already by consumers, as they are exhibiting clear intent to use best astrology apps. Consumers will often purchase stones, request reports or look up remedies based on their predictive astrological readings. However, one reason why so many users fail to have a successful journey with today’s available […]

Read More

Our Drupal Services

Mobile App Development →AI Development Services →Healthcare Software Development →Web Development →

Share Your Ideas Here!

We are all ears!

Get in touch with us

  • Contact info type iconsales@appicsoftwares.com
  • Contact info type icon
    +91 - 8233801424,+91 - 9887354080
  • Contact info type iconlive:appicsoftwares
  • Contact info type icon41/11 Varun Path, New Sanganer Road, Jaipur, Rajasthan
  • Follow Us

Global Presence

Your Partner Everywhere!

India Background

India

41/11 Varun Path, New Sanganer Road, Jaipur, Rajasthan

USA Background

USA

5 Cowboys Way, Suite 300, Frisco, TX 75034, USA

Germany Background

Germany

Magdalenenstraße 34, 80638 München, Germany

Industries

  • All industries
  • Astrology
  • Healthcare
  • Real estate
  • On-demand
  • Travel
  • Education
  • Fitness
  • Pet Care
  • Pet Training

Services

  • iOS App Development
  • Android App Development
  • Software Development
  • Flutter App Development
  • Mobile App Development
  • Ionic development
  • Maintenance & Support

Portfolio

  • Bridl
  • Obdoor
  • Laiqa
  • Rocca Box
  • Plantify
  • City of Cars
  • No-limit-Qr
  • Sync Remote

Platform

  • Artificial Intelligence
  • Blockchain
  • IOT
  • MVP
  • Angular
  • PWA
  • Devops
  • Drupal

About

  • Our company
  • Blog
  • Portfolio
  • Case Studies
  • Let's connect
  • Career

Recognized For Excellence

GoodFirms Award
TopDevelopers.co Award
Clutch Leader Award
DesignRush Award
SelectedFirms Award

© 2026 Appic Softwares. All Rights Reserved. |Privacy Policy