I encountered a technique recently which, I feel would be worth sharing. I found this while going through different automation technique in search for my quest :). Many of you would be aware of this already. Though it sounds scary but indeed a very helpful method to perform Regression and integration testing. It is the very innovative method of testing which is very fast and efficient. It’s know as Headless Automation.

What is Headless  Automation?

Headless Automation is a great way of creating light-weight tests that quickly send you results without the burden of actually opening a physical browser. So basically this way, we navigate to a website but save on the rendering time which may be beneficial in some scenarios like Continuous Integration where we want to have quick results and is more convenient to run from the command line(or a BAT file)

Here is a list of headless browsers that I know about:

  • HtmlUnit
    • Java.
    • Custom browser engine.
    • Limited JavaScript support/DOM emulated.
    • Open source.
  • Ghost
    • Python only.
    • WebKit-based.
    • Full JavaScript support.
    • Open source.
  • Twill
    • Python/command line.
    • Custom browser engine.
    • No JavaScript.
    • Open source.
  • PhantomJS
    • Command line/all platforms.
    • WebKit-based.
    • Full JavaScript support.
    • Open source.
  • Awesomium
    • C++/.NET/all platforms.
    • Chromium-based.
    • Full JavaScript support.
    • Commercial/free.
  • SimpleBrowser
    • .NET 4/C#.
    • Custom browser engine.
    • No JavaScript support.
    • Open source.
  • ZombieJS
    • Node.js.
    • Custom browser engine.
    • JavaScript support/emulated DOM.
    • Open source.
    • Based on jsdom.
  • EnvJS
    • JavaScript via Java/Rhino.
    • Custom browser engine.
    • JavaScript support/emulated DOM.
    • Open source.
  • Watir-webdriver with headless gem
    • Ruby via WebDriver.
    • Full JS Support via Browsers (Firefox/Chrome/Safari/IE).
  • Spynner
    • Python only.
    • PyQT and WebKit.
  • jsdom
    • Node.js.
    • Custom browser engine.
    • Supports JS via emulated DOM.
    • Open source.
  • TrifleJS
    • port of PhantomJS using MSIE (Trident) and V8.
    • Open source.
  • ui4j
    • Pure Java 8 solution.
    • A wrapper library around the JavaFx WebKit Engine incl.
    • headless modes.
  • Chromium Embedded Framework
    • Full up-to-date embedded version of Chromium with off-screen rendering as needed.
    • C/C++, with .NET wrappers (and other languages).
    • As it is Chromium, it has support for everything.
    • BSD licensed.
  • Selenium WebDriver
    • Full support for JavaScript via browsers (Firefox, IE, Chrome, Safari, Opera).
    • Officially supported bindings are C#, Java, JavaScript, Haskell, Perl, Ruby, PHP, Python, Objective-C, and R.
    • Unofficial bindings are available for Qt and Go.
    • Open source.

Headless browsers that have JavaScript support via an emulated DOM generally have issues with some sites that use more advanced/obscure browser features, or have functionality that has visual dependencies (e.g. via CSS positions and so forth), so whilst the pure JavaScript support in these browsers is generally complete, the actually supported browser functionality should be considered as partial only.

    1. Install NUnit from here and add a reference to the following DLL in your project – “C:\Program Files (x86)\NUnit.org\framework\3.0.5813.39031\net-4.0\nunit.framework.dll” (this path may change depending on your version and the path where you install NUnit)
See also  Going Back to QTP 11 from UFT 11.5

 

    1. Download Selenium Libraries from here and add reference to following DLLs in your Project(this would be present where you download selenium\selenium-dotnet-2.48.0\net40:-
      • Selenium.WebDriverBackedSelenium.dll
      • ThoughtWorks.Selenium.Core.dll
      • WebDriver.dll
      • WebDriver.Support.dll

       

    2. You will also need the phantomjs.exe from here. You need to add this to the bin\Debug folder in your project.

 

    1. In Order to capture snapshots(yes, this is possible for Headless Browsers also !), you need to add a reference to System.Drawing from the default assemblies available.

 

    1. For Nunit Fundamentals, you can refer this link.

 

Headless functional testing with PhantomJs and Selenium

The obvious downside to Selenium is that it requires a full graphical desktop for any and all tests.Selenium can now control PhantomJS in the same way that it does any other browser.

Selenium offers bindings in most popular programming languages, so we can choose a language according to our needs.I consider JavaScript to be the best choice for describing functional tests for websites and web applications.

  1. Mocha – test runner
  2. Chai – assertion library
  3. webdriverjs – browser control bindings
  4. Selenium – browser abstraction and running factory
  5. PhantomJS – fast headless browser

There are some pre-developed frameworks also available which can help you to run automated web applications and report their results on a regular basis in Jenkins.Framework can be found here

We will cover some more from these headless automation browsers in our upcoming posts.. stay tuned.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.