Is there any tool available to determine the code coverage for my selenium tests?
My tests are written in Java having use of selenium WebDriver with BDD-Cucumber implementation in it.
-
1If you mean with your system-under-test, then yes all the standard code coverage tools should work. Start the server with code coverage tool enabled before you run your tests. If you mean code coverage on your selenium code then yes, also run it from your IDE debugger, but ask WHY do that. It gives you no meaningful information about the SUT.Martin Spamer– Martin Spamer2019年11月28日 14:31:25 +00:00Commented Nov 28, 2019 at 14:31
-
@MartinSpamer basically I want to know that how much dev code got hit with my selenium test scripts. Looking for a tool that has selenium integration which can give me info about how much dev code is covered with my selenium script.Updesh Kumar– Updesh Kumar2019年11月29日 07:08:42 +00:00Commented Nov 29, 2019 at 7:08
-
Then the SUT needs to be run under some dev harness that includes code coverage. JaCoCo is pretty solid way of doing this stand alone alternatively running the SUT in debug mode from within your IDE. The details depend the SUT more than the WebDriver or Cucumber. eclemma.org/jacoco/trun isk/doc/agent.htmlMartin Spamer– Martin Spamer2019年12月05日 22:46:52 +00:00Commented Dec 5, 2019 at 22:46
2 Answers 2
You can use Istanbul to instrument front-end code for code-coverage.
Process looks something like this:
- Start application with code instrumented by coverage tool
- Run the Cucumber/Selenium tests against web-app instance
- Generate report of with coverage tool
This article describes how you can use Istanbul to generate code-coverage from UI tests.
This question describes how to use Istanbul with Selenium.
Similar questions other tools:
-
Selenium scripts are written in java but the application I am testing is in javaScript. so looking out a tool which has integration with java (selenium) wrt application under test is in JavaScript.Updesh Kumar– Updesh Kumar2019年11月29日 10:47:30 +00:00Commented Nov 29, 2019 at 10:47
-
@UpdeshKumar The concept is the same. Added links for Istanbul the current most popular JavaScript code-coverage tool.Niels van Reijmersdal– Niels van Reijmersdal2019年11月29日 10:55:01 +00:00Commented Nov 29, 2019 at 10:55
-
@UpdeshKumar It was not very clear from your question that you wanted to test the front-end javascript code. Please write clearer question with more context.Niels van Reijmersdal– Niels van Reijmersdal2019年11月29日 10:56:19 +00:00Commented Nov 29, 2019 at 10:56
Finally, this solution works for me --
- Instrument the Istanbul.js.
Use Command - istanbul instrument test.js>> test-instumented.js
Now, use the below code in @AfterClass annotation. It will execute the below method after all tests.
AfterClass Implementation 4. Now, we have coverage.json.
- Crete a HTML using coverage,json using istanbul report.
-
What is the js.executeScript() line doing? Didn't see the use in your code. Also, can you please explain more about this? "Use Command - istanbul instrument test.js >> test-instumented.js" Once the dev frontend code is using instanbul, then can we use the production environment to run Selenium WebDriver automation?Sun Shine– Sun Shine2020年04月29日 18:55:38 +00:00Commented Apr 29, 2020 at 18:55
-
Your note in #3 seems to contradict the code sample you gave. You said @ AfterClass, but your coe is using @ AfterMethod. Which should it be, or is that even important?John Chesshir– John Chesshir2020年05月15日 14:24:34 +00:00Commented May 15, 2020 at 14:24
Explore related questions
See similar questions with these tags.