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
Page Object Extension

Page Object Extension Laravel Package

friends-of-behat/page-object-extension

View on GitHub
Deep Wiki
Context7

:pager: Default classes for Page object pattern in Behat

Frequently asked questions about Page Object Extension
Can I use this package with Laravel without Symfony dependencies?
Yes, but you’ll need to extend `SymfonyPage` into a custom `LaravelPage` class to replace Symfony-specific features like routing and dependency injection with Laravel equivalents (e.g., `route()` helper and the Illuminate container). The core `Page` and `Element` classes are framework-agnostic and work directly with Laravel.
How do I install this in a Laravel project?
Run `composer require friends-of-behat/page-object-extension --dev` in your project root. Ensure you also have `behat/behat` and a Laravel-Behat bridge (like `mabehas/laravel-behat`) installed, as this package depends on Behat itself. No additional Laravel-specific setup is required beyond these dependencies.
Will this work with Laravel 10+?
The package itself doesn’t enforce Laravel version constraints, but compatibility depends on your Behat and Laravel-Behat bridge versions. Test thoroughly, as Symfony-based routing helpers in `SymfonyPage` may need adjustments for Laravel’s routing system. Check the [Laravel-Behat bridge docs](https://github.com/mabehas/laravel-behat) for version alignment.
How do I handle Laravel’s routing in Page Objects?
Override `SymfonyPage`’s `getUrl()` method to use Laravel’s `route()` or `url()` helpers instead of Symfony’s `Router`. For example, replace `$this->router->generate()` with `route('your.route')`. This ensures Page Objects generate Laravel-compatible URLs dynamically.
Can I integrate this with Laravel’s Pest or PHPUnit tests?
This package is Behat-specific, so it won’t integrate directly with Pest or PHPUnit. However, you can use Page Objects for Behat scenarios while keeping Pest/PHPUnit for unit tests. Organize your test suite to avoid conflicts, or consider hybrid approaches where Behat handles BDD workflows and Pest handles unit/feature tests.
What’s the performance impact of using Page Objects in Laravel?
Page Objects add a layer of abstraction, which may slightly increase test execution time compared to native Laravel tools like Dusk. Benchmark your tests in CI to compare speeds, especially for large suites. Optimize by minimizing dynamic selectors and reusing Page/Element instances across scenarios.
How do I mock Laravel services in Page Objects?
Use Laravel’s container to bind mocks or dependencies in your `services.yml` (Behat config). For example, inject a mocked `Auth` facade or `RouteServiceProvider` via Behat’s dependency injection. Avoid hardcoding Laravel services in Page Objects to keep them reusable outside Laravel contexts.
Are there alternatives for Page Objects in Laravel?
Yes. For E2E testing, Laravel Dusk is tightly integrated and faster. For unit/feature tests, Pest or PHPUnit with custom Page Object libraries (like `laravel-testing`) may suffice. If you’re committed to Behat, this package is the most robust Page Object solution, but evaluate tradeoffs like setup complexity and CI overhead.
How do I handle dynamic content in Page Objects for Laravel apps?
Use Behat’s `wait()` or `retry()` steps to handle AJAX-heavy Laravel apps. For dynamic selectors, avoid hardcoding IDs/classes; use data attributes or unique text patterns. Combine with Laravel’s `waitFor()` helpers in Dusk-style tests if needed, though this requires custom logic in Page Objects.
Is this package actively maintained for Laravel?
The package is maintained by the FriendsOfBehat community, but it’s Symfony-focused. For Laravel-specific needs, monitor forks like `mabehas/laravel-behat` or consider contributing Laravel adaptations (e.g., a `LaravelPage` base class). The last major update was in 2021, so test stability in your Laravel version before production use.
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.
yandex/translate-api
voku/simple_html_dom
league/flysystem-vfs
bkwld/upchuck
filament/spatie-laravel-tags-plugin
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php