What kind of authentication?
For Basic authentication have a look at:
HTTP Basic Authentication credentials passed in URL and encryption
so you could just add that to your base url.
If you have to go through the login process, you can use the setupSpec() and setup methods. The former gets executed before anything else happens, the latter before each individual test method.
You can use the @Stepwise notation to stop cookies from being deleted between test methods.
If you have different geb classes and want all of them to be prepended with your setup or setupSpec method, use the extends notation:
class BaseClass extends GebSpec {
def setupSpec() {
<loginProcess>
}
}
@Stepwise
class ASpec extends BaseClass {
testMethod() { }
}
@Stepwise
class BSpec extends BaseClass {
testMethod() { }
}
note that this will execute the login process one extra time because it happens in the BaseClass as well.
I got around this with an
if (this.getClass().getPackage().getName() != "gebMethods")
block but I guess there might be a more elegant solution.