Monday 19 May 2008

Dont trip on webtests due to this

A small gotcha when using Webtests which has caught a couple of pairs out is when your webtest is failing, citing a 404 as the cause whilst when you view the target URL using a browser it renders fine.

To flush this out, we enabled the following in our webtest (see storeResponseCode)

void webtest(String name, Closure yield) {
ant.testSpec(name: name) {
config(configMap) {
option(name: "ThrowExceptionOnFailingStatusCode", value: false)
}
steps {
yield.delegate = ant
yield()
}
}

}


then added

webtest("MyTest: some test"){
invoke(url:'/urlThatWorks')
storeResponseCode(property:"status")
verifyProperty(name:"status", text:"200")
.... [rest of test]
}


Our test passed with 200 status code, thus revealing the clue... our advert IFRAME within the page was 404'ing and the actual cause of our webtest failure.

No comments: