How would I use the control statements in katalon to see if a web page can be accessed or not?
I know I can simply tell it to navigate to a URL but if the navigation is supposed to fail, how do I make the test pass.
I would expect something like: IF WebUI.navigateToUrl (URL) false then test pass? I am a complete programming noob trying to use katalon for web QA work.
WebUI.navigateToUrl(String URL) does not return true/false value. Therefore you have no chance to be informed if the URL is accessible or not = you can not perform IF … THEN … ELSE …
I do not think Katalon Studio’s built-in keywords cover feature of verifying accessibility of a given URL. You would need a Custom Keyword which returns boolean value.
In fact have developed such Custom Keyword for my job. It does not drive a Browser; it makes HTTP GET request and check the response, checks the response to verify if the URL was accessible or not. It required 2 weeks of my programming effort in Groovy. To be honest, it was not very easy.
Do you know anything about the URL you are trying to access?
You could try and verify text on the page to see if it if present, such as success text or the text of an error message.
You could use a verifyElement or verifyTextPresent, perhaps wrapped in a Try/Catch block?
WebUI.openBrowser('https://www.google.co.jp/')
def imgSrc = WebUI.getAttribute(findTestObject('Page_Google/img_hplogo'), 'src')
def result = CustomKeywords.'com.kazurayam.ksbackyard.MyCustomKeywords.verifyUrlAccessibility'(imgSrc)
if (result) {
WebUI.comment(">>> do whatever you want in case <img> is proved accessible")
} else {
WebUI.comment(">>> do whatever you want in case <img> is found inaccessible")
}
WebUI.closeBrowser()