PHPackages                             clevyr/laravel-behat-dusk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. clevyr/laravel-behat-dusk

ActiveLibrary[Testing &amp; Quality](/categories/testing)

clevyr/laravel-behat-dusk
=========================

0.0.2(4y ago)113MITPHPPHP ^8.0

Since Oct 19Pushed 2y ago10 watchersCompare

[ Source](https://github.com/clevyr/laravel-behat-dusk)[ Packagist](https://packagist.org/packages/clevyr/laravel-behat-dusk)[ RSS](/packages/clevyr-laravel-behat-dusk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (9)Versions (4)Used By (0)

[![GitHub release (latest SemVer including pre-releases)](https://camo.githubusercontent.com/c4a59343c513e2f0911e40e8d3aa47fe8e7e3cf14a8483bb4f49aefac1f5e2ef/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f636c657679722f6c61726176656c2d62656861742d6475736b3f696e636c7564655f70726572656c6561736573)](https://camo.githubusercontent.com/c4a59343c513e2f0911e40e8d3aa47fe8e7e3cf14a8483bb4f49aefac1f5e2ef/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f636c657679722f6c61726176656c2d62656861742d6475736b3f696e636c7564655f70726572656c6561736573)[![](https://github.com/clevyr/laravel-behat-dusk/workflows/Run%20Tests/badge.svg?branch=master)](https://github.com/clevyr/laravel-behat-dusk/workflows/Run%20Tests/badge.svg?branch=master)

Laravel Behat Dusk is a simple package with the goal of integrating Behat with Laravel and Laravel Dusk.

**This is not a 1:1 implementation of Behat with Laravel, the current goal is to enable a simple and quick way to write Behavior Driven Tests in Laravel Applications.**

---

Pre-requisites
--------------

[](#pre-requisites)

- Laravel 8+
- PHP 8.0+
- Basic Understanding of Behavioral Driven Development and Behat

Installation
------------

[](#installation)

```
composer require clevyr/laravel-behat-dusk --dev
```

Install the Package

```
php artisan lbd:install
```

The following files will be outputted

- features
    - bootstrap
        - FeatureContext
- behat.yml

#### Testing Environments

[](#testing-environments)

Laravel Behat Dusk's environment setup works the exact same way as Laravel Dusk. Take a look at their documentation for environment handling. https://laravel.com/docs/8.x/dusk#environment-handling

#### Running in Docker

[](#running-in-docker)

- Create a .env.dusk.local file by running `cp .env .env.dusk.local` and add it to your .gitignore file
- Update the following `.env.dusk.local` environment file with the following

```
APP_URL=http://laravel.test
DUSK_DRIVER_URL=http://selenium:4444/wd/hub
```

If you are not using Laravel Sail use the docker-compose container names for your Application and Selenium Containers.

- Run Laravel Behat Dusk in the app container `sail artisan lbd`

Usage
-----

[](#usage)

#### Creating a context file

[](#creating-a-context-file)

This creates a Context file in the `features/bootstrap` and appends the relevant configuration data inside the behat.yml

`php artisan lbd:make ExampleContext`

```
--profile[=PROFILE]  Create under the profile in the Behat Config [default: "default"]
--suite[=SUITE]      Create under the suite in the Behat Config [default: "default"]
```

#### Running Behat

[](#running-behat)

Run this command to run the Behat test runner, you are able to use all arguments from the Behat CLI

`php artisan lbd`

#### Traits

[](#traits)

**Refresh the database before each Scenario**`use RefreshScenario;`

#### Example feature file and context file

[](#example-feature-file-and-context-file)

login.feature file

```
Feature: User Login

    In order to acess the site
    As a user
    I want to be able to login

    Scenario: Logging in as a User
        Given There are users
            | email            | password |
            | user@example.com | password |
        When I am on the "/login" page
        When I fill in email
        When I fill in password
        When I press the submit button
        Then I should be redirected to the "/dashboard" page
```

FeatureContext.php

```
