Sunday, June 30, 2013

Selenium: Is there any JS (JavaScript) code coverage tool which we can integrate with Selenium Server/RC

Solutions
1.
I don't know what you are trying to achieve, but:
  • Selenium is testing the final output, as seen on the page itself.
So it really does not matter if its PHP, HTML, JSP, ASP or .NET - the Selenium is designed to mimick the end user and click the final application - the final HTML code generated by whatever is under the hood.
Selenium is also not that good for code coverage tests - one piece code can be on many pages - so better approach with selenium is to do the "user" coverage - try to cover all the possible actions which living human could possibly do with your page

2.
Not aware of a tool for Selenium, but JsTestDriver has a design very similar to Selenium RC (can launch tests from the command line and they are run on a server that drives browsers headlessly) and provides code coverage information.
IntelliJ integrates with JsTestDriver and provides a visual display of coverage information.

3.
In theory, you can use any coverage tool that instruments JavaScript code to collect coverage data.
For example, you can use JSCoverage either in proxy mode (for real-time instrumentation) or for static instrumentation to run your Selenium tests off the instrumented code.
One technical hurdle could be to devise a way to accumulate coverage data across multiple pages. The coverage tool of your choice could already have support for accumulation of data from multiple page runs. If not, you might have to handle that bit yourself, but this is probably not something trivial.

4.
There is no particular tool that can integrate with Selenium to do JS coverage. However there are lots of tools which test JS on every page which can tell if the JS that executing on your web page had any errors. This may not ideal solution but on each page you will have the measure of uptil which point JS executed properly on your webpage under test. There are two solutions for that:
1.) JSErrorCollector API: It will integrate directly with Selenium and let you know if there were any error on the page. Can be found at: http://mguillem.wordpress.com/2011/10/11/webdriver-capture-js-errors-while-running-tests/
2.) Full fledged JS coverage tools: There is an excellent list of tools here which will essentially help you in covering JS on on your web pages. Can be found at: Looking for a better JavaScript unit test tool

5.
I've integrated this tool in my Selenium tests a time ago. You need a bit of work to gather coverage info before page changes (in any case js trigger a page reload, link etc...)
Once you set up everything, it will fully coverage any js executed while Selenium load and test your website pages.
PS : Even if it was specially adapted for YUI test, you can use it with selenium.

1 comment: