Is there a way to remove a listener?

332 views
Skip to first unread message

imagreenplant

unread,
Apr 8, 2013, 4:10:53 PM4/8/13
to casp...@googlegroups.com
Hello all.

I am making use of the test functionality in casper where one can have many test files, and casperjs will recursively run through the directories and look for the test scripts.  One one of my test scripts, I created a resource requested listener:

casper.on('resource.requested', function(resource) {...

However, I only want those events to be caught inside that one test script.  I don't want that listener for later scripts that are run in the sequence.  How can I remove the listener?

For example:
casperjs test 
test1.js ...
test2.js (has 'resource.requested' listener) ...
test3.js ...

How do I stop test3.js from having its resource.requested events being caught?

Thanks for any and all help.  It is much appreciated.

imagreenplant

unread,
Apr 8, 2013, 5:56:57 PM4/8/13
to casp...@googlegroups.com
I think I figured this out.  I put an empty listener at the end of the script, like so:

this.on('resource.requested', function() {});


However, if anyone has a better way I would love to know.  Thanks all.

Risto Novik

unread,
Apr 11, 2014, 11:39:18 AM4/11/14
to casp...@googlegroups.com
Actually this is good question, what I want to do is that on each test file I would like to get the request information. Currently when I add one request handler to some 'pre-executed' script which captures all requests even if the test has already passed.

Simon Chong

unread,
Jan 26, 2016, 7:58:50 PM1/26/16
to CasperJS
Yes there is.

I wrote some documentation here:


It should get merged back into the CasperJS documentation soon.
Reply all
Reply to author
Forward
0 new messages