kamalkhan / web-browser

Programmatically navigate/test the web using php. A convenience wrapper around laravel/dusk.
MIT License
0 stars 0 forks source link
browser dusk laravel testing web

Web Browser Build Status Total Downloads MIT License

Programmatically navigate/test the web.

Requirements

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.