Reputation: 137
I've been doing some research on the pros and cons of using a headless browser vs real browsers but am not sure how it all comes together.
I'm under the impression that:
Knowing the above, how do I approach building a test suite? What are valuable uses of the headless browser?
Upvotes: 1
Views: 291
Reputation: 397
About your impressions:
Tests in a headless browser run much faster
Maybe. Your mileage may vary here. Definitely spinning up a headless browser to perform a test should be faster than spinning up a full-fledged browser, but an overall performance improvement will depend on the tests and the system under test. If a test waits 30 seconds to perform an action, running it on a headless browser doesn't help; if the system under test takes a lot to answer to actions, running it on a headless browser doesn't help either.
A headless browser will miss certain things that may appear differently on specific browsers
True. It's an entire different browser with different engines. In a headless browser, tests will catch bugs that don't depend on the browser and bugs that only happen in a headless browser. It's worth considering the fact that the end users of your system won't use a headless browser normally, so you probably don't care about bugs that only happen in headless.
With this in mind, in order to approach building a test suite, take a closer look to your specific situation:
If your code has browser specific behaviour, you should validate that by writing tests that cover that specific behaviour and running them with the relevant browser.
However, having to run some tests in a specific browser doesn't mean your entire suite has to be run against that "real" browser. You can have generic tests run against a headless browser within your test suite, especially if your runs can benefit of a performance improvement that headless can provide in your case.
If your end users mostly use one browser and you don't expect that to change, maybe it's worth running the whole suite in that browser, taking it as your main focus and reference. You will catch bugs that matter most to your users, and that might compensate the performance loss you potentially get by not running headless.
Having said this, the more the browsers adhere to standards and behave similarly, the less browser specific issues and behaviour will happen, thus the more traction headless testing will get.
Upvotes: 3