I'm writing Spock + Geb based tests for web site testing. Web site is used to create offers and later various actions can be performed on them (confirm, reject, withdraw). I already created working scenario for creating an offer. But now when I came to the point that I need to implement scenarios for various combinations of actions I would like to be able to reuse "create offer" in these other scenarios. Unfortunately I'm not able to find any example or to think good way how to do it. Could someone give me any ideas about that?
By the way I need to perform actions in predefined sequence so I'm using Stepwise annotation on my specifications.
Single Page Actions:
It's hard to say without seeing examples of your code, but one way of doing this is to define the methods for your actions (confirm, reject, withdraw) as simple methods in your Page class:
Then in your Specification class you can do
This works because Geb uses Groovy's method missing stuff to find the name of the method on the current page called "confirm ()", and will execute that code.
Multiple Page Actions:
If the actions are complicated and involve navigating to several pages, it is best to create an abstract base class for your tests which need to perform the actions:
Then the extending classes: