How does WebUI verify browser status code?

My code is very simple, just like:

WebUI.navigateToUrl(url)
// I want to verify the browser status code in this line.
WebUI.back()

And actually, I’d like to navigate to every link and button on my homepage and make sure each one return status code 200, is there a better way to do this?

I’d tried WebUI.verifyAllLinksOnCurrentPageAccessible(), but it only return passed or failed, and even the result is somewhat inaccuracy.

Hi Wade,

you can get a status code for each page using a Web Service Request. Basically you are getting status codes for each endpoint on a page, not the page itself. Try this code:

import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject

String url = "http://www.google.com"

RequestObject ro = new RequestObject()
ro.setRestRequestMethod("GET")
ro.setRestUrl(url)
ResponseObject resp = WSBuiltInKeywords.sendRequest(ro)
println resp.getStatusCode()

You should get 200 in a Console.

2 Likes

:slight_smile: Got it, thanks!

Using getStatusCode method also helps to get status code then will use assert to perform the validation status code