Search code examples
urlkatalon-studiokatalon

How can I save part of URL using Katalon?


I would like to save part of the URL and I don't really know how to do it. I would like to save the part of the URL in a variable.

Anyone has an idea how to do it?


Solution

  • First, to get the current url, use

    current_url = WebUI.getUrl()
    

    Then you will need to use some kind of string manipulations to get the part that you need.

    Katalon uses Groovy language, so you can read about the string methods here.

    For example, if current_url='https://www.tutorialspoint.com/groovy/groovy_strings.htm' you wish to get only the part of the url after the last / try something like this:

    split_url = current_url.split('/')
    partial_url = split_url[split_url.size()-1]
    println partial_url
    

    The result of the above is "groovy_strings.htm".