Skip to content

sebsobseb/dawn

 
 

Repository files navigation

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.

Dusk API Compatibility

Much of the Dusk API has been implemented, but not all of it.

Missing methods (may not be exhaustive):

  • whenAvailable()
  • waitFor()
  • waitUntilMissing()
  • waitUntilMissingText()
  • waitForText()
  • waitForTextIn()
  • waitForLink()
  • waitForInput()
  • waitForLocation()
  • waitForRoute()
  • waitUntilEnabled()
  • waitUntilDisabled()
  • waitUntil()
  • waitUntilVue()
  • waitUntilVueIsNot()
  • waitUntilVueIsNot()
  • waitForReload()
  • clickAndWaitForReload()
  • waitForEvent()
  • waitUsing()
  • attach()
  • pressAndWaitFor()
  • drag()
  • dragUp()
  • dragDown()
  • dragLeft()
  • dragRight()
  • dragOffset()
  • moveMouse()
  • mouseover()
  • clickAtPoint()
  • clickAtXPath()
  • clickAndHold()
  • doubleClick()
  • rightClick()
  • releaseMouse()

Missing assertions (may not be exhaustive):

  • assertVueContains()
  • assertVueDoesNotContain()
  • assertQueryStringHas()
  • assertQueryStringMissing()

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.

Footnotes

  1. Dawn is generally easier to use out of the box, but writing custom low-level WebDriver code is trickier due to how Dawn works under the hood.

About

Experimental next-gen browser testing for Laravel

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 57.9%
  • JavaScript 36.8%
  • CSS 4.9%
  • Blade 0.4%