codeception/lib-innerbrowser
InnerBrowser module for Codeception that simulates browser requests without a real browser. Useful for functional testing PHP web apps by sending GET/POST requests, managing cookies and sessions, following redirects, and asserting responses quickly in-memory.
Http testing layer (e.g., actingAs(), json(), assertStatus()) but extends it with DOM inspection—critical for UI-centric validation (e.g., flash messages, form errors) in acceptance tests.PhpBrowser/Symfony modules, meaning integration is opinionated but seamless for Laravel projects already using Codeception. For non-Codeception Laravel projects, requires wrapping (e.g., via a custom TestCase trait).$I->amOnPage('/dashboard') with session cookies) without spinning up a full browser.$I->see('Welcome')) or CSRF tokens in forms.Post::create() followed by $I->seeInDatabase()).symfony/dom-crawler) and PHPUnit 10–13, aligning with Laravel’s latest LTS (v10+). No direct Laravel dependencies, but works harmoniously with:
laravel/framework (for request/response handling).codeception/codeception (for test suites).codeception/module-laravel (for Laravel-specific helpers like seeInDatabase()).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Test Flakiness | DOM state may diverge if tests assume global state (e.g., shared sessions). | Use refresh() or amOnPage() to reset state; avoid static helpers. |
| Performance Overhead | In-memory parsing adds ~10–20ms per request vs. raw Laravel HTTP tests. | Benchmark against Http::fake() for API-heavy tests; reserve InnerBrowser for UI logic. |
| Debugging Complexity | Stack traces may obscure Codeception/InnerBrowser internals. | Enable debug: true in suite config; use dom_dump() for DOM inspection. |
| Upgrade Path | Breaking changes in Codeception (e.g., v5 migration) may require rework. | Pin to ^4.0 for stability; monitor Codeception’s lib-innerbrowser deprecations. |
| Customization Limits | Limited hooks for extending DOM behavior. | Override InnerBrowser class via module config or create a custom Codeception module. |
Http::fake() for API tests) or UI fidelity (InnerBrowser for Blade/form validation)?TestResponse assertions, or supplement them for DOM-specific checks?$I->amLoggedInAs().codeception/parallel module)?PhpBrowser/Symfony modules, which integrate with codeception/module-laravel via:
// tests/acceptance.suite.yml
modules:
enabled:
- Laravel:
environment_file: .env.testing
- PhpBrowser: ~ # Uses InnerBrowser under the hood
TestCase trait:
use Codeception\Lib\InnerBrowser;
trait InnerBrowserTestTrait {
protected InnerBrowser $browser;
protected function setUp(): void {
$this->browser = new InnerBrowser();
$this->browser->setRequestFactory($this->app->make('http.client'));
}
protected function submitForm(string $url, array $data): void {
$this->browser->amOnPage($url);
$this->browser->fillField('#email', $data['email']);
$this->browser->submitForm('#login-form');
}
}
mocks: For unit tests (no DOM inspection).seeElement(), dontSee()) vs. API-only tests (migrate to Http::fake()).composer.json:
composer require --dev codeception/codeception codeception/module-laravel codeception/lib-innerbrowser
acceptance.suite.yml with Laravel + PhpBrowser modules.simple_html_dom) in favor of InnerBrowser’s Crawler.TestResponse assertions that duplicate InnerBrowser’s DOM checks.| Component | Compatibility Status | Notes |
|---|---|---|
| Laravel 10/11 | ✅ Full support | Uses Symfony 7/8 components; no Laravel-specific hooks required. |
| PHPUnit 10/11/12/13 | ✅ Supported | Explicit support in releases 4.0.0–4.1.0. |
| Symfony 6/7/8 | ✅ Supported | Symfony 4/5 deprecated in v4.0.0+. |
| Blade Templates | ✅ Partial | Parses rendered HTML but won’t execute directives (e.g., @auth). |
| Sanctum/Passport Auth | ✅ Via Codeception Laravel module |
Uses $I->amLoggedInAs() to simulate authenticated requests. |
| JavaScript (AJAX) | ❌ No support | Redirects/JS-rendered content won’t update DOM. Use WebDriver for these cases. |
| Database Transactions | ✅ Via seeInDatabase() helper |
Works with Laravel’s DatabaseMigrations module. |
acceptance.suite.yml and PhpBrowser.TestResponse::assertSee() with $I->see() where DOM inspection is needed.dom_dump() in `How can I help you explore Laravel packages today?