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 Sahi Driver Laravel Package

behat/mink-sahi-driver

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require behat/mink-sahi-driver
    

    Ensure behat/mink (~1.5) is also installed.

  2. Prerequisites:

    • Install Sahi (Java-based automation tool) and ensure Sahi JS is running on your machine.
    • Configure Sahi to use Firefox (or another supported browser) via sahi.ini or environment variables.
  3. First Use Case: Configure Mink to use the Sahi driver in your Behat or custom test suite:

    use Behat\Mink\Mink;
    use Behat\Mink\Session;
    use Behat\Mink\Driver\SahiDriver;
    
    $mink = new Mink([
        'sahi' => new Session(new SahiDriver('firefox')),
    ]);
    

    Verify Sahi is accessible by running:

    sahi -p 9999
    

Implementation Patterns

Workflows

  1. Test Suite Integration:

    • Register the Sahi driver in your Behat services.yml or Laravel test bootstrapping:
      # behat.yml
      default:
        extensions:
          Behat\MinkExtension:
            sessions:
              sahi:
                sahi: ~
      
    • Use in feature files:
      Given I am on "/login"
      When I click "Submit"
      Then I should see "Welcome"
      
  2. Laravel-Specific Usage:

    • Extend Laravel’s HttpTestCase or DuskTestCase to include Mink:
      use Behat\Mink\Mink;
      use Behat\Mink\Session;
      
      class CustomTestCase extends TestCase
      {
          protected $mink;
      
          public function setUp(): void
          {
              $this->mink = new Mink([
                  'sahi' => new Session(new SahiDriver('firefox')),
              ]);
          }
      
          protected function getSession(): Session
          {
              return $this->mink->getSession('sahi');
          }
      }
      
  3. Dynamic Element Interaction:

    • Leverage Sahi’s advanced selectors (e.g., //div[contains(@class, 'dynamic-class')]):
      $session->getPage()->find('css', '.dynamic-class')->click();
      
  4. Cross-Browser Testing:

    • Switch drivers dynamically (e.g., Sahi for complex interactions, Selenium for others):
      $session->switchTo('sahi'); // Use Sahi for specific steps
      

Gotchas and Tips

Pitfalls

  1. Sahi Server Dependency:

    • Sahi must be running (sahi -p 9999) before tests execute. Use a pre-test hook or CI setup script:
      # In Laravel's phpunit.xml
      <php>
          <server name="SAHI_SERVER" value="http://localhost:9999"/>
      </php>
      
    • Debug Tip: Check Sahi logs (logs/sahi.log) for connection errors.
  2. Firefox-Specific Quirks:

    • Sahi defaults to Firefox. For Chrome/Edge, configure sahi.ini or use a custom driver path:
      new SahiDriver('firefox', 'http://localhost:9999', 'chrome')
      
  3. Deprecated Package:

    • Last updated in 2016; ensure compatibility with modern Mink (~1.5) and PHP (~7.4+).
    • Workaround: Fork the repo or use a wrapper for newer Mink versions.
  4. Element Visibility:

    • Sahi may fail on AJAX-heavy pages. Add waits explicitly:
      $session->wait(5000); // Wait 5 seconds for dynamic content
      

Tips

  1. Performance:

    • Disable Sahi’s debug mode in sahi.ini for faster tests:
      debug=false
      
  2. Custom Selectors:

    • Combine Sahi’s JS-based selectors with Mink’s methods:
      $session->getPage()->find('sahi', '//button[text()="Save"]')->click();
      
  3. Laravel Artisan Commands:

    • Create a custom command to start/stop Sahi:
      // app/Console/Commands/StartSahi.php
      public function handle()
      {
          Artisan::call('process:start', ['command' => 'sahi -p 9999']);
      }
      
  4. Extension Points:

    • Override SahiDriver to add custom assertions or logging:
      class CustomSahiDriver extends SahiDriver
      {
          public function takeScreenshot($file)
          {
              // Custom logic
              parent::takeScreenshot($file);
          }
      }
      
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle