📜 ⬆️ ⬇️

Laravel Dusk is close

Laravel dusk


Laravel provides a set of helper methods that are useful when writing end-to-end tests. They make it easy to click on the link, fill out the form and send it. Under the hood, Laravel uses the Symfony BrowserKit component to simulate the behavior of a web browser. However, if your application uses JavaScript and AJAX to load the page, BrowserKit will not be able to help you.


Laravel Dusk is a new tool that was added to Laravel 5.4 to solve this problem.


Laravel Dusk is a tool for end-to-end testing of your applications that use JavaScript. Its purpose is to provide the right way to test various interactive functions, such as clicking on a button or link, filling out a form, and even Drag and Drop!


Laravel Dusk uses ChromeDriver and Facebook PHP-WebDriver to perform end-to-end tests. It can also work with any Selenium browser, but by default it comes with ChromeDriver, which will allow you to avoid installing JDK or Selenium. This makes Dusk very easy to use. You do not need to go through the time-consuming installation process of Selenium and constantly start the server. Plus, Taylor Otvela noted that the tests in Dusk run faster than in Selenium.


Dusk allows you to wait until a condition becomes true or the CSS selector is available. All this allows you to better test applications using JavaScript.


Also Dusk automatically saves screenshots of failed tests! You can see what the page looked like and what went wrong.


Another nice feature is loginAs helpers, which allows you to log in and get the user's identity. At the same time, you can open any page where authorization is required without the need to log in each time.


Dusk allows you to open multiple browser windows for one test. This simplifies testing applications that use sockets: you can perform some actions in one window and get the result in another.


He also provided some information about the test environment in Dusk. The root of your application contains a .env.dusk file that stores the settings of the test environment. To run Dusk tests, you do not use PHPUnit directly. Instead, you call the artusan Dusk command, which backs up your .env file, replaces it with the .env.dusk file for the duration of the tests, and when it is completed, it restores your .env file.


Note that your tests written using BrowserKit will not be lost when upgrading from Laravel 5.3 to 5.4. For backward compatibility, there is a separate package - Laravel BrowserKit Testing .


')

Source: https://habr.com/ru/post/318704/


All Articles