Last active
December 10, 2015 02:09
-
-
Save brianmhunt/4365815 to your computer and use it in GitHub Desktop.
A CasperJS wrapper for remote jQuery calls (untested)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class jQueryCasperWrapper | |
constructor: (@selector) -> | |
wrappedMethods = ['data', 'visible'] # ... plus all the other jQuery functions being wrapped | |
_.each(wrappedMethods, (method) => # lodash/underscore foreach -- just from my own preferences | |
wrapper = (args...) => @RemotejQuery(method, args) | |
@[method] = wrapper | |
) | |
RemotejQuery: (methodName, args) -> | |
remote_fn = (_selector, _methodName, _args) -> | |
jobj = jQuery(_selector) | |
return jobj[_methodName].apply(jobj, _args) | |
casper.evaluate(remote_fn, | |
_selector: @selector | |
_methodName: methodName | |
_args: args | |
) | |
jQueryInCasper = (selector) -> | |
return new jQueryCasperWrapper(selector) | |
casper.$ = jQueryInCasper | |
# now we can do casper.$("hello").data() or casper.$("#header").text() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment