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.
## Getting Started
For Laravel developers using Codeception, `lib-innerbrowser` is the backbone of DOM parsing and HTTP request simulation in `PhpBrowser` and `Symfony` modules. Start by ensuring it’s installed via Codeception’s dependencies (no direct Composer install needed unless extending modules).
**First use case**: Write a test to validate a form submission without a real browser:
```php
// tests/acceptance/LoginCest.php
public function testLoginFormSubmission(AcceptanceTester $I)
{
$I->amOnPage('/login');
$I->fillField('#email', 'user@example.com');
$I->fillField('#password', 'secret');
$I->click('#submit-btn');
// InnerBrowser powers these assertions via Symfony's DomCrawler
$I->see('Welcome, User');
$I->seeInCurrentUrl('/dashboard');
}
Where to look first:
PhpBrowser module docs (uses InnerBrowser under the hood).tests/_support/Helper/Acceptance.php for custom assertions.$I->debugSection('response', $I->grabPageSource()).Use InnerBrowser’s crawler methods for element inspection:
// Check for elements, links, or text
$I->seeElement('#user-profile');
$I->dontSee('Error message');
// Extract data
$title = $I->grabTextFrom('h1');
$links = $I->grabMultiple('//a[@class="nav-link"]');
// Click/Submit forms
$I->click('Submit');
$I->submitForm('#login-form', ['email' => 'test@example.com']);
Leverage InnerBrowser’s request/response utilities:
// Assert headers or status codes
$I->seeResponseCodeIs(200);
$I->seeHttpHeader('Content-Type', 'application/json');
// Debug raw responses
$headers = $I->grabHttpHeader('X-CSRF-TOKEN');
$body = $I->grabPageSource();
PhpBrowser to simulate authenticated requests:
$I->amGoingTo('/admin');
$I->seeResponseContains('Admin Dashboard');
Client (backed by InnerBrowser).Extend functionality in _support/Helper/Acceptance.php:
public function seeLaravelFlashMessage($message)
{
$this->see($message, 'div.alert-success');
}
No JavaScript Execution:
WebDriver or Playwright.$I->see('Dynamic content') if it relies on JS.DOM State Caching:
$I->amOnPage() resets the DOM. Avoid chaining requests without reloads.$I->refreshPage() if needed.Deprecated Methods:
deleteHeader() → Use unsetHeader() (since v4.0.4).unsetHttpHeader().Symfony/DOM-Crawler Quirks:
name="field[0]" syntax if dynamic.fillField('#dynamic-field', 'value') instead of array keys.$I->debugSection('dom', $I->getDom()->html());
$I->debugSection('headers', $I->grabAllHttpHeaders());
# tests/acceptance.suite.yml
modules:
enabled:
- PhpBrowser:
debug: true
Custom DOM Manipulation:
Override InnerBrowser in a module:
// tests/_support/InnerBrowser.php
class CustomInnerBrowser extends \Codeception\Module\InnerBrowser
{
public function customAssertion()
{
// Extend with Laravel-specific logic
}
}
Register in suite.yml:
modules:
InnerBrowser:
class: \tests\_support\InnerBrowser
Mocking HTTP Responses:
Use Symfony’s Client mocking:
$client = $this->getModule('PhpBrowser')->getClient();
$client->getKernel()->getContainer()->set('router', $this->createMock(RouterInterface::class));
Performance:
$this->getModule('PhpBrowser')->getClient()->getContainer()->set('debug', false);
VerifyCsrfToken middleware is disabled in test routes.array driver in .env.testing for consistency:
SESSION_DRIVER=array
// tests/_bootstrap.php
putenv('QUEUE_CONNECTION=sync');
---
**Key Takeaway**: Treat `lib-innerbrowser` as a "black box" for DOM/HTTP interactions in Codeception. Focus on its integration with `PhpBrowser`/`Symfony` modules, and extend only when needed for Laravel-specific edge cases.
How can I help you explore Laravel packages today?