Once in a while, we might want to add an additional library into an existing page with Geb.
The easy way to do so is to add a helper method called injectLibrary as follows:
def injectLibrary( library ){
js.exec("document.body.appendChild(document.createElement('script')).src='$library'");
}
Then, whenever you want to add a new library, simply call
injectLibrary( 'http://sinonjs.org/releases/sinon-1.4.2.js' )
This would add the javascript library you have specified in your link into your page.
There are a few scenarios where I have found this to be useful:
Pingback: Injecting javascript | Jlaura