最近在用Spock做自動化測試,其中遇到一些錯誤,把這些錯誤記錄下來供參考。
錯誤現象:
groovy.lang.MissingPropertyException: Unable to resolve addSchoolButton as content for page.ClassListPage, or as a property on its Navigator context. Is addSchoolButton a class you forgot to import?
at geb.content.PageContentSupport.propertyMissing(PageContentSupport.groovy:45)
at geb.Page.propertyMissing(Page.groovy:99)
at geb.Browser.propertyMissing(Browser.groovy:213)
at geb.spock.GebSpec.propertyMissing(GebSpec.groovy:60)
問題原因:因爲groovy並不會對不存的變量進行檢查,像這類錯誤一般是寫錯了單詞,並不在相關的類中存在, 本例addSchoolButton並不在ClassListPage