Skip to content

Instantly share code, notes, and snippets.

@antony
Created September 20, 2015 11:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antony/647d5a0cd658bb3bdbde to your computer and use it in GitHub Desktop.
Save antony/647d5a0cd658bb3bdbde to your computer and use it in GitHub Desktop.
Testing asynchronously inserted content (such as modals) with Geb. Thanks to Verity.
// We use 'to:' on the modal trigger to force a refresh of the page cache once the modal has been inserted.
// Angular Bootstrap modals are actually created in the DOM once they are triggered, so our initial page parse doesn't grab them.
// If we don't do this, you will end up with a lot of nulls since Geb 0.11.
class ExamplePage extends Page {
static content = {
modalTrigger(to: ExamplePage) { $('.show-modal') }
modal { $('.my-modal').module(ModalDialogModule) }
}
}
class ModalDialogModule extends Module {
isShown() {
waitFor {
hasClass('inmodal') // without 'to: ' above, this will never be true.
}
return true
}
}
class ModalDialogSpec extends GebSpec {
def 'Test that a modal has some content'() {
given:
to ExamplePage
when:
modalTrigger.click()
then:
modal.shown
// now make assertions
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment