Why use Selenium with Laravel for testing?

Both Laravel and Selenium use PHPUnit statements. In Laravel and Selenium, you write code for testing (instead of doing something in the GUI, for example open: google.com , write in: name->queryInput text:"test search" , click: name->searchButton ) . Both Laravel and Selenium can visit web pages, submit forms and check the results. You can automate tests in both Laravel and Selenium by adding the PHPUnit command to cron.

So, why should I use Selenium for testing in Laravel ?

The only thing I could think of is that Selenium allows you to choose the browser in which the pages will open. Therefore, if your test passes using only Laravel testing, it may not work for some browsers, for example, Internet Explorer.

At this Laracast, the author says at 1:00:

One of the problems with this [testing in Laravel] is that it does not include JavaScript support. Therefore, instead, we fake the request, we get the answer, we check it, but the viewing mechanism or JavaScript is not involved in this process.

But what are the disadvantages of faking queries? How will selenium help? An example would be ideal.

+6
source share
1 answer

In fact, you already have an answer. What you declare is correct.

Laravel integrated tests will emulate requests internally and can take advantage of some benefits (e.g. Disabling middleware, Mocking, Spying, etc.) to ensure that you isolate a specific problem (test case). The idea is to test the application without introducing the side effects of third-party components into the battlefield, it will be: client browsers , external services , etc. These types of tests are very quick and easy. Also very suitable for testing API calls.

Thus, Selenium is designed to cover all of these cases in which you really want to cover those scenarios that affect the side effects of third-party components, such as JavaScript in Chrome, IE, Firefox, etc., even in different versions. You can understand this as trying to be as close as possible to a real-world scenario, where the client’s browser can actually interfere with the expected behavior of your application. You can also run screenshots if you want to visually check CSS or interactive components. It is important to note that because of this browser, these tests run slower.

The conclusion should be that you do not need to use one or the other exclusively . They work similarly, but in the end, they provide different possibilities. You may have a Laravel integration test suite and a Selenium test suite for those things that are important to you. I offer you this Laracast

I can provide you with an example in my project, but not an appropriate, but at least a way to show that both types of tests can coexist in the same project.

Hope this helps!

+6
source

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


All Articles