How to verify navigated URL

I want to verify navigated URL is correct or not. let’s say i’m in “TestSite.com is for sale | Designs.com” . after login i want to verify whether i’m in correct landing page or not by comparing above URL with “TestSite.com is for sale | Designs.com” . Is there any way to do that?

1 Like

Hi @Russ_Thomas… Thanks for replying. I used this one

url = WebUI.getUrl()
print(url)
url1 ='https://www.sample.com/sample/'
if(url==url1){
	println('you are in correct page')

But always test is passed after changing the url1 to wrong one… Why is that?

@rushantha

Your code will print some messages, that’s all it does. Your code will always pass because it has no assertion statement. If you want it to fail in case, you need to write some assertion statements.

The following example uses Groovy’s assert statement. This is the most concise assertion method. The assert statement may let the test case fail and emit message to the Console, but will not show message in the Log Viewer.

assert WebUI.getUrl() == 'https://www.sample.com/sample/'

Or, if you would like to see message in the Kalalon Log Viewer, use WebUI.equal() keyword:

def url = WebUI.getUrl()
WebUI.verifyEqual(url, 'https://www.sample.com/sample/')
2 Likes

@kazurayam Couldn’t that give a false-positive or by throwing that exception, katalon shows failed step?

1 Like

I changed my previous reply.

yeah…it works…Thanks @kazurayam