Js Code Coverage With Selenium Tests
Solution 1:
A tool like nyc is what you need. Take your js file(s) and run something like
nyc instrument
on them and nyc will modify the js files to record coverage. Use these modified files in your website. Then run your selenium tests. At the end of the selenium test, you need to capture the data from the JS files and save it to a json file. I use this code for that.
IJavaScriptExecutor js = (IJavaScriptExecutor)driver; string coverageData = (string)js.ExecuteScript("return JSON.stringify(window.cov_h0rgge4zy);"); File.WriteAllText(@"C:\someDir\coverage\" + DateTime.Now.Ticks + ".json", "{\"someFile\":" + coverageData + "}");
then run something like
nyc report html someCoverage.json
and you'll get the coverage report, html format
Solution 2:
Solution 3:
keep generated .json file in .nyc_output directory then run below command. nyc report --reporter=html
reference https://istanbul.js.org/docs/advanced/coverage-object-report/
Post a Comment for "Js Code Coverage With Selenium Tests"