Installation:
composer require behat/mink-sahi-driver
Ensure behat/mink (~1.5) is also installed.
Prerequisites:
sahi.ini or environment variables.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
Test Suite Integration:
Behat services.yml or Laravel test bootstrapping:
# behat.yml
default:
extensions:
Behat\MinkExtension:
sessions:
sahi:
sahi: ~
Given I am on "/login"
When I click "Submit"
Then I should see "Welcome"
Laravel-Specific Usage:
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');
}
}
Dynamic Element Interaction:
//div[contains(@class, 'dynamic-class')]):
$session->getPage()->find('css', '.dynamic-class')->click();
Cross-Browser Testing:
$session->switchTo('sahi'); // Use Sahi for specific steps
Sahi Server Dependency:
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>
logs/sahi.log) for connection errors.Firefox-Specific Quirks:
sahi.ini or use a custom driver path:
new SahiDriver('firefox', 'http://localhost:9999', 'chrome')
Deprecated Package:
Element Visibility:
$session->wait(5000); // Wait 5 seconds for dynamic content
Performance:
sahi.ini for faster tests:
debug=false
Custom Selectors:
$session->getPage()->find('sahi', '//button[text()="Save"]')->click();
Laravel Artisan Commands:
// app/Console/Commands/StartSahi.php
public function handle()
{
Artisan::call('process:start', ['command' => 'sahi -p 9999']);
}
Extension Points:
SahiDriver to add custom assertions or logging:
class CustomSahiDriver extends SahiDriver
{
public function takeScreenshot($file)
{
// Custom logic
parent::takeScreenshot($file);
}
}
How can I help you explore Laravel packages today?