source: branches/features/purchaseOrders/test/functional/gnumims/functional/pages/GrailsPage.groovy @ 952

Last change on this file since 952 was 952, checked in by gav, 13 years ago

Functional tests, refactor login/logout.

File size: 1.6 KB
Line 
1package gnumims.functional.pages
2
3import geb.Page
4
5/**
6 * http://ldaley.com/post/1013531080/painless-page-identification-with-geb-grails
7 */
8abstract class GrailsPage extends Page {
9
10    // To be overridden by subclasses
11    static controller = null
12    static action = null
13    static url = "$controller/$action"
14
15    static at = {
16        // delegate here is the original page _instance_ (i.e. the subclass)
17
18        def expectedPageControllerName = delegate.class.controller
19        if (expectedPageControllerName == null) {
20            throw new IllegalStateException("${delegate.class} forgot to declare which controller it belongs to")
21        }
22
23        def expectedPageActionName = delegate.class.action
24        if (expectedPageActionName == null) {
25            throw new IllegalStateException("${delegate.class} forgot to declare which action it is")
26        }
27
28        def actualPageControllerName = controllerName
29        def actualPageActionName = actionName
30
31        assert actualPageControllerName == expectedPageControllerName
32        assert actualPageActionName == expectedPageActionName
33
34        true // at checkers must return true
35    }
36
37    static content = {
38        pageId { $("meta", name: "pageId").@content }
39        controllerName { pageId.split('\\.')[0] }
40        actionName { pageId.split('\\.')[1] }
41        logoutButton(to:LogoutPage, required: false) { $("a[class=logoutButton]") }
42        message { $("div.body div.message").text() }
43    }
44
45    def verifyLoggedIn() {
46        assert logoutButton
47        return true
48
49    }
50
51    def verifyLoggedOut() {
52        assert !logoutButton
53        return true
54
55    }
56
57}
58
Note: See TracBrowser for help on using the repository browser.