-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGrailsPage.groovy
42 lines (31 loc) · 1.26 KB
/
GrailsPage.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package pages
import geb.Page
/**
* @see http://ldaley.com/post/1013531080/painless-page-identification-with-geb-grails
*/
abstract class GrailsPage extends Page {
// To be overridden by subclasses
static controller = null
static action = null
static at = {
// delegate here is the original page _instance_ (i.e. the subclass)
def expectedPageControllerName = delegate.class.controller
if (expectedPageControllerName == null) {
throw new IllegalStateException("${delegate.class} forgot to declare which controller it belongs to")
}
def expectedPageActionName = delegate.class.action
if (expectedPageActionName == null) {
throw new IllegalStateException("${delegate.class} forgot to declare which action it is")
}
def actualPageControllerName = controllerName
def actualPageActionName = actionName
assert actualPageControllerName == expectedPageControllerName
assert actualPageActionName == expectedPageActionName
true // at checkers must return true
}
static content = {
pageId { $("meta", name: "pageId").@content }
controllerName { pageId.split('\\.')[0] }
actionName { pageId.split('\\.')[1] }
}
}