Last updated by marcpalmer
4 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.| Task | Grails Functional Testing | Webtest |
|---|---|---|
| Turn off JavaScript | javaScriptEnabled = false | option( name:'JavaScriptEnabled', value:'false') |
| Turn off auto-redirect | redirectEnabled = false | option( name:'RedirectEnabled', value:'false') |
| GET a page | get('someurlhere') | invoke( url:'someurlhere') |
| POST post params to a URL | post('someurlhere') { x = y } | invoke( url:'someurlhere', method:'POST', content: 'x=y.encodeAsURL()' ) |
| POST data to a URL | post('someurlhere') { body { "<root><value>1</value></root>" } } | invoke( url:'someurlhere', method:'POST', content: "<root><value>1</value></root>" ) |
| Check response code | assertStatus 302 | ? Don't know |
| Check redirect Url | assertRedirectUrlContains 'thetarget' | ? Don't know |
| Check response contains some content, ignoring case and whitespace | assertContentContains "something" | ? Don't know |
| Check response contains some content exactly | assertContentContainsStrict "something" | verifyText(text:'something') |
| Select a form | form('form1') { … } | selectForm(name:'form1') |
| Set textarea/input field value by id | field1 = 'Rock!' | setInputField(htmlId:'field1', value:'Rock!') |
| Set textarea/input field value by name | field1 = 'Rock!' | setInputField(name:'field1', value:'Rock!') |
| Select a checkbox by id | checkbox1 = true | setCheckbox(htmlId:'checkbox1', checked:'true') |
| Select a checkbox by name | checkbox1 = true | setCheckbox(name:'checkbox1', checked:'true') |
| Select a radiobutton (within a group) by id | radio1 = 'value1' | ? Don't know - does setRadiobutton check the one with correct value? |
| Select a radiobutton (within a group) by name | radio1 = 'value1' | ? Don't know - does setRadiobutton check the one with correct value? |
| Click a submit button by id | buttonNameOrId.click() -or- click "buttonNameOrId" | clickButton(htmlId:'buttonId') |
| Click a submit button by name | buttonNameOrId.click() -or- click "buttonNameOrId" | clickButton(name:'buttonId') |
| Click a submit button by value | buttonValue.click() -or- click "buttonValue" | ? Don't know |
| Follow a previously asserted redirect | followRedirect() | ? Don't know |