Why don't use Docker for providing building, deploying and testing environments?
It will provide the kind of isolation that you require for building and testing your web app inside your Jenkins server.
You can define different environments to match your project's dependencies using Dockerfiles and building your own container images. Think of containers as very light weight virtual machines. In your case, for building and testing your web app I imagine you would need at least a machine with JDK and Selenium Webdriver installed.
There are a bunch of images available at the official Docker container registry, Dockerhub which you could use instead of building your own.
For a nice white paper on getting started using continuous integration with Docker and Jenkins go here
https://stackoverflow.com/questions/38012628/integration-tests-in-jenkins