2

I have a Page class and having some method which extract the Web page. Now I want to call these method into the Where block of Spock to pass as data provider. But when I call the method then it throws an error as it did not find it. But the same is accessible from out of Where block. Why is it so?

Example

def "Validate all article has its id"(){
    when:"I am at Overview page"
    at OverviewPage

    then:"I should the article id of all article"
    getAllCountOf(articleInfo).size() ==  actualCount

    where:
    articleInfo                          |actualCount
    TopArticleListInfo.ARTICLE_THUMBNAIL |filter.getCount()

}

In the above code 'filter.getCount()' can not be accessed from Where block, But the same method is accessible in when or then block.

i want to understand the logic behind the scene It looks like , Where block is not able to find this method statically, need to create an object to call this.

When I tried the solution provided by erdi, But that also not solving the issue

when:"I am at Overview page"
    at OverviewPage
    then:"I should the article id of all article"
    getAllCountOf(articleInfo).size() ==  page."$actualCount"

    where:
    articleInfo                          |actualCount
    TopArticleListInfo.ARTICLE_THUMBNAIL |'getRowCount().size()'

Here getRowCount().size() substitute in "$actualCount". But still it throwing the error

Error Message

getAllCountOf(articleInfo).size() == page."$actualCount" | | | | | | | 10 | groovy.lang.MissingPropertyException: Unable to resolve getRowCount().size() as content for inca.sundashboard.pageobject.OverviewPage, or as a property on its Navigator context. Is getRowCount().size() a class you forgot to import? |

  • Possible duplicate of [Using Spock Data Tables to Test Geb Page Objects](https://stackoverflow.com/questions/46960922/using-spock-data-tables-to-test-geb-page-objects) – Leonard Brünings Nov 17 '17 at 19:46
  • See my response to the question Leonard mentioned for explanation: https://stackoverflow.com/a/46971915/1856764 – erdi Nov 18 '17 at 20:39
  • I tried the solution provided by you , But it did not resolve the issue i am facing. when:"I am at Overview page" at OverviewPage then:"I should the article id of all article" getAllCountOf(articleInfo).size() == page."$actualCount" where: articleInfo |actualCount TopArticleListInfo.ARTICLE_THUMBNAIL |'getRowCount().size()' . this piece of code does not work. – Perwez Alam Nov 20 '17 at 06:51

1 Answers1

2

I'm using Dynamic Method Names in my tests, here is a small example:

def "Validate all article has its id"(){
    when: "I am at Overview page"
    at OverviewPage

    then: "I should the article id of all article"
    getAllCountOf(articleInfo).size() ==  "$actualCountMethod"().getCount()

    where:
    articleInfo                          | actualCountMethod
    TopArticleListInfo.ARTICLE_THUMBNAIL | filter

}

Royg
  • 1,665
  • 1
  • 13
  • 20
  • 1
    This really worked out. This is what i was looking for to pass the dynamic method from data table. Thank you so much @Royg for your help. – Perwez Alam Nov 20 '17 at 07:03