Question

I attempted to create a Page that extends another Page and got the following error message when I tried to run my project: groovy.lang.MissingPropertyException: No such property: navLinkPage1 for class: myPage

    import geb.Page

    class HomePage extends myPage {
        static url = "http://www.mywebsite.com"
        static at = { title == "Home"}
    }

    class MyPage extends Page {
        static content = { navLinkPage1 { $("#page1Link") }
    }

Every page is going to have the exact same page header block with the same links and whatnot. So how come I can't just create a page object of that and inherit it in individual pages after? Or did I simply do this incorrectly?

Was it helpful?

Solution

If you could include the block of code that actually uses the navLinkPage1 link, I believe we could track down your exact issue with navLinkPage1, but it sounds like your block of code is going "to MyPage" instead of "to HomePage".

That said, consider the Module Object pattern over the Page Object pattern for complex UIs (disclaimer: I just made that term up). So, instead of making every page inherit from MyPage, creating a (false?) relationship between the Pages, make, say, a "NavigationModule", a la:

class NavigationModule extends Module {
    static content = { 
        homeLink { $("a", title:"Home") }
        contactLink { $("a", title:"Contact Us") }
    }
}

class HomePage extends Page {
    static content = { navBar { module NavigationModule } }
}

and in your test, you'd say:

to HomePage
navBar.contactLink.click()

Personally, I've been treating modules like classes, and pretended their content is private, only giving myself access to operations rather than content. So, only accessing my LoginModule via the logIn(user,pass) method, rather than interacting directly with the username and password members... but... that may not work for you. A nav bar is particularly well suited to direct access. :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top