glhd / dawn
Requires
- php: ^8.1
- ext-json: *
- ext-pcntl: *
- ext-sockets: *
- ext-zip: *
- illuminate/support: ^9.0
- nyholm/psr7: ^1.5
- php-webdriver/webdriver: ^1.12
- react/http: ^1.7
- symfony/psr-http-message-bridge: ^2.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- laravel/sanctum: ^3.0
- mockery/mockery: ^1.3
- nunomaduro/collision: ^6.1
- orchestra/testbench: ^7.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ignition: ^1.0
This package is auto-updated.
Last update: 2024-10-29 23:50:59 UTC
README
Dawn
Dawn is an experimental browser-testing library for Laravel. It aims to be mostly compatible with Dusk, but with different trade-offs1. The main benefit of Dawn is that it allows you to write browser tests exactly as you write all other feature tests (database transactions, mocks, custom testing routes, etc). This generally means that they run faster and with fewer restrictions.
Warning This is a very early release. Some edge-cases have been accounted for. Many have not. Much of the Dusk API has been implemented, but plenty of methods and assertions are missing.
Installation
Install Dawn
You can install the development release of Dawn via Composer (you'll need PHP 8.1 and Laravel 9):
composer require glhd/dawn:dev-main
Install Chrome Driver globally
You'll also need chromedriver installed on your machine.
Note Eventually, Dawn will install a copy of chromedriver for you, just like Dusk. The current implementation has only been tested on MacOS with chromedriver installed via homebrew. YMMV.
Usage
To use Dawn, add RunsBrowserTests
to any test case. Then you can call openBrowser()
to get
a Browser
instance to start testing with.
class MyBrowserTest extends TestCase { use RefreshDatabase; use RunsBrowserTests; public function test_can_visit_homepage() { $this->openBrowser() // <-- this is Dawn ->visit('/') ->assertTitleContains('Home'); } }
Dawn API
Dawn aims to have an API that is mostly compatible with Laravel Dusk. Not all features or assertions are implemented, but for right now you're best using the Dusk documentation for reference.
Differences from Dusk
The primary API difference between Dawn and Dusk is that the Dawn APIs do not require browser
interactions to happen inside of callbacks. For the most part, this just involves replacing
calls to $this->browse()
with $this->openBrowser()
and removing the closure:
-$this->browse(function ($browser) { +$browser = $this->openBrowser(); $browser->visit('/login') -});
There are certain Dusk methods are either tricky to implement with Dawn's async I/O channel, or are impossible to recreate exactly due to serialization constraints (you cannot serialize a TCP connection, for example). Here are some such functions:
login()
,loginAs()
, etc — these don't make any sense in Dawn, because you can just use the normalactingAs()
orbe()
helper methods in your test.cookie()
andplainCookie()
— these will eventually be implementedelement()
andelements()
— because Dawn interacts with the WebDriver instance in a background process, it is a little harder to get direct access to the underlyingRemoteWebElement
instances in your main PHPUnit process. There will eventually be an API for accessing these, but it will likely work slightly differently.ensurejQueryIsAvailable()
— Dawn does not rely on jQuery
Dusk API Compatibility
Much of the Dusk API has been implemented, but not all of it.
Missing methods (may not be exhaustive):
pressAndWaitFor()
within()
/with()
/elsewhere()
/elsewhereWhenAvailable()
(scopes are generally not implemented yet)onComponent()
(components aren't implemented yet)
Missing assertions (may not be exhaustive):
assertVueContains()
assertVueDoesNotContain()
assertQueryStringHas()
assertQueryStringMissing()
Troubleshooting
- I get an error like `Failed to connect to localhost port 9515 after 2 ms: Couldn't connect to server`
- Make sure you have both `chromedriver` and the same version of Google Chrome installed.
FAQ
- Does it work on anything other that Chris's Mac?
- 🤷♂️
- Will it ever work on Windows?
- 🤷♂️ Probably?
- When can I use this?
- Fortune favors the brave.
- Is this the final API?
- Most of the `RunsBrowserTests` is pretty solid. The underlying implementation may change a ton before 1.0.
Major TODO Items
- Finish copying over the Dusk API
- Full test coverage
- Get automated tests running on Windows
- Improve the
chromedriver
installation/etc story - Get drag and drop working