tntim96 / JSCover

JSCover is a JavaScript Code Coverage Tool that measures line, branch and function coverage
GNU General Public License v2.0
399 stars 84 forks source link

coverage data can not be reflected to the JSON file #217

Closed zhou777 closed 8 years ago

zhou777 commented 8 years ago

1)a part of instrumented code: ... $jscoverage['///*.js'].lineData[54]++; alert($jscoverage['///.js'].lineData[54]); data.getIndexHTML(); $jscoverage['///_.js'].lineData[55]++; cookie.setCookie("isLogin", "false"); ... 2)json data "lineData":...,0,0...

when I run the test case by chrome,(alert($jscoverage['//_/*.js'].lineData[54]);) was executed, And the result is 1. why can not be reflected to the JSON file?

※Only a part of the code in a file will have this problem.

tntim96 commented 8 years ago

Are you saving the JSON before it is executed? Can you provide a code snippet for me to reproduce the issue?

zhou777 commented 8 years ago

Are you saving the JSON before it is executed? when the testCase is finished,then I save the JSON file(self.report()).

Can you provide a code snippet for me to reproduce the issue? sorry,Because it involves ISMS, I can't provide JS code. At before, is there a similar problem?

code snippet of testCase : (testCase by selenium2 + python)

def test_login_logout_push(self):     
    driver = self.driver
    driver.get(self.base_url + "/")
    time.sleep(2)
    driver.find_element_by_id("login").click()
    element = driver.find_element_by_id("loginButton").is_displayed()
    self.assertTrue(element)

    driver.find_element_by_id("Password").clear()
    driver.find_element_by_id("Password").send_keys("admin")
    driver.find_element_by_id("loginButton").click()
    time.sleep(2)

    driver.find_element_by_id("login").click()
    time.sleep(2)
    self.report()
    driver.close()

def report(self):
    coverageJSON = self.driver.execute_script("return jscoverage_serializeCoverageToJSON();")  
    file = open("C:/src/jscoverage.json","w")

    file.write(coverageJSON)
    file.close()
tntim96 commented 8 years ago

No, I haven't seen this before. I suspect it's a timing issue, or the code is executed in another context. Have you tried with --local-storage?

zhou777 commented 8 years ago

I only used cookie,did not used html5's local storage.

tntim96 commented 8 years ago

Can you trying the file instrumentation with --local-storage and see if the result is the same?