To alleviate this issue, you need to use the \Sepehr\BehatLaravelJs\Concerns\PreserveBehatEnvironment trait in your
Consider this example: Your testing environment is set to use SQLite as the database while your local/production
to your Laravel app endpoint. And to your surprise, it meets with another Laravel instance that is using the .env
file. An instance operating in a different environment: different databases, cache drivers, queues, etc.
To alleviate this one, you need to use Laracasts\Behat\Context\MigrateRefresh trait in your
FeatureContext class instead of using DatabaseTransactions and Migrator traits.
The very popular DatabaseTransactions trait and its
begin a transaction before a scenario. The transaction will be commited only if there are no exceptions. Then after the
scenario, they will rollback it in order to keep the database state intact.
In middle of the process, when a browser emulator dispatches the request to another instance of Laravel, the transaction
won't be commited and thus you will encounter unexpected results.
Consider a scenario, when you first insert a few test users into the database in the testing instance and in the next
step, you request a page (to the other instance) to see if their data exist on a page. To your surprise, the data you're
looking for won't be available.
Instead, in order to maintain a clean database state, use the MigrateRefresh trait to refresh the database before each
To alleviate this one, you should be using the \Sepehr\BehatLaravelJs\Concerns\AuthenticateUsers trait in your
FeatureContext class. It will provide you with helper authentication methods to login, logout and get the current
Authentication is another problem. In the testing environment you log a user into the system, then you tell Behat to
fire a Selenium session and check a protected page. As you might already know, the user won't be logged-in. The testing
browser has no authentication cookie to send to the other Laravel instance.
Available methods are:
Login as a user
Get current user's data
Assert that the user is authenticated
Assert that the user is authenticated AS
Assert that the user is NOT authenticated
Just as Dusk.
Install the package using composer:
composer install sepehr/behat-laravel-js
Then, in your AppServiceProvider::boot(), register the package service provider for testing environments. Please note
that it'd be a SECURITY RISK if you enable this in your production environment. See the package service provider to find