dmore/behat-chrome-extension
DatabaseMigrations, DatabaseTransactions).| Risk Area | Description | Mitigation Strategy |
|---|---|---|
| Chrome Version Lock | CDP API may break across Chrome versions. | Pin Chrome version in CI/CD (e.g., chrome:114.0.5735.198) and test matrix. Monitor CDP changelog. |
| Behat Learning Curve | Adopting Behat/Gherkin adds complexity for teams unfamiliar with BDD. | Start with hybrid approach: Use Behat for E2E flows, PHPUnit for unit/feature tests. Provide internal documentation or workshops. |
| Flakiness | Chrome automation can be flaky (e.g., timing issues, race conditions). | Implement retry logic (e.g., Behat’s @retry tags) and use explicit waits (e.g., ->waitUntil()). |
| CI/CD Setup | Requires Chrome installation in headless environments (e.g., GitHub Actions, Docker). | Use pre-built Docker images (e.g., chromium:latest) or CI templates (e.g., Behat Chrome Extension’s GitLab CI example). |
| Debugging | Harder to debug than PHPUnit tests (e.g., no Xdebug integration for Chrome steps). | Use Chrome’s built-in DevTools for debugging and log CDP responses to files for post-mortem analysis. |
| Performance | Chrome instances consume more memory/CPU than PHPUnit tests. | Run E2E tests in parallel (Behat supports this) and separate them from unit tests in CI pipelines. |
ChromeDriver as a singleton).actingAs(), followRedirects()).RefreshDatabase, MigrateFresh) for Behat.| Component | Tool/Library | Justification |
|---|---|---|
| Test Runner | Behat | Core requirement for this package. |
| PHP Testing | PHPUnit | For unit/feature tests; keep separate from Behat. |
| Browser Automation | dmore/behat-chrome-extension |
Chrome-specific E2E testing. |
| Database Testing | Laravel’s DatabaseMigrations |
Pair with Behat for full-stack tests (e.g., "Given a user exists, when they visit X, then Y"). |
| CI/CD | GitHub Actions/Docker | For Chrome headless execution. |
loginAsUser()).composer require --dev behat/behat dmore/behat-chrome-extension
behat.yml to use Chrome:
default:
suites:
default:
contexts:
- FeatureContext:
chrome: true
extensions:
Behat\MinkExtension:
base_url: 'http://laravel.test'
browser_name: 'chrome'
Behat\ChromeExtension: ~
Feature: User Dashboard
Scenario: User sees their profile
Given I am logged in as "[email protected]"
When I visit "/dashboard"
Then I should see "Welcome, John"
use Behat\ChromeExtension\Context\ChromeContext;
use Behat\MinkExtension\Context\MinkContext;
class FeatureContext extends MinkContext {
use ChromeContext;
public function __construct() {
$this->useChrome();
}
/**
* @Given I am logged in as :email
*/
public function iAmLoggedInAs($email) {
// Use Laravel's HTTP client or session helpers
$response = $this->getSession()->getDriver()->getClient()->post('/login', [
'email' => $email,
'password' => 'password',
]);
// Assert login success (e.g., redirect to dashboard)
}
}
How can I help you explore Laravel packages today?