Closed hiteshsardana99 closed 7 years ago
Are you running Chrome? If so, try adding --allow-file-access-from-files
yes , i am running this on chrome , I am trying to debug jscoverage.js file . I have checked that , in jscoverage_load_body() funtion , i am getting null value in request variable .
So did you start Chrome with the --allow-file-access-from-files
switch?
yes , i have tried that also . i went to the folder where chrome,exe file exist , than i have given this below command in cmd . chrome.exe --allow-file-access-from-files
After that chrome is open , I loaded that jscoverage.html file , still 404 error is coming
Even i have opened that jscoverage.html file in IE , it is showing like this
And in microsoft edge browser it showing same as chrome browser ( 404 ERROR )
Hey , i checked the error in console . I found this below issue
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.\
I found one solution that i should open this file in Mozilla rather than any other browser . So it is working fine in Mozilla .
Thanks again
Great.
The other option is to serve the entire directory on a web-server and load it in that. You could do that with JSCover with:
java -cp JSCover-all.jar jscover.server.SimpleWebServer your-directory 8190
(for port 8190).
Hey , sorry to bother you again and again ..
Again , i am facing one problem .
I have run my all test cases on my instrument code , after that i have generated coverage report . When i have opened that jscoverage.html file . I have seen that most of coverge bars are red . According to code coverage statistics , no single function is running . It showing the function hit value is zero in all the js files .
I am not getting , what mistake i have done . I think this statistics are based on coverage report that is in json form and it means coverage report is not correct .
I am telling you in brief , what i did so far
1) Generated Instrument code 2) Run my all test cases on instrumented code 3) Generated coverage report ( loaded all instrument js files and jscoverage.js file and by taking the help of that function , generated report in json format) 4) saved that report in that folder , where jscoverge.html is present and others file . 5) Did some changed in jscoverge.js file and seen the statistics in jscoverage.html
Problem is - all bars are red and no single function get the hit .
I'm guessing you lost some of the coverage data between tests. You can keep the coverage data between page loads using HTML5 local storage switch.
If that won't work for some reason, you could save the JSON after each test (or whenever you think you're losing the coverage data) and merge them together.
I want to know thing . After instrumenting my js files , when i run the test cases than how jscover save the data , that these lines are executed and these functions get hit . Is it saving these values locally in one variable . Do i need to merge the json data , that is generated after each file ? .
How this process is going on , for each file ?
There's a working example using this technique in https://github.com/tntim96/JSCover/tree/master/examples/localStorage-file-system
When you run a test, the data is stored in _$jscoverage
When you leave a page with HTML5 local storage switch, it gets stored in (and loaded from) localStorage["jscover"]
Do i need to merge the json data , that is generated after each file ?
You shouldn't need to if using HTML5 local storage switch
How this process is going on , for each file ?
This is the local-storage code which hopefully answers that question for you:
if (typeof(_$jscoverage) === "undefined" && (typeof(Storage) !== "undefined") && typeof(localStorage["jscover"]) !== "undefined")
_$jscoverage = jscoverage_parseCoverageJSON(localStorage["jscover"]);
if (typeof(jscoverbeforeunload) === "undefined") {
jscoverbeforeunload = (window.onbeforeunload) ? window.onbeforeunload : function () {};
window.onbeforeunload = function () {
jscoverbeforeunload();
if ((typeof(_$jscoverage) !== "undefined") && (typeof(Storage) !== "undefined"))
localStorage["jscover"] = jscoverage_serializeCoverageToJSON();
};
}
I want to conform one thing ,
Is it correct way of generating report that , in one html file i have loaded all the instrumented js files ( to get the report of all js files ) and jscoverage.js file and than use that function
Because , when i am trying to debug this file to check , which lines are executing . I saw that it showing error in my code but at that period of time , i assume that only jscover lines should run, rather than my codes lines .
I don't understand the question. jscoverage_serializeCoverageToJSON()
will generate the data that goes in the jscoverage.json
file. How you execute that depends on your test tools. With WebDriver in Java you could do it like:
String json = (String)((JavascriptExecutor) webClient).executeScript("return jscoverage_serializeCoverageToJSON();");
//then write this to your file
In PhantomJS
var json = page.evaluate(function(){
return jscoverage_serializeCoverageToJSON();
});
try {
fs.write(system.args[2] + '/jscoverage.json', json, 'w');
} catch(e) {
console.log(e);
}
Hey , i want to know one thing . What will be the behavior of JSCover, if i will use it with parallel processing.
Now , what i am doing . I am running my test cases on instrument code with parallel processing to save my time . But in this approach , i am facing one problem . When i am running the jscoverage_serializeCovergaeToJSON() funtion in the end, I am not getting the complete report .
Can you suggest me something ?
You would need to save your results from jscoverage_serializeCovergaeToJSON()
from each process separately then merge them.
If jscoverage_serializeCovergaeToJSON()
itself is not returning data as expected, perhaps you are losing data between tests or overwriting it somehow. It's hard to tell without seeing your set-up.
hii !!...
First I have generated instrumented code using filesystem mode, after that using that instrumented code . I have generated json data using jscoverage_serializeCoverageToJSON(); function . Manually , i have taken the json data and saved in a file , I have given the filename - jscoverage.json and saved that json file in same directory , where jscoverage.html file and other files are present .
According to your instruction , i append the jscoverage_isReport = true; at the end of jscoverage.js file . When i did this , I did not get the report coverage . it showing 0% and i am also getting some errors
i have seen the jscoverage.js file , u have initialize jscoverage_isReport = false , initially. I have changed its value to true , than also i was facing same issue .
Please help me in this issue . i want to see code coverage statistics of my js files in jscoverage.html