Skip to content

Java Selenium 3 for javascript code coverage utility using JSCover

License

Notifications You must be signed in to change notification settings

DaveBrad/JscovTestUtil

Repository files navigation

JscovTestUtil

Java Selenium 3 class for javascript code coverage utility using JSCover

JscovTestUtil basic documentation

Provides a library class to use in Java Selenium to use JSCover to do code coverage on javascript as instrumented on-the-fly. JSCover primer: JSCover is used as an external program which uses a local proxy service to HTTP 'get' files from the web-server. A proxy process will instrument the javascript files as they are provided to the browser.

This is very useful class to test IoT device(s) that support a simple web-server capability (such as an ESP8266). JSCover may be used for any web-server, but be aware that it has limitations.

JSCover provides the ability to launch a browser to view reports of the Javascript files code coverage.

Alt image

(Letters a, b, c and d are represented by i, ii, iii and iv in the below text.)

  1. Test setup:
    • Start the proxy-server via ProcessBuilder using the JSCover executable directory.
  2. Testing:
    • Begin executing tests, perform GET-URL action.
      • Proxy-server: passes GET requests directly to web-server.
  3. Web-server:
    • Respond to GET requests and sends files back to requestor (for files: HTML, CSS, JS,...).
    1. Proxy-server: Javascript file(s) are intercepted by JSCover proxy-server and instrumented, if not excluded from instrumentation.
    2. Proxy-server: Instrumented files are forwarded to browser.
    3. Proxy-server: Excluded from instrumentation files are passed-through to the browser.
    4. Proxy-server: Records the original Javascript and retains them in the JSCover reports directory.
  4. Testing:
    • Performs normal test actions via the WebDriver API.
  5. Testing/capture report:
    • invoke a store-report at end of each test, or during testing, or whenever.
    1. Instrumented Javascript: Invoke the jscoverage_report(...) function in the instrumented Javascript. This will cause the script to forward captured results to the proxy-server directly.
    2. Proxy-server: Receives jscoverage JSON and other datum which will be formatted and converted into JSCover report format files.
    3. Proxy-server: Report-files are stored in the JSCover reports directory. JSCover will also merge the data if existing datum files present.
  6. Testing/stop:
    • On testing stop a request to terminate and stop the proxy-server is "called". This will cause a store-report first before stopping the JSCover proxy-server process on the system.

Why Netbeans project?

JscovTestUtil interacts with external programs: a-browser, JSCover proxy-server, and a pseudo web-server. Testing once through all these interactions involves integration tests, rather than unit tests.

TestNG is used to cause tests to be run sequentially.