Re: Structuring Groovy tests

Murat <murat.knecht-gM/[email protected]>
Newsgroups gmane.comp.web.canoo.webtest
Message-ID <[email protected]>
Hi,

we have groovy webtests, where we structure the code as follows:


def someTest() {
    asUser('Bill', "Make Order, verify and then regret it") {
      makePurchase()
      verifyCart()
    }

   asUserDo('CustomerSupport', "Nullify Bills order") {
     openOrdersOfCustomer('Bill')
     nullifyFirstOrder()
   }

    asUserDo('Bill', "Verifies orders has been nullified.") {
      viewOrders()
      verifyNoOrdersOpen()
    }
}


Via superclass or Mixin, we define something like:

def asUserDo(commonName, title, Closure closure) {
  group(description:title) {
      login_as_user user:commonName
      closure()
      logout()
  }
}

Imho, this helps keep boilerplate code out of the tests, and, using
"group", helps keeps the test reports readable.

Hope this helps, as I myself didn't find much documentation regarding
webtest with groovy. :)

Regards,
Murat






2011/1/20 Markus Strickler <[email protected]>:
>
> Hi-
>
> I've just started using Webtest following a pure groovy approach as
> described here:
> http://mguillem.wordpress.com/2009/04/30/webtest-with-groovy-maven-and-eclipse/
>
> Now I'm wondering what's the best way to structure the tests.
> Many tests will make use of common steps, like logging into the website,
> putting a product into a shopping cart, etc.)
> So what I'm trying to achieve is being able to write tests like this:
>
>        webtest('My Test') {
>
>            addToCart(ean: 12345567)
>
>            login(user: user, password: pasword)
>
>            // some 'regular' webtest calls
>        }
>
> Is anyone using webtest with groovy in a similar fashion? Also does anyone
> have pointers to non trivial examples of groovy webtests?
>
> Thanks for your help,
>
> -markus
> _______________________________________________
> WebTest mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/webtest
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.