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 ...