I’m working on a WebGL project that uses GLGE framework and I need to set up automated testing. The challenge is that I want to run these tests on my CI/CD pipeline using Jenkins, which means I need a headless environment.
I’ve been looking into using PhantomJS for this purpose, but I’m not sure if it properly supports WebGL rendering without a display. Has anyone managed to get WebGL unit tests working in a headless setup? I’m particularly interested in whether the WebGL context initializes correctly and if rendering operations can be tested.
Any experiences or alternative solutions would be really helpful. Thanks in advance!
You’ll need mesa-utils and xvfb-run for WebGL tests without a display on Linux CI. I ran into this exact problem setting up automated tests for a Three.js app last year. The trick is getting the virtual framebuffer configured right with proper color depth settings. Don’t just use headless browsers - I’ve found xvfb + Firefox headless gives way more consistent WebGL context initialization than Chrome. Mesa’s software renderer handles most WebGL stuff fine for testing, just expect it to be slower than hardware acceleration. Make sure you’ve got libgl1-mesa-dri installed and set LIBGL_ALWAYS_SOFTWARE to force software rendering when there’s no GPU access.
WebGL tests in CI are tricky, but Docker containers with headless Chrome work pretty well. You need proper GPU support or software rendering fallbacks in your container. I use --disable-gpu-sandbox and --disable-software-rasterizer flags when launching headless Chrome for WebGL tests. PhantomJS has weak WebGL support and breaks on complex rendering - I’d skip it. Selenium WebDriver with headless Chrome has been way more stable for our WebGL tests. Playwright’s another good option since it handles WebGL contexts better than most alternatives. Just make sure your CI environment has the graphics libraries installed, even for software rendering.
i’ve had good luck with puppeteer for doing headless testing with webgl, way better than phantom. xvfb is ok, but you might run into some issues. def check if your tests are running smooth in headless chrome tho. good luck!