PHPackages                             bk-ty/magic-test-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. bk-ty/magic-test-laravel

ActiveLibrary[Testing &amp; Quality](/categories/testing)

bk-ty/magic-test-laravel
========================

Use Magic Test with Laravel Dusk

v1.2(1y ago)28441[1 PRs](https://github.com/bk-ty/magic-test-laravel/pulls)MITPHPPHP ^7.4|^8.0

Since Mar 8Pushed 1y agoCompare

[ Source](https://github.com/bk-ty/magic-test-laravel)[ Packagist](https://packagist.org/packages/bk-ty/magic-test-laravel)[ Docs](https://github.com/bk-ty/magic-test-laravel)[ GitHub Sponsors](https://github.com/mateusjatenee)[ RSS](/packages/bk-ty-magic-test-laravel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (10)Versions (20)Used By (0)

Magic Test for Laravel
======================

[](#magic-test-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d45bfbc8c330b5b5826d155ce4aa5721eb031fa1aec9fbc94e8449022613a056/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616769632d746573742f6d616769632d746573742d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/magic-test/magic-test-laravel)[![GitHub Tests Action Status](https://camo.githubusercontent.com/be13dc569a66eb71000213da2308cbc55ac86754d65f58d3b6285bd2fd30c093/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d616769632d746573742f6d616769632d746573742d6c61726176656c2f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/magic-test/magic-test-laravel/actions?query=workflow%3ATests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ab40aacbac260bc3870ccdae833a1f35d25bfa473827364fe4b2308babfd4135/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d616769632d746573742f6d616769632d746573742d6c61726176656c2f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/magic-test/magic-test-laravel/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/cfff0c03df6d979ece5deb43aa81ef1afdd6985ea5b9a129607f86855fb5f5dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d616769632d746573742f6d616769632d746573742d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/magic-test/magic-test-laravel)

Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slowness of constantly restarting the testing environment.
It inverts the test-writing experience and avoids all the back and forth between tests, your terminal and your template files. [See it in action here.](https://twitter.com/mateusjatenee/status/1368905554790334464)
The easiest way to explain Magic Test is through a video. [Check it out here](https://twitter.com/mateusjatenee/status/1368905554790334464).

Magic Test was originally created by [Andrew Culver](http://twitter.com/andrewculver) and [Adam Pallozi](https://twitter.com/adampallozzi) for Ruby on Rails.
Laravel Magic Test was created by [Mateus Guimarães](https://twitter.com/mateusjatenee).

> Magic Test is still in early development, and that includes the documentation. Any questions you have that aren't already address in the documentation should be opened as issues so they can be appropriately addressed in the documentation.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require bk-ty/magic-test-laravel --dev
```

Usage
-----

[](#usage)

On your Laravel Dusk tests, simply add `magic()` at the end of your method chain. For example:

```
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/')
                    ->magic();
        });
    }
```

### Running Tests

[](#running-tests)

```
php artisan dusk:serve
```

This will start a `artisan serve` process in the background to execute your tests.

Recording Actions
-----------------

[](#recording-actions)

```
php artisan dusk:serve --browse
```

Behind the scenes, it is the same as running `php artisan dusk`, but it will maintain the browser window open. Within this browser, you can start configuring your tests using the `magic()` helper method.

Once the browser is open, Magic Test will already be capturing all of your actions. You can click around, fill inputs, checkboxes, selects and radios just like you would do manually testing an application.

Generating Assertions
---------------------

[](#generating-assertions)

Additionally, you can generate text assertions by selecting a given text and then pressing ControlShift + A. You'll see a dialog box confirming the assertion has been recorded.

Saving the new actions to the test file
---------------------------------------

[](#saving-the-new-actions-to-the-test-file)

To save the actions that were recorded, simply go to the Shell and type `ok`. You are free to close it and come back to your Magic Sessiona any time, or just keep recording more actions.
If you're satisfied with your test, you can type `finish` on the Shell and it'll remove the `magic()` call from your test, leaving you with a clean, working test.

See how it works [on this video](https://twitter.com/mateusjatenee/status/1368905554790334464)

Magic Test is still in it's early days, so you might find that the output is not exactly what you wanted. In that case, [feel free to submit an issue](https://github.com/magic-test/magic-test-laravel/issues/new) and we'll try to improve it ASAP.

Known issues
------------

[](#known-issues)

Magic Test does not work well with Inertia.js assertions. If you're using Inertia in an integration test, please disable Magic Test by add the following code to your `setUp` method:

```
