All Projects → orchestral → Testbench Dusk

orchestral / Testbench Dusk

Licence: mit
[Package] Laravel Dusk Testing Helper for Package Development

Projects that are alternatives of or similar to Testbench Dusk

Rpg
Online Role Playing Game (based on Laravel)
Stars: ✭ 121 (+98.36%)
Mutual labels:  laravel, browser
Validatorjs
A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
Stars: ✭ 1,534 (+2414.75%)
Mutual labels:  laravel, browser
Laravel Health Check
A package for checking the health of your Laravel & Lumen applications
Stars: ✭ 59 (-3.28%)
Mutual labels:  laravel
Lashop
Simple shop based on Laravel 7.3
Stars: ✭ 60 (-1.64%)
Mutual labels:  laravel
Laravel Multiauth
Simple Multiple auth system using guards
Stars: ✭ 59 (-3.28%)
Mutual labels:  laravel
Wkzombie
WKZombie is a Swift framework for iOS/OSX to navigate within websites and collect data without the need of User Interface or API, also known as Headless browser. It can be used to run automated tests / snapshots and manipulate websites using Javascript.
Stars: ✭ 1,105 (+1711.48%)
Mutual labels:  browser
Browser Shell
A Linux command-line shell in the browser
Stars: ✭ 60 (-1.64%)
Mutual labels:  browser
Laravel Paytm Wallet
Integrate paytm wallet in your laravel application easily with this package. This package uses official Paytm PHP SDK's.
Stars: ✭ 58 (-4.92%)
Mutual labels:  laravel
Laravel Generator
laravel-generator / laravel代码生成器
Stars: ✭ 61 (+0%)
Mutual labels:  laravel
Laravel Simple Uploader
Simple file uploader for Laravel 5.
Stars: ✭ 59 (-3.28%)
Mutual labels:  laravel
Laravelinventry
Stock management application using Laravel 5.4
Stars: ✭ 60 (-1.64%)
Mutual labels:  laravel
Laravel admin api
基于laravel5.5开发的基础后台管理脚手架, RBAC权限控制; 接口基于dingo/api和tymon/jwt, 可在此基础上完成你的laravel项目
Stars: ✭ 59 (-3.28%)
Mutual labels:  laravel
Laravel Course
Laravel Essentials Udemy course Full Source Code
Stars: ✭ 59 (-3.28%)
Mutual labels:  laravel
Www.broqiang.com
个人博客,已经使用新的博客 https://github.com/broqiang/mdblog 此博客不再更新维护
Stars: ✭ 60 (-1.64%)
Mutual labels:  laravel
Multiformat Response Objects
Response objects for handling multiple response formats within the one controller
Stars: ✭ 59 (-3.28%)
Mutual labels:  laravel
Asciichart
Nice-looking lightweight console ASCII line charts ╭┈╯ for NodeJS, browsers and terminal, no dependencies
Stars: ✭ 1,107 (+1714.75%)
Mutual labels:  browser
Laravel Cachebuster
Adds MD5 hashes to the URLs of your application's assets, so when they change, their URL changes.
Stars: ✭ 58 (-4.92%)
Mutual labels:  laravel
Vultrdash
Vultr self-hosted dashboard.
Stars: ✭ 59 (-3.28%)
Mutual labels:  laravel
Connectivity
Detect if the network is up (do we have connectivity?)
Stars: ✭ 58 (-4.92%)
Mutual labels:  browser
Laravel Json Schema Assertions
JSON Schema assertions for the Laravel framework
Stars: ✭ 61 (+0%)
Mutual labels:  laravel

Laravel Dusk Testing Helper for Packages Development

The Testbench Dusk Component is a simple package that is supposed to help you write tests for your Laravel package using Laravel Dusk.

The package was developed by Konsulting Ltd and transferred to the Orchestra namespace where we will assist with supporting it in the future. It is in early development and feedback is appreciated.

tests Latest Stable Version Total Downloads Latest Unstable Version License

Version Compatibility

Laravel Testbench Dusk
5.4.x 3.4.x
5.5.x 3.5.x
5.6.x. 3.6.x
5.7.x. 3.7.x
5.8.x 3.8.x
6.x 4.x
7.x 5.x
8.x 6.x

Getting Started

Before going through the rest of this documentation, please take some time to read the following documentation:

Installation

To install through composer, run the following command from terminal:

composer require --dev "orchestra/testbench-dusk"

Usage

