JSCover with PhantomJS - TypeError: "null" is not an object

When I try to start JSCover with PhantomJS, I see the ERROR below:

Steps:

1) Launch JSCover server:

java -jar ~/JSCover/target/dist/JSCover-all.jar -ws --report-dir=report

2) Run the PhantomJS runner with JSCover: *phantomjs --debug=true ~/JSCover/src/test/javascript/lib/PhantomJS/run-jscover-jasmine.js localhost8080/<app>/module/framework/test/SpecRunner.html

TypeError: 'null' is not an object (evaluating''document.body.querySelector (". Description '). InnerText')`

phantomjs://webpage.evaluate():3 phantomjs://webpage.evaluate():22 phantomjs://webpage.evaluate():22 2013-09-19T16:36:07 [DEBUG] WebPage - evaluateJavaScript result QVariant(, ) 2013-09-19T16: 36: 07 [DEBUG] WebPage - evaluateJavaScript "(function () {return (function () {jscoverage_report ('phantom');}) ();}) ()" 2013-09 -19T16: 36: 07 [DEBUG] WebPage - evaluation of the result of javaScript QVariant (,) 2013-09-19T16: 36: 07 [DEBUG] Network - Error requesting resource: 5 ("Operation canceled") URL: localhost8080/<app_home>/lib/backbone/1.0.0/backbone.js?cb=0.5381254460662603

+6
source share
3 answers

That was the problem I encountered yesterday. Turns out the sample script doesn't work for newer versions, so I created a new Phantom script that works for Jasmine 2.X that fixes it. You can find the working script here in my repository:

https://github.com/tkaplan/PhantomJS-Jasmine

+1
source

I ran into the same problem when trying to start Jasmine with PhantomJS. I realized that the latest version of Jasmine-html.js (jasmine-2.0.0-rc2) does not go along with PhantomJS run-jasmine.js (phantomjs-1.9.2-windows).

In Jasmine-html.js version, jasmine-2.0.0-rc2 version, the .description class is not available if all tests pass. This class 'description' is only created if the test fails.

Thus, when I run phantomjs with all the tests passed, I get the above error message. I modified run-jasmine.js to adapt to Jasmine-html.js (jasmine-2.0.0-rc2) to solve this problem.

0
source

Are you loading your tests asynchronously? I am using requirejs for modular javascript. It is also used to download test specifications:

 <script data-main='SpecRunner' src='/test/scripts/libs/require.js'></script> 

When using JSCover run-jscover-jasmine.js script does not take this asynchronous mode into account, so the DOM nodes referenced by the request do not yet exist. I modified the script to delay the call waiting for 1 second:

 page.open(system.args[1], function(status){ if (status !== "success") { console.log("Unable to access network"); phantom.exit(); } else { // Added 1s delay here window.setTimeout(function() { waitFor(function(){ return page.evaluate(function(){ return document.body.querySelector('.symbolSummary .pending') === null }); }, function(){ var exitCode = page.evaluate(function(){ console.log(''); console.log(document.body.querySelector('.description').innerText); var list = document.body.querySelectorAll('.results > #details > .specDetail.failed'); if (list && list.length > 0) { console.log(''); console.log(list.length + ' test(s) FAILED:'); for (i = 0; i < list.length; ++i) { var el = list[i], desc = el.querySelector('.description'), msg = el.querySelector('.resultMessage.fail'); console.log(''); console.log(desc.innerText); console.log(msg.innerText); console.log(''); } return 1; } else { console.log(document.body.querySelector('.alert > .passingAlert.bar').innerText); return 0; } }); page.evaluate(function(){ jscoverage_report('phantom'); }); phantom.exit(exitCode); }); }, 1000); } }); 

Depending on the amount of code downloaded, you may need to increase the delay.

0
source

Source: https://habr.com/ru/post/954210/


All Articles