Seeking a modern headless browser for Spring Boot app testing

Hey everyone, I’m working on a Spring Boot project with Thymeleaf and plain JavaScript for the frontend. We’re currently using HTMLUnit for our UI tests, but it’s causing some issues with newer JavaScript features.

For example, when we use array.flatMap(), HTMLUnit’s engine can’t handle it. This is becoming a problem as we try to use more modern JavaScript in our app.

Does anyone know of a good alternative to HTMLUnit that works well with Spring Boot? We need something that can handle newer JavaScript features and is easy to set up.

If you’ve used a different headless browser for testing Spring Boot apps, I’d love to hear about your experience. Any tips on integrating it would be super helpful too.

Thanks in advance for any suggestions!

I’ve been in a similar situation and found Puppeteer to be a great solution for Spring Boot testing. It’s a Node.js library that provides a high-level API to control Chrome or Chromium over the DevTools Protocol. While it’s not a Java-native solution, you can easily integrate it using something like js-executor.

Puppeteer handles modern JavaScript features like a champ, including ES6+ syntax. It’s also pretty fast and has great documentation. The setup process is straightforward, and you can run it in headless mode for CI/CD pipelines.

One thing to keep in mind is that you’ll need to have Node.js installed on your system. But once that’s done, integrating Puppeteer with Spring Boot is relatively painless. It’s been a game-changer for our team’s testing workflow, especially when dealing with complex JavaScript interactions.

Have you considered using Playwright? It’s a newer alternative that’s gaining traction in the testing community. I’ve used it on a recent Spring Boot project and it’s been fantastic for handling modern JavaScript.

Playwright supports multiple browsers (Chrome, Firefox, and Safari) out of the box, which is great for cross-browser testing. It’s also designed to handle modern web features seamlessly, so things like array.flatMap() won’t be an issue.

Integration with Spring Boot isn’t too complex. You can use the playwright-java library, which provides a Java API. The setup involves adding the dependency and writing a simple configuration.

One caveat: it’s a bit heavier than HTMLUnit, so your tests might run slightly slower. But the trade-off in terms of JavaScript support and stability is worth it in my experience. Give it a shot if you’re looking for a robust, future-proof solution.

hey mike, have u tried selenium with chrome headless? it’s pretty solid for modern js testing. i switched from htmlunit a while back and it’s been smooth sailing. setup’s not too bad either. just make sure u got the right webdriver version for ur chrome. good luck with ur project!