Introducing Laravel Dusk0:00
Okay, next step, I get to show you Laravel Dusk. Let's pull it in. Now, Laravel Dusk is going to give you the ability to browser test your applications. So when you perform a test, it's literally going to open up a browser and interact with it. And this way, if you want to test behavior in JavaScript, all of that can now be done really, really simply. In the past, we had to use things like Selenium, and they were tricky, and you'd get lots of false positives or false failures. I think you're going to like this quite a bit.
Registering Dusk Provider0:23
false positives or false failures. I think you're going to like this quite a bit. All right, that's done. So as always, we're going to add the service provider so that Dusk can bootstrap itself with Laravel. In my config/app.php file, we're going to go down to the providers section, and we're going to pull in Laravel Dusk, DuskServiceProvider. This will add the necessary artisan commands and things like that. So if we run php artisan now and scroll up, you should now see a new section specifically for Dusk.
Installing Dusk Scaffolding0:47
So if we run php artisan now and scroll up, you should now see a new section specifically for Dusk. One to install the application, and basically that's going to copy over some boilerplate and stubs to your test directory. One to create a new test class, and then one to create a page class, which is a page object is like a wrapper around a page so that you can associate URIs and elements with identifiers. Anyways, let's go ahead and run dusk:install and switch back to Sublime. You'll now see in your test directory, it looks a little bit different. You have this new DuskTestCase. So any Dusk specific class will extend this.
You have this new Dusk test case. So any Dusk specific class will extend this. Next you'll see a new browser directory. Let's take a look at the example test. All right, open up a browser, visit the home page, and expect to see Laravel. We're all set to run this, but real quick I'm going to go into my config/app.php directory, and I will set my app URL. So you can see here it's referencing an app URL environment variable, so let's update that to be laravel54.dev. That's the domain I'm using.
Running First Dusk Test1:47
that to be laravel54.dev. That's the domain I'm using. Okay, let's run the test. php artisan dusk, and we get green. Okay, great. So this means if we switch back, you can now interact with the browser. You can open up modals, you can press buttons, you could type some text into an input, you could click a link, there's a lot you can do here. And in fact, you can even open up multiple browsers, and this would be good for testing real-time applications.
