Automated Tester

.science

This content shows Simple View

Headless

Running Tests Headless with PhantomJS

PhantomJS is a headless web driver which will enable you to execute your Selenium tests without having to spin up a driver, this can improve the speed of your tests and use less resources. Commonly it is used in your CI builds when running acceptance tests.

It’s easy to implement and get up and running with lets get a copy of it from PhantomJS.org.

Next lets add the executable to our C# solution, set to Copy if newer and setup the driver:

private static void SetupHeadlessDriver()
{
PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
service.LoadImages = false;

Driver = new PhantomJSDriver(service);
}

You will notice I have included an service argument which is quite self explanatory, there are a number of these but rather than view them in detail here you can explore more options in the PhantomJS documentation.

You should now be able to run your tests without actually seeing anything on screen.




top