Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mink Browserkit Driver Laravel Package

friends-of-behat/mink-browserkit-driver

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require friends-of-behat/mink-browserkit-driver
    

    Ensure symfony/browser-kit is also installed (dependency).

  2. Basic Configuration In your Laravel project, register the driver in config/mink.php (or create it):

    'drivers' => [
        'browserkit' => [
            'class' => \FriendsOfBehat\MinkBrowserKitDriver\Driver::class,
            'guzzle_options' => [], // Optional Guzzle config
            'options' => [],       // Mink-specific options
        ],
    ],
    
  3. First Use Case Use the driver in a Behat scenario or custom test suite:

    use FriendsOfBehat\MinkBrowserKitDriver\Driver;
    use Mink\Mink;
    
    $mink = new Mink();
    $mink->setDefaultDriver(new Driver());
    $session = $mink->getSession();
    $session->start();
    $session->visit('/');
    

Implementation Patterns

Workflows

  1. Integration with Laravel Testing Use the driver in Laravel’s PHPUnit tests or custom test suites:

    use FriendsOfBehat\MinkBrowserKitDriver\Driver;
    use Laravel\BrowserKitTesting\TestCase;
    
    class FeatureTest extends TestCase {
        protected function createMinkDriver() {
            return new Driver($this->app['browserkit']);
        }
    }
    
  2. Dynamic Session Management Reuse sessions across tests to avoid redundant setup:

    $session = $mink->getSession();
    $session->visit('/dashboard');
    $this->assertSession()->addressEquals('/dashboard');
    
  3. Handling Forms and Submissions Simulate user interactions:

    $session->fillField('email', 'user@example.com');
    $session->pressButton('Login');
    $this->assertSession()->responseContains('Welcome');
    
  4. Custom Middleware Extend the driver with middleware (e.g., auth headers):

    $driver = new Driver($browserKit, [
        'middleware' => [
            function ($request) {
                $request->headers->set('X-Custom-Header', 'value');
            },
        ],
    ]);
    

Gotchas and Tips

Pitfalls

  1. Symfony BrowserKit Limitations

    • No JavaScript execution (use mink-selenium2-driver for JS-heavy apps).
    • Headless testing requires symfony/browser-kit + a browser (e.g., Chrome via laravel-dusk).
  2. Session State Persistence

    • Sessions are stateless by default. Reset between tests if needed:
      $session->reset();
      
  3. Guzzle Version Conflicts Ensure guzzlehttp/guzzle is compatible (v6+ recommended). Resolve conflicts via:

    composer require guzzlehttp/guzzle:^6.0
    

Debugging

  1. Enable Verbose Logging Configure Guzzle for debug output:

    'guzzle_options' => [
        'debug' => fopen('debug.log', 'w'),
    ],
    
  2. Check Response Headers Inspect raw responses:

    $response = $session->getResponse();
    var_dump($response->getHeaders());
    

Tips

  1. Leverage Laravel’s BrowserKit Inject Laravel’s BrowserKit instance directly:

    $driver = new Driver($this->app['browserkit']);
    
  2. Combine with Mink Extensions Use mink-extension for Laravel-specific helpers:

    composer require dusk-framework/dusk:mink-extension
    
  3. Performance Optimization Reuse the BrowserKit instance across tests to avoid overhead:

    $browserKit = $this->app['browserkit'];
    $driver = new Driver($browserKit);
    
  4. Custom Assertions Extend Mink’s assertions for Laravel-specific checks:

    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->elementTextContains('css', '.alert', 'Success');
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware