Forum Discussion
I know NOTHING about this but I copied your question into Chat GPT. This may be complete rubbish but worth a shot to help! 🤪🤪
Retrieving window.__coverage__ in TestComplete (JavaScript)
TestComplete provides the ability to interact with browser content using Page and Eval methods. You can use this to fetch the coverage object.
Solution: Use Eval() to Retrieve window.__coverage__
Try the following JavaScript code in TestComplete:
function getCoverageData() {
var page = Sys.Browser("chrome").Page("*");
// Execute JavaScript in the browser context
var coverageData = page.Eval("JSON.stringify(window.__coverage__)");
if (coverageData) {
Log.Message("Coverage Data Retrieved");
Log.Message(coverageData); // Display the coverage JSON in the TestComplete log
// Save to a file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.CreateTextFile("C:\\temp\\coverage.json", true);
file.Write(coverageData);
file.Close();
Log.Message("Coverage data saved to C:\\temp\\coverage.json");
} else {
Log.Warning("No coverage data found. Ensure Istanbul is properly instrumented.");
}
}
How This Works
- Access the Browser Session
- Sys.Browser("chrome").Page("*") gets the active page.
- Extract window.__coverage__
- Using Eval("JSON.stringify(window.__coverage__)") runs JavaScript in the browser.
- Log & Save Coverage Data
- Displays the JSON data in the TestComplete log.
- Saves it to C:\temp\coverage.json for further analysis.
Next Steps
- Verify that your app is properly instrumented and window.__coverage__ is available.
- If using a different browser, replace "chrome" with "firefox" or "edge".
- Analyze the saved coverage.json using Istanbul's reporting tools:
npx nyc report --reporter=html
Then open coverage/index.html in your browser.
- allenjTC11 months agoNew Contributor
Thanks for the attempt, I already spent many hours interrogating ChatGPT with no useful results.
At best, page.contentDocument.Script.eval("JSON.stringify(window__coverage__)") runs but returns "No coverage data found" message, despite the fact that I can clearly see the data with "window.__coverage__" command in the console. I also have Cypress scripts on the same build that give me coverage.
page.Eval, page.eval and other variations mostly say "Unable to find the object". ChatGPT is particularly eager to tell me to use EvaluateJavaScript, a command that as far as I can tell only exists in one users unanswered question on StackOverflow.
- scot196711 months ago
Champion Level 3
Worth a shot. Post back if you figure it out. Good luck!