Use this on Chrome for using osmesa
sudo apt-get install libosmesa
sudo ln -s /usr/lib/x86_64-linux-gnu/libOSMesa.so.6 /opt/google/chrome/libosmesa.so
google-chrome --no-first-run --user-data-dir=~/chrome-stuff --use-gl=osmesa
Warning: If your using osmesa, the entire page will be rendered with osmesa thus making it slow. So, if you can run tests that do not need WebGL, then this is preferable.
You might also want to know that Chrome itself uses osmesa to headless test. But not all versions. Check out the suported versions here: https://cs.chromium.org/chromium/src/third_party/mesa/README.chromium
Or else, for running headless in general, you can use this: https://gist.github.com/addyosmani/5336747