Get the url and paste into new .txt file

Hello!

I am automating tests cases for a commerce web, so after I place an order I get a confirmation page where the orderID is stored in the website’s URL.

I would like to get that url, extract the order number (by extracting the order number from the URL string) and create + paste into a .txt file in a local directory.

What I’ve done so far is the following

url= WebUI.getUrl()
String url
url.substring(a,b)

I’m new to the Katalon world and coding so I’d appreciate any tips/best practices.

Thanks!

The concern I see is the position (and length) of the orderId within the URL. Will the position (and length) always be the same? If it will be, then substring may work. If it will not be, then I might look into the split method instead.

"assume the orderid is in the 6th position"
orderId = url.split('\')[5]

Here are a couple of ideas to assist you:

Hi,

The position is variable. I also want to write into a .txt and deposit it into a folder as part of the test results, could you help me with that?

Also, does the split function takes the rest of the url from the 6th position? Let’s say

https://new.loan.com/loan?loanId=9307/orderconfirmation
I just want to extract “9307”

Do two splits:

  1. Split on “loadId=” and take the remainder.
  2. Split on “/” and take the zeroth member.

For writing a string to a file, maybe this will help: