I have a responsive site and would like to separate out the concerns of whether parts of my page template are collapsed from the main content per-page:
trait DesktopPage {
static content = {
header { $('nav', id:'nav-container') }
}
}
trait MobilePage {
// other stuff
}
trait HomePage {
static url = ''
static at = { title == 'My Site' }
}
class DesktopHomePage extends Page implements DesktopPage, HomePage {}
However, the Geb runtime does not appear to collect the static
description blocks off of the traits, instead acting as if they weren't present.
Is it possible to compose concerns like this implicitly using traits with Geb? If not, is there a syntax that will let me pull in the information from implemented traits? HomePage.at
doesn't resolve.
If you have look at the documentation on traits and static fields you will notice that it explicitly mentions that mixing in a trait that declares a static field doesn't add the field to the class. Geb was created way before traits were added to Groovy thus using them to compose page was definitely not taken into account when designing the API.
If the url and at checker are the same for both pages and only the content differs between mobile and desktop version why don't you simply use inheritance?
class HomePage {
static url = ''
static at = { title == 'My Site' }
}
class DesktopHomePage extends HomePage {
static content = {...}
}
class MobileHomePage extends HomePage {
static content = {...}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With