Question

This is my gebish test and I don't know why it doesn't work.

 def "create 9 more names"(){
       def i = 0
   8.times{

   $("button", value:"newCat").click()

   waitFor { $("input", name:"name") }

   $("input", name:"name") << "gebTest"
   $("input", name:"create").click()

   waitFor { $("h1", text:"Show New Name") }

   $("a", text:"new name").click()

   waitFor {$("h1.title").text() == "Names"}
   expect: at NewNamesPage
       i++
  }

}

This test does work:

 def "create name"() {

   $("button", value:"newCat").click()

   waitFor { $("input", name:"name") }

   $("input", name:"name") << "gebTest"+i
   $("input", name:"create").click()

   waitFor { $("h1", text:"Show New Name") }

   $("a", text:"new name").click()

   waitFor {$("h1.title").text() == "Names"}
   expect: at NewNamesPage

 }

So it seems to not like the spock block:

  8.times {
        //do something 8 times
   }

I have also tries it with a for loop. It doesn't even start the loop.

Any ideas?

Was it helpful?

Solution

This should work for you. Also you don't need to define any variable, n.times should run the block n times. Hope that helps!

def "create 9 more names"(){
   def i = 0
   8.times{

   $("button", value:"newCat").click()

   waitFor { $("input", name:"name") }

   $("input", name:"name") << "gebTest"
   $("input", name:"create").click()

   waitFor { $("h1", text:"Show New Name") }

   $("a", text:"new name").click()

   waitFor {$("h1.title").text() == "Names"}
   expect: at NewNamesPage
    i += 1
  }

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