2

Question restated:

How can we dynamically trigger, run, and get results back from CasperJS/PhantomJS tests via a web-app running NodeJS/Express/AngularJS?

Background and investigation:

Let me preface this question by saying that I understand there have been similar questions asked around this, which I have tried at length to do my due diligence on reading / understanding.

I believe my question is a little different because I understand that PhantomJS and NodeJS do not inherently work together due to a variety of reasons. There have been various projects that have attempted to "bridge" between NodeJS and PhantomJS. The one that always comes up is phantomjs-node.

However, as the author of that app points out there are a myriad of issues and the chief dev (I believe) of PhantomJS has indicated that they will not support NodeJS.

Got it. However, there are lots of test runners out there that seem to offer NodeJS integration and leverage PhantomJS. GruntJS for example, can leverage MochaJS tests, which in-turn can call JasmineJS, which apparently can be leveraged via PhantomJS.

Challenge/Differentiators

I don't want to test MY webapp and that seems to be the only use-case most tutorials and questions revolve around in the community. My use-case is testing other sites, already live for proper integration of a web app.

To that end I have a whole NodeJS / Express / AngularJS application that is a web-based test and reporting suite and I want to integrate the CasperJS / PhantomJS test results. I want to be able to dynamically pass a URL from my AngularJS front-end to my NodeJS / Express server, which will then trigger my CasperJS/PhantomJS tests and return the results in a fashion that I can include in my AngularJS reporting front-end.

Potential solution through calling separate process from NodeJS

I have seen reference, though I cannot find it now, of calling a "command" to generate a separate process to run PhantomJS from NodeJS. Is this the best way to accomplish my goals (I do not want to use one of the NodeJS / PhantomJS bridges if possible, tell me if I'm being too closed minded)?

Potential solution through Mocha visionmedia.github.io/mocha/

I have looked at Mocha and it appears promising, with their tagline being, "Mocha is a feature-rich JavaScript test framework running on node.js and the browser." However, they don't provide any examples of pluming those tests into a dynamic web-app like mine. They always come from the stance of assuming you are testing your app and you will be running a series of tests outside of your app instead of from within your app, as I intend to do.

This part looks particularly promising with Mocha Browser Support. It appears I could potentially use this in my front-end to trigger my Mocha tests, right?

Thanks for all your help in advance! I'm pretty new to testing so my head is swimming some here.

[EDIT] Related question(s), which do not 100% answer my question

Is it possible to run PhantomJS from node.js as a command line argument

Save and render a webpage with PhantomJS and node.js

Parse output of spawned node.js child process line by line

Community
  • 1
  • 1
arteedecco
  • 21
  • 3
  • Yes, using [child_process](http://nodejs.org/api/child_process.html) is probably the best option even if you need constant updates on the testing process. But what kind of test are we talking about here? You say you only want to give a URL to be tested and the server then returns the results to the front end. So, there is no script that you want to run for that specific site? There is only one (general) test script for every site? Btw, PhantomJS/CasperJS are also used for scraping or automating stuff and not only testing. – Artjom B. Sep 19 '14 at 17:15
  • @ArtjomB. thanks for the comment. I am not doing a ton of UI testing on these sites. I am looking to see if specific resources (JS files) are loaded and if certain DOM elements are present and if so, visible or not. I am also doing this with/without JS scripts loading on remote site, via resource.requested (CasperJS) and abort(). So "yes," there is a script being run, written ideally in CasperJS, which is a generic test run against any site URL passed via the front-end. I am aware of CasperJS getHTML() and getPageContent(), though those still mandate being able to load PhantomJS from my app. – arteedecco Sep 19 '14 at 17:42
  • I looks like the last link ([Parse output of spawned node.js child process line by line](http://stackoverflow.com/questions/9781214/parse-output-of-spawned-node-js-child-process-line-by-line)) answers your question pretty good. What is missing? – Artjom B. Sep 19 '14 at 18:13
  • @ArtjomB. yeah it is a solution I am going to try. However, I was hoping for way to utilize Mocha since as I noted it has the Browser Support. Is that something you can speak to? The idea of spawning multiple child processes for each user utilizing my testing app seems... problematic considering memory concerns and threads, right? – arteedecco Sep 19 '14 at 19:22
  • I can't speak about mocha, but the browser support you're linked to seems to be about mocha tests that run directly in the browser, but maybe I understood it wrong. Even if you use some framework that abstracts from the browser, you still need multiple processes for every user, because the under-the-hood (headless) browsers handle the cookies and therefore the session. If you don't care if multiple users share a session, then you could write a script that uses only one browser process for all users. I just don't think this would be possible with a testing framework like mocha. – Artjom B. Sep 19 '14 at 22:42

0 Answers0