Skip to content

Instantly share code, notes, and snippets.

@michaelhollman
Last active September 3, 2020 07:20
Show Gist options
  • Save michaelhollman/6072862 to your computer and use it in GitHub Desktop.
Save michaelhollman/6072862 to your computer and use it in GitHub Desktop.
The woes of CasperJS nesting
//nesting thens
casper.then(function () {
this.log('THEN #1', 'info', 'then');
this.then(function () {
this.log('THEN #2', 'info', 'then');
this.then(function () {
this.log('THEN #3', 'info', 'then');
});
this.log('THEN #4', 'info', 'then');
this.then(function () {
this.log('THEN #5', 'info', 'then');
});
this.log('THEN #6', 'info', 'then');
});
this.log('THEN #7', 'info', 'then');
this.then(function () {
this.log('THEN #8', 'info', 'then');
this.then(function () {
this.log('THEN #9', 'info', 'then');
});
this.log('THEN #10', 'info', 'then');
this.then(function () {
this.log('THEN #11', 'info', 'then');
});
this.log('THEN #12', 'info', 'then');
});
this.log('THEN #13', 'info', 'then');
});
//nesting thenopens
casper.thenOpen('', function () {
this.log('THENOPEN #1', 'info', 'thenOpen');
this.thenOpen('', function () {
this.log('THENOPEN #2', 'info', 'thenOpen');
this.thenOpen('', function () {
this.log('THENOPEN #3', 'info', 'thenOpen');
});
this.log('THENOPEN #4', 'info', 'thenOpen');
this.thenOpen('', function () {
this.log('THENOPEN #5', 'info', 'thenOpen');
});
this.log('THENOPEN #6', 'info', 'thenOpen');
});
this.log('THENOPEN #7', 'info', 'thenOpen');
this.thenOpen('', function () {
this.log('THENOPEN #8', 'info', 'thenOpen');
this.thenOpen('', function () {
this.log('THENOPEN #9', 'info', 'thenOpen');
});
this.log('THENOPEN #10', 'info', 'thenOpen');
this.thenOpen('', function () {
this.log('THENOPEN #11', 'info', 'thenOpen');
});
this.log('THENOPEN #12', 'info', 'thenOpen');
});
this.log('THENOPEN #13', 'info', 'thenOpen');
});
//nested waitFors
casper.waitFor(function () { return true }, function () {
this.log('WAITFOR #1', 'info', 'waitFor');
this.waitFor(function () { return true }, function () {
this.log('WAITFOR #2', 'info', 'waitFor');
this.waitFor(function () { return true }, function () {
this.log('WAITFOR #3', 'info', 'waitFor');
});
this.log('WAITFOR #4', 'info', 'waitFor');
this.waitFor(function () { return true }, function () {
this.log('WAITFOR #5', 'info', 'waitFor');
});
this.log('WAITFOR #6', 'info', 'waitFor');
});
this.log('WAITFOR #7', 'info', 'waitFor');
this.waitFor(function () { return true }, function () {
this.log('WAITFOR #8', 'info', 'waitFor');
this.waitFor(function () { return true }, function () {
this.log('WAITFOR #9', 'info', 'waitFor');
});
this.log('WAITFOR #10', 'info', 'waitFor');
this.waitFor(function () { return true }, function () {
this.log('WAITFOR #11', 'info', 'waitFor');
});
this.log('WAITFOR #12', 'info', 'waitFor');
});
this.log('WAITFOR #13', 'info', 'waitFor');
});
casper.run(function () {
this.test.done();
});
PS C:\hudl\hudl\functests> casperjs test nest-test.js --direct --log-level=info --includes=include.js --pre=pre.js --scr
eenCaptureDir=captures/ --site=http://www.hudl.com
Test file: C:/hudl/hudl/functests/pre.js
[info] [phantom] Starting...
[info] [phantom] Running suite: 1 step
PASS 200 for http://www.hudl.com/
[info] [phantom] Step 1/1 http://www.hudl.com/ (HTTP 200)
[info] [hudl] ---- Creating Hudl users from users.js ----
[info] [hudl] ---- Finished creating Hudl users from users.js ----
[info] [phantom] Step 1/1: done in 19338ms.
[info] [phantom] Done 1 steps in 19344ms
Test file: nest-test.js
[info] [phantom] Running suite: 5 steps
[info] [phantom] Step 2/5 http://www.hudl.com/ (HTTP 200)
[info] [then] THEN #1
[info] [then] THEN #7
[info] [then] THEN #13
[info] [phantom] Step 2/5: done in 19378ms.
[info] [phantom] Step 3/7 http://www.hudl.com/ (HTTP 200)
[info] [then] THEN #2
[info] [then] THEN #4
[info] [then] THEN #6
[info] [phantom] Step 3/7: done in 19390ms.
[info] [phantom] Step 4/9 http://www.hudl.com/ (HTTP 200)
[info] [then] THEN #3
[info] [phantom] Step 4/9: done in 19396ms.
[info] [phantom] Step 5/9 http://www.hudl.com/ (HTTP 200)
[info] [then] THEN #5
[info] [phantom] Step 5/9: done in 19406ms.
[info] [phantom] Step 6/9 http://www.hudl.com/ (HTTP 200)
[info] [then] THEN #8
[info] [then] THEN #10
[info] [then] THEN #12
[info] [phantom] Step 6/9: done in 19419ms.
[info] [phantom] Step 7/11 http://www.hudl.com/ (HTTP 200)
[info] [then] THEN #9
[info] [phantom] Step 7/11: done in 19426ms.
[info] [phantom] Step 8/11 http://www.hudl.com/ (HTTP 200)
[info] [then] THEN #11
[info] [phantom] Step 8/11: done in 19437ms.
PASS 200 for http://www.hudl.com/
[info] [phantom] Step 10/11 http://www.hudl.com/ (HTTP 200)
[info] [thenOpen] THENOPEN #1
[info] [thenOpen] THENOPEN #7
[info] [thenOpen] THENOPEN #13
[info] [phantom] Step 10/11: done in 20986ms.
PASS 200 for http://www.hudl.com/
[info] [phantom] Step 12/15 http://www.hudl.com/ (HTTP 200)
[info] [thenOpen] THENOPEN #2
[info] [thenOpen] THENOPEN #4
[info] [thenOpen] THENOPEN #6
[info] [phantom] Step 12/15: done in 22432ms.
PASS 200 for http://www.hudl.com/
[info] [phantom] Step 14/19 http://www.hudl.com/ (HTTP 200)
[info] [thenOpen] THENOPEN #3
[info] [phantom] Step 14/19: done in 24103ms.
PASS 200 for http://www.hudl.com/
[info] [phantom] Step 16/19 http://www.hudl.com/ (HTTP 200)
[info] [thenOpen] THENOPEN #5
[info] [phantom] Step 16/19: done in 25496ms.
PASS 200 for http://www.hudl.com/
[info] [phantom] Step 18/19 http://www.hudl.com/ (HTTP 200)
[info] [thenOpen] THENOPEN #8
[info] [thenOpen] THENOPEN #10
[info] [thenOpen] THENOPEN #12
[info] [phantom] Step 18/19: done in 27049ms.
PASS 200 for http://www.hudl.com/
[info] [phantom] Step 20/23 http://www.hudl.com/ (HTTP 200)
[info] [thenOpen] THENOPEN #9
[info] [phantom] Step 20/23: done in 29233ms.
PASS 200 for http://www.hudl.com/
[info] [phantom] Step 22/23 http://www.hudl.com/ (HTTP 200)
[info] [thenOpen] THENOPEN #11
[info] [phantom] Step 22/23: done in 30776ms.
[info] [phantom] Step 23/23 http://www.hudl.com/ (HTTP 200)
[info] [phantom] Step 23/23: done in 30784ms.
[info] [phantom] waitFor() finished in 20ms.
[info] [phantom] Step 24/24 http://www.hudl.com/ (HTTP 200)
[info] [waitFor] WAITFOR #1
[info] [waitFor] WAITFOR #7
[info] [waitFor] WAITFOR #13
[info] [phantom] Step 24/24: done in 30818ms.
[info] [phantom] Step 25/26 http://www.hudl.com/ (HTTP 200)
[info] [phantom] Step 25/26: done in 30823ms.
[info] [phantom] waitFor() finished in 20ms.
[info] [phantom] Step 26/27 http://www.hudl.com/ (HTTP 200)
[info] [waitFor] WAITFOR #2
[info] [waitFor] WAITFOR #4
[info] [waitFor] WAITFOR #6
[info] [phantom] Step 26/27: done in 30857ms.
[info] [phantom] Step 27/29 http://www.hudl.com/ (HTTP 200)
[info] [phantom] Step 27/29: done in 30863ms.
[info] [phantom] waitFor() finished in 20ms.
[info] [phantom] Step 28/30 http://www.hudl.com/ (HTTP 200)
[info] [waitFor] WAITFOR #3
[info] [phantom] Step 28/30: done in 30896ms.
[info] [phantom] Step 29/30 http://www.hudl.com/ (HTTP 200)
[info] [phantom] Step 29/30: done in 30904ms.
[info] [phantom] waitFor() finished in 20ms.
[info] [phantom] Step 30/31 http://www.hudl.com/ (HTTP 200)
[info] [waitFor] WAITFOR #5
[info] [phantom] Step 30/31: done in 30935ms.
[info] [phantom] Step 31/31 http://www.hudl.com/ (HTTP 200)
[info] [phantom] Step 31/31: done in 30944ms.
[info] [phantom] waitFor() finished in 20ms.
[info] [phantom] Step 32/32 http://www.hudl.com/ (HTTP 200)
[info] [waitFor] WAITFOR #8
[info] [waitFor] WAITFOR #10
[info] [waitFor] WAITFOR #12
[info] [phantom] Step 32/32: done in 30978ms.
[info] [phantom] Step 33/34 http://www.hudl.com/ (HTTP 200)
[info] [phantom] Step 33/34: done in 30984ms.
[info] [phantom] waitFor() finished in 20ms.
[info] [phantom] Step 34/35 http://www.hudl.com/ (HTTP 200)
[info] [waitFor] WAITFOR #9
[info] [phantom] Step 34/35: done in 31016ms.
[info] [phantom] Step 35/35 http://www.hudl.com/ (HTTP 200)
[info] [phantom] Step 35/35: done in 31024ms.
[info] [phantom] waitFor() finished in 20ms.
[info] [phantom] Step 36/36 http://www.hudl.com/ (HTTP 200)
[info] [waitFor] WAITFOR #11
[info] [phantom] Step 36/36: done in 31055ms.
[info] [phantom] Done 36 steps in 31061ms
PASS 8 tests executed in 29.599s, 8 passed, 0 failed.
@vumaasha
Copy link

makes me wonder if i should use casperjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment