Created
September 20, 2015 11:10
-
-
Save antony/647d5a0cd658bb3bdbde to your computer and use it in GitHub Desktop.
Testing asynchronously inserted content (such as modals) with Geb. Thanks to Verity.
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
// 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) } | |
} | |
} |
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 ModalDialogModule extends Module { | |
isShown() { | |
waitFor { | |
hasClass('inmodal') // without 'to: ' above, this will never be true. | |
} | |
return true | |
} | |
} |
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 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