bhittani / web-browser
A convenience wrapper around laravel/dusk
Requires
- php: >=7.2
- bhittani/web-driver: ^0.6.0
- laravel/dusk: ^6.15
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-11-23 19:26:48 UTC
README
Programmatically navigate/test the web.
Requirements
- PHP >= 7.2
Install
You may install this package using composer.
$ composer require bhittani/web-browser
Install chrome driver
$ vendor/bin/install-chrome-driver
Install phantomjs driver
$ vendor/bin/install-phantomjs-driver
Usage
This package conveniently wraps laravel/dusk.
Chrome
First ensure you have installed the chrome driver.
<?php use Bhittani\WebBrowser\Chrome; $browser = new Chrome;
Phantomjs
First ensure you have installed the phantomjs driver.
<?php use Bhittani\WebBrowser\Phantomjs; $browser = new Phantomjs;
API
All browser instances extend Laravel\Dusk\Browser
, hence, the same API applies.
Example
<?php $browser->visit('https://example.com')->assertSee('Example');
Testing
We can also make assertions and capture failures within a testing environment.
<?php use Bhittani\WebBrowser\Browser; use Bhittani\WebBrowser\Phantomjs; use Bhittani\WebBrowser\Testing; Testing::bootstrap(); // Required for purging failed assertions. Browser::test(function ($browser1, $browser2/*, ... */) { $browser1->visit('https://example.com')->assertSee('Example'); $browser2->visit('https://example.net')->assertSee('Example'); }); Phantomjs::test(/*...*/); Testing::tearDown(); // Required for closing all browsers.
The above test callback will capture any failed assertions by taking a screenshot, save the console log and the source of a web page that caused the failure.
PHPUnit
A TestCase
class and a TestTrait
trait under the Bhittani\WebBrowser
namespace is included for making it easy to write your browser tests using PHPUnit
.
Changelog
Please see CHANGELOG for more information on what has changed.
Testing
$ git clone https://github.com/kamalkhan/web-browser $ cd web-browser $ composer install $ composer install-drivers $ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email shout@bhittani.com
instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see the License File for more information.