behat-skill
This skill enables you to create and run Behat behavior-driven development tests using Gherkin syntax, making it straightforward to validate PHP web application behavior through readable, executable specifications. Leverage structured scenario definitions to bridge the gap between business requirements and automated test coverage.
behat-skill enables you to write Behat tests for PHP by using Gherkin feature files that describe application behavior in plain language. You define scenarios with Given-When-Then steps, then map those steps to PHP code in context classes. Create a `features/` directory with `.feature` files, set up a `FeatureContext` class to implement step definitions, and run `behat` from the command line. This approach bridges business requirements and automated test coverage through readable, executable specifications.
AI-generated summary based on this skill's SKILL.md
Install
LambdaTest/agent-skills/behat-skill · repository language: Python
git clone https://github.com/LambdaTest/agent-skills
cp -r agent-skills/behat-skill ~/.claude/skills/behat-skillFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do you write Behat tests for PHP web applications?
behat-skill enables you to write Behat tests for PHP by using Gherkin feature files that describe application behavior in plain language. You define scenarios with Given-When-Then steps, then map those steps to PHP code in context classes. Create a `features/` directory with `.feature` files, set up a `FeatureContext` class to implement step definitions, and run `behat` from the command line. This approach bridges business requirements and automated test coverage through readable, executable specifications.
What is a behat.yml configuration example for basic setup?
behat-skill uses a `behat.yml` configuration file to define test suites and contexts. A basic example includes specifying the default suite, the features path (typically `features/`), the bootstrap path for context classes, and the context class name (usually `FeatureContext`). You can also configure profiles for different environments, set output formatters (like `pretty` or `html`), and define extensions like MinkExtension for browser automation. The configuration file allows you to organize multiple test suites and control how Behat discovers and executes your scenarios.
How do you set up behat with MinkContext for browser automation and form interaction testing?
behat-skill integrates with MinkExtension to enable browser automation through MinkContext. Install the Mink library and configure it in `behat.yml` with a driver (such as Selenium2 for real browsers). Extend your `FeatureContext` class with `MinkContext` to gain step definitions for clicking elements, filling form fields, and navigating pages. MinkContext provides built-in steps like `I fill in "field" with "value"` and `I press "button"`, allowing you to write feature files that interact with web forms without writing custom step code for common interactions.
How do you create custom step definitions and context classes for domain-specific test scenarios?
behat-skill allows you to create custom step definitions by writing methods in your context classes annotated with `@Given`, `@When`, or `@Then` attributes. Define a method that matches your Gherkin step text using regex patterns, then implement the test logic in PHP. For domain-specific scenarios, create additional context classes that extend `BehatContext` and define steps relevant to your application's business logic. You can organize multiple context classes by suite and combine them using composition or inheritance, enabling reusable, maintainable test code tailored to your specific application needs.
How do you integrate Behat tests into CI/CD pipelines with reporting and debugging?
behat-skill integrates into CI/CD pipelines by running `behat` as a command-line tool in your build process. Configure output formatters in `behat.yml` to generate reports (such as `html`, `json`, or `junit` formats) that your CI system can parse and display. Use tags like `@smoke` or `@critical` to filter which scenarios run in different pipeline stages. For debugging, enable verbose output with `--verbose` flags, capture screenshots on failure using Mink hooks, and use `@BeforeScenario` and `@AfterScenario` hooks to set up and tear down test state. Most CI platforms (GitHub Actions, GitLab CI, Jenkins) support Behat natively.
What is the difference between behat and phpunit for BDD testing?
behat-skill differs from PHPUnit in that Behat is purpose-built for behavior-driven development using Gherkin's human-readable Given-When-Then syntax, making it ideal for acceptance testing and stakeholder communication. PHPUnit is a unit testing framework focused on testing individual functions and classes with code-level assertions. behat-skill excels at describing application workflows and user interactions in business language, while PHPUnit is better suited for testing internal logic and edge cases. Many projects use both: Behat for high-level acceptance tests and PHPUnit for low-level unit tests, creating a comprehensive testing pyramid.
SKILL.md
rendered from the published skill — quoted content, verbatim
Behat BDD Skill
Core Patterns
Feature File (features/login.feature)
Feature: User Login
As a user I want to log in
Scenario: Successful login
Given I am on "/login"
When I fill in "email" with "user@test.com"
And I fill in "password" with "password123"
And I press "Login"
Then I should see "Dashboard"
And I should be on "/dashboard"
Scenario: Invalid credentials
Given I am on "/login"
When I fill in "email" with "wrong@test.com"
And I fill in "password" with "wrong"
And I press "Login"
Then I should see "Invalid credentials"
Custom Context (features/bootstrap/LoginContext.php)
```php <?php use Behat\MinkExtension\Context\MinkContext; use Behat\Behat\Context\Context;
class LoginContext extends MinkContext implements
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 3 files
behat-skill/SKILL.md
behat-skill/reference/advanced-patterns.md
behat-skill/reference/playbook.md