Selenium Code Coverage for Java Web Applications

In this 4mins video, you will see how to generate selenium code coverage for web application developed with Java in eclipse ide using RKTracer Tool with 3 simple steps.

  1. Enable the RKTracer tool and rebuild the application.
  2. Test instrumented application and save coverage data.
  3. Generate code coverage reports

Code Coverage tool integration with Eclipse IDE

1: Close all instances of Eclipse IDE.

2: Open a new command prompt and run the following command to install the RKTracer tool plugin for eclipse IDE.

rktracer -ec -integrate

code coverage eclipse IDE Integration step 1
code coverage eclipse IDE Integration step 1

Once successfully RKTracer tool is integrated with Eclipse IDE. You can see RKTracer tool options in Run menu–> External tools

code coverage eclipse IDE Integration step 2
code coverage eclipse IDE Integration step 2

Selenium Code Coverage for Java based Web Application

Ensure that you’re able to build the application and run the selenium tests.

Enable the RKTracer tool

Select the project in eclipse in the project explorer and enable the RKTracer tool.

Run–> External Tools –> RKTracer ON

Selenium code coverage for Java Web Applications in eclipse IDE step 1
Selenium code coverage for Java Web Applications in eclipse IDE step 1

Rebuild and run selenium tests

Run maven clean and maven test to build web application and run selenium tests. In general, testing can be unit testing or functional testing.

Selenium code coverage for Java Web Applications in eclipse IDE step 2
Selenium code coverage for Java Web Applications in eclipse IDE step 2
Selenium code coverage for Java Web Applications in eclipse IDE step 3
Selenium code coverage for Java Web Applications in eclipse IDE step 3

Generate Code Coverage reports

Go to –>Run menu–> External Tools –> RKTracer Report.

Selenium code coverage reports
Selenium code coverage reports

Enable coverage for selected files

Generate coverage reports  for the selected folders

C:\project\sound\drivers\base\power\

C:\project\sound\drivers\base\power\firmware_loader\

C:\project\sound\drivers\core\

C:\project\sound\security\keys\

C:\project\sound\security\lockdown\

Suppose you need code coverage for source files from three different folders, i.e., core, keys, power, and ignore coverage for folders firmware_loader and lockdown. Edit rktracer.config in the RKTracer installation folder and go to the end of the file add the following information. 

ignore *.java

instrument */power/* */core/* */keys/*

never */firmware_loader/* */lockdown/*

ignore *.java = Ignores all Java source files from instrumentation

Instrument = Instrument source files from given folders

never = ignore selected folder  

Generate coverage reports only for selected functions from three different files.

fun_X() in source-file-X 

fun_Y() in source-file-Y

fun_Z() in source-file-Z

Suppose you need code coverage for selected functions from three different files. Edit rktracer.config in the RKTracer installation folder and go to the end of the file and set the following variables as shown below.  

ignore *.java

instrument *source-file-X.java *source-file-Y.java *source-file-Z.java

function-ignore *

function-instrument fun_X() fun_Y() fun_Z()

ignore *.java = Ignore all Java programming source files

instrument *file-X.java  *file-Y.java  *file-Z.java  = Instrument only these three source files.

function-ignore * = Then ignore all functions in the above three files.function-instrument fun_X() fun_Y() fun_Z() = Don’t ignore these three functions from these three files from instrumentation

Similar Posts