CasperJS, parallel viewing Using a testing platform

Question: I would like to know whether it is possible to perform parallel viewing using the testing environment in a single script file , therefore, using the tester module and the testing command casperjs.

I saw how some people create two casper instances: simultaneous CasperJS and https://groups.google.com/forum/#!topic/casperjs/Scx4Cjqp7hE requests , but as the document says, we cannot create a new casper instance in test script.

So, I tried to do something similar - a simple example - with testing a casper script (just copy and execute this, it will work):

var url1 = "http://casperjs.readthedocs.org/en/latest/testing.html" ,url2 = "http://casperjs.readthedocs.org/en/latest/testing.html" ; var casperActions = { process1: function () { casper.test.begin('\n********* First processus with our test suite : ***********\n', function suite(test) { "use strict"; casper.start() .thenOpen(url1,function(){ this.echo("1","INFO"); }); casper.wait(10000,function(){ casper.test.comment("If parallel, it won't be printed before comment of the second processus !"); }) .run(function() { this.test.comment('----------------------- First processus over ------------------------\n'); test.done(); }); }); }, process2: function () { casper.test.begin('\n********* Second processus with our test suite : ***********\n', function suite(test) { "use strict"; casper.start() .thenOpen(url1,function(){ this.echo("2","INFO"); }); casper.test.comment("Hi, if parallel, i'm first !"); casper.run(function() { this.test.comment('----------------------- Second processus over ------------------------\n'); test.done(); }); }); } }; ['process1', 'process2'].forEach(function(href) { casperActions[href](); }); 

But this is not parallel, they are executed one by one. I am currently doing parallel viewing, but with node, so not in the file itself, using a child process. Therefore, if you split my previous code into two files -proc1.js, proc2.js- (only two scripts-> casper.test.begin {...}) and run the code below through node, something like that will be work - with Linux, I have to look for the equivalent syntax for windows-:

 var exec = require("child_process").exec ; exec('casperjs test proc1.js',function(err,stdout,stderr){ console.log('stdout: ' + stdout); console.log('endprocess1'); }); exec('casperjs test proc2.js',function(err,stdout,stderr){ console.log('stdout: ' + stdout); console.log('endprocess2'); }); 

My problem is that the redirects and opening new URLs are quite long, so I want some of them to run in parallel. I could make XXX files and run them in parallel with node, but I do not want XXX files with 5 lines of code, so if someone managed (if possible) to open URLs in parrallel in the same test file without node (so without multiple processes), please teach me!

And I would like to know what is the difference between chaining instructions or reusing the casper object each time:

so meanwhile:

 casper.test.begin('\n********* First processus with our test suite : ***********\n', function suite(test) { "use strict"; casper.start() .thenOpen(url1,function(){ this.echo("1","INFO"); }) .wait(10000,function(){ casper.test.comment("If parallel, it won't be print before comment of the second processus !"); }) .run(function() { this.test.comment('----------------------- First processus over ------------------------\n'); test.done(); }); }); 

So what:

 casper.test.begin('\n********* First processus with our test suite : ***********\n', function suite(test) { "use strict"; casper.start(); casper.thenOpen(url1,function(){ this.echo("1","INFO"); }); casper.wait(10000,function(){ casper.test.comment("If parallel, it won't be print before comment of the second processus !"); }) casper.run(function() { this.test.comment('----------------------- First processus over ------------------------\n'); test.done(); }); }); 

Combining my instructions, will it block the entire chain if one of my steps fails (promise rejected) instead of following all the steps for each chassis?

So, it would be better to associate commands with dependent steps [for example, thenClick (selector)] and use a casper object with independent steps (for example, open a new URL), right?

Edit: I tried, and if the step fails, the chain or not, it will stop all subsequent steps, so I don't see the difference with the whole steps or not ...

+8
promise parallel-processing casperjs functional-testing
source share
2 answers

Well, chaining or using the casper object every time is just a matter of taste, it does the same thing, and we cannot run multiple instances of casper in a testing script. If you have a loop that opens some links, you have to wait for each page to load sequentially.

To start parallel viewing using a testing framework, you need to complete several processes, so using node does the trick.

After digging, I finally split the files with too many redirects to be no longer than my main script, which cannot be split. A folder with 15 files is executed - in parallel - after 2/4 minutes on the local computer.

+3
source share

There is no official support for parallel viewing right now in casperjs, there are several works around. I have set up several different environments and am going to check that the witch is one of the best

I see that one person works with multiple instances of casper in this way.

 var google = require('casper').create(); var yahoo = require('casper').create(); google.start('http://google.com/'); yahoo.start('http://yahoo.com/', function() { this.echo(google.getTitle()); }); google.run(function() {}); yahoo.run(function() {}); setTimeout(function() { yahoo.exit(); }, 5000); 

I am currently running multiple caspers in node using 'child_process' . It is very suitable for both the processor and memory.

+1
source share

All Articles