URL Verification

Hello Everyone,

I have a question around URL verification in Katalon. I am not able to verify how to verify if the URL on which user is landing doesn’t contain some of the the strings that I will mention in my test case. There are many solutions available but not able to figure this out. I just started in Automation and learning new stuff daily.

For e.g I want to verify a url that it should not contain any " - " in it. How to verify this. I tried this statement

WebUI.verifyNotMatch(‘https://www.thisismy-url.com/’, ‘-’, true)

but it gave me error

verifyNotMatch(‘https://www.thisismy-url.com/’, ‘-’, true) FAILED.

Reason:

com.kms.katalon.core.exception.StepFailedException: Unable to verify not match between actual text ‘https://www.thisismy-url.com/’’ and expected text ‘-’ using regular expression (Root cause: java.util.regex.PatternSyntaxException: Dangling meta character ‘*’ near index 0

-

^)

No need to use the WebUI API here, just use plain old java/groovy:

String url = "https://www.thisismy-url.com/";
assert !url.contains("-");
2 Likes

Thanks Buddy, Giving it a try.

@Brandon_Hein This worked well too.

Thanks for helping me out today. Keep up the good work.

Now I will update my existing test cases with the enhancements needed.

No problem :grin:

Just to add an explanation here: WebUI.verifyNotMatch() won’t check for non-existence of the " - ", it will compare both of the strings and should return true if they are not equal.
The third parameter (“true” in this case) says that the string in question is regex.

1 Like

@Mate_Mrse Thanks for explaining the function here. I would suggest to Katalon to make the description plain and easy on the keyword help pages.

@Brandon_Hein @Mate_Mrse One more question. Is there a way that I can verify if the URL has any character in capital or in small case ?

char[] urlChars = url.toCharArray()
for(char ch in urlChars) {
	if(Character.isUpperCase(ch)) {
		println "URL contains uppercase letter : " + ch	
	}
}

Use the same approach for lower case letters.

Thanks @Marek_Melocik

Is there a way that we can use an assert statement or verify statement.

I want test case to fail if there are uppercase letters. The team is not checking logs if the test case has passed.

1 Like

Of course, just put failure statement into the condition.

char[] urlChars = url.toCharArray()
for(char ch in urlChars) {
	if(Character.isUpperCase(ch)) {
		KeywordUtil.markFailed("The URL contains uppercase letter.")	
	}
}
2 Likes

@Marek_Melocik Thanks buddy, this solution worked too. You guys are really helpful.