To use Testbench Dusk Component, all you need to do is extend Orchestra\Testbench\Dusk\TestCase instead of Laravel\Dusk\TestCase. The fixture app booted by Orchestra\Testbench\Dusk\TestCase is predefined to follow the base application skeleton of Laravel 7.

<?php

class BrowserTestCase extends Orchestra\Testbench\Dusk\TestCase
{
    //
}

Custom Host and Port

By default, Testbench Dusk will start its own PHP server at http://127.0.0.1:8000.

You can customize this by replacing the $baseServeHost and $baseServePort such as below:

<?php

class BrowserTestCase extends Orchestra\Testbench\Dusk\TestCase
{
    protected static $baseServeHost = '127.0.0.1';
    protected static $baseServePort = 9000;
}

Running with or without UI

Dusk 3.5+ offers the ability to run Dusk tests without UI (the browser window), and this is the default and is normally slightly quicker.
You can switch the behaviour with the following calls:

// To show the UI during testing
\Orchestra\Testbench\Dusk\Options::withUI();

// To hide the UI during testing
\Orchestra\Testbench\Dusk\Options::withoutUI();

We recommend you place this in a tests/bootstrap.php file, similar to this packages own test setup and use this for PHP Unit.

Database

By default you can either use sqlite, mysql, pgsql or sqlsrv with Testbench Dusk, however do note that it is impossible to use sqlite using :memory: database as you would with Testbench or Testbench BrowserKit.

If you opt to use sqlite, you might want to set the default database connection to sqlite either using phpunit configuration or setting it up on getEnvironmentSetUp() method.

/**
 * Define environment setup.
 *
 * @param  Illuminate\Foundation\Application  $app
 *
 * @return void
 */
protected function getEnvironmentSetUp($app)
{
    $this->app['config']->set('database.default', 'sqlite');
}

To create the sqlite database you just need to run the following code:

php vendor/orchestra/testbench-dusk/create-sqlite-db

Advanced Usage

Customising the Laravel App instance used during a test

We use the calling test class to build up the application to be used when serving the request.

Sometimes you will want to make a minor change to the application for a single test (e.g. changing a config item).

This is made possible by using the tweakApplication method on the test, and passing in a closure to apply. At the end of the test, you need to call the removeApplicationTweaks method to stop the changes being applied to the server.

An example test (can_tweak_the_application_within_a_test) is available in the tests/Browser/RouteTest.php test file.

Selectively running Dusk tests

Browser tests can take a while to run, so you could also separate your tests in your phpunit.xml file by providing different testsuites, allowing you to run your Browser tests on demand.

For example:

<testsuites>
    <testsuite name="Browser">
        <directory suffix="Test.php">./tests/Browser</directory>
    </testsuite>
    <testsuite name="Feature">
        <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>
    <testsuite name="Unit">
        <directory suffix="Test.php">./tests/Unit</directory>
    </testsuite>
</testsuites>

Run only your browser tests by running phpunit with the --testsuite=Browser option.

You can optionally set the default testsuite with the option defaultTestSuite="Unit".

Troubleshooting

Chrome versions

Facebook\WebDriver\Exception\SessionNotCreatedException: session not created: Chrome version must be between 70 and 73

If tests report following error, run the following command:

./vendor/bin/dusk-updater update

Alternatively you can run the following command to detect installed ChromeDriver and auto update it if neccessary:

./vendor/bin/dusk-updater detect --auto-update

Running Dusk and standard testbench tests in same suite

You may encounter the error PHP Fatal error: Cannot declare class CreateUsersTable, because the name is already in use in... when using loadLaravelMigrations() with some of your test extending the Dusk test class \Orchestra\Testbench\Dusk\TestCase and others extend the "normal" test class \Orchestra\Testbench\TestCase.

The problem arises because migrations are loaded from both packages' "skeletons" during the same test run, and Laravel's migration classes are not namespaced.

Solution

Make sure all integration tests in your test suite use the same Laravel skeleton (the one from testbench-dusk), regardless of the base class they extend by overriding getBasePath() in your test classes. Do the override in your base integration test class, or perhaps in a trait if you need it in multiple classes.

/**
* Make sure all integration tests use the same Laravel "skeleton" files.
* This avoids duplicate classes during migrations.
*
* Overrides \Orchestra\Testbench\Dusk\TestCase::getBasePath
*       and \Orchestra\Testbench\Concerns\CreatesApplication::getBasePath
*
* @return string
*/
protected function getBasePath()
{
    // Adjust this path depending on where your override is located.
    return __DIR__.'/../vendor/orchestra/testbench-dusk/laravel'; 
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].