0

I was trying to run a GEB test using Gradle; It works fine if I run everything from a method but fails if I use a helper function:

Scenario 1 that works:

def "Select ORG Unit and save the invoice and Delete it"() {            
    when: "We click arrivals drop-down link"
        waitFor { inprogtoArrivals.isDisplayed() }

    then: "Click on the Arrivals Tab"
        waitFor { $('#arrivalsTab').find("a").click() }

        Browser.drive {
                go driver.currentUrl
            }
        waitFor { createInvoice.click() }
}

Scenario 2 that doesn't work:

def uploadInvoice() {

    when: "We click arrivals drop-down link"
        waitFor { inprogtoArrivals.isDisplayed() }

    then: "Click on the Arrivals Tab"
        waitFor { $('#arrivalsTab').find("a").click() }
}

def "Select ORG Unit and save the invoice and Delete it"() {            
    when:           
        uploadInvoice()
        Browser.drive {
                go driver.currentUrl
            }
    then:
        waitFor { createInvoice.click() }
}

Here, it can't handle uploadInvoice() and fails. Can anyone please help me to solve this issue?

tim_yates
  • 167,322
  • 27
  • 342
  • 338
Sharif Mamun
  • 3,508
  • 5
  • 32
  • 51
  • 1
    Why are you using `Browser.drive {}` blocks inside of your specs? Using plain `go driver.currentUrl` should work without any need to wrap it in any `drive {}` blocks. – erdi Jun 13 '14 at 22:17
  • If something fails for you it's usually good to include the stacktrace - that way it is way easier to help out. – erdi Jun 13 '14 at 22:22
  • 1
    thanks for the tips in your first comment. I was totally unaware of that! – Sharif Mamun Jun 13 '14 at 22:33

1 Answers1

0

You cannot use when: and then: blocks inside of a helper methods because these blocks are what Spock uses to differentiate between feature (test) methods and regular methods. The fact that you used these blocks means that uploadInvoice() is a test.

Sharif Mamun
  • 3,508
  • 5
  • 32
  • 51
erdi
  • 6,944
  • 18
  • 28
  • I don't know whether there is a rule that I can not use when: and then: inside a helper function but I have used at least 50 helper functions with when: and then:; and they worked fine for me! – Sharif Mamun Jun 13 '14 at 22:32