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.
(Letters a, b, c and d are represented by i, ii, iii and iv in the below text.)
- Test setup:
- Start the proxy-server via ProcessBuilder using the JSCover executable directory.
- Testing:
- Begin executing tests, perform GET-URL action.
- Proxy-server: passes GET requests directly to web-server.
- Begin executing tests, perform GET-URL action.
- Web-server:
- Respond to GET requests and sends files back to requestor (for files: HTML, CSS, JS,...).
- Proxy-server: Javascript file(s) are intercepted by JSCover proxy-server and instrumented, if not excluded from instrumentation.
- Proxy-server: Instrumented files are forwarded to browser.
- Proxy-server: Excluded from instrumentation files are passed-through to the browser.
- Proxy-server: Records the original Javascript and retains them in the JSCover reports directory.
- Testing:
- Performs normal test actions via the WebDriver API.
- Testing/capture report:
- invoke a store-report at end of each test, or during testing, or whenever.
- 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.
- Proxy-server: Receives jscoverage JSON and other datum which will be formatted and converted into JSCover report format files.
- Proxy-server: Report-files are stored in the JSCover reports directory. JSCover will also merge the data if existing datum files present.
- 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.