Last updated by marcpalmer 5 years ago

The Difference between Webtest and Grails Functional Testing DSLs

This is a quick summary to show the difference in spirit between the two functional testing plugins. Both of these plugins are really just DSL and reporting wrappers around HtmlUnit. The secret's in the sauce put on top!

The primary difference is that the Webtest DSL wraps an XML grammar, which by its nature is less "Groovy". There are many things that Webtest offers currently that G-func cannot do. But some of these are not necessarily desirable, and others that are will come in future.

If anybody can help me fill in the "? Don't know" sections for webtest that would be much appreciated.

TaskGrails Functional TestingWebtest
Turn off JavaScriptjavaScriptEnabled = falseoption( name:'JavaScriptEnabled', value:'false')
Turn off auto-redirectredirectEnabled = falseoption( name:'RedirectEnabled', value:'false')
GET a pageget('someurlhere')invoke( url:'someurlhere')
POST post params to a URLpost('someurlhere') { x = y }invoke( url:'someurlhere', method:'POST', content: 'x=y.encodeAsURL()' )
POST data to a URLpost('someurlhere') { body { "<root><value>1</value></root>" } }invoke( url:'someurlhere', method:'POST', content: "<root><value>1</value></root>" )
Check response codeassertStatus 302? Don't know
Check redirect UrlassertRedirectUrlContains 'thetarget'? Don't know
Check response contains some content, ignoring case and whitespaceassertContentContains "something"? Don't know
Check response contains some content exactlyassertContentContainsStrict "something"verifyText(text:'something')
Select a formform('form1') { … }selectForm(name:'form1')
Set textarea/input field value by idfield1 = 'Rock!'setInputField(htmlId:'field1', value:'Rock!')
Set textarea/input field value by namefield1 = 'Rock!'setInputField(name:'field1', value:'Rock!')
Select a checkbox by idcheckbox1 = truesetCheckbox(htmlId:'checkbox1', checked:'true')
Select a checkbox by namecheckbox1 = truesetCheckbox(name:'checkbox1', checked:'true')
Select a radiobutton (within a group) by idradio1 = 'value1'? Don't know - does setRadiobutton check the one with correct value?
Select a radiobutton (within a group) by nameradio1 = 'value1'? Don't know - does setRadiobutton check the one with correct value?
Click a submit button by idbuttonNameOrId.click() -or- click "buttonNameOrId"clickButton(htmlId:'buttonId')
Click a submit button by namebuttonNameOrId.click() -or- click "buttonNameOrId"clickButton(name:'buttonId')
Click a submit button by valuebuttonValue.click() -or- click "buttonValue"? Don't know
Follow a previously asserted redirectfollowRedirect()? Don't know