cancel
Showing results for 
Search instead for 
Did you mean: 

extracting a string starting from a known value

SOLVED
Occasional Contributor

extracting a string starting from a known value

i have a string like below in my response.

 

https://metalTin.abcd.com/dbname/dbname_WebUI/views/home/knownpage.aspx?uniquecode=coNews&area=home&view=coNews

 

 

I have already setup property transfer and am capturing the value in a variable.

def urlFromResponse = context.expand( '${#TestSuite#url_link}')

 

How do I extract the substring (everything after abcd.com)

"/dbname/dbname_WebUI/views/home/knownpage.aspx?uniquecode=coNews&area=home&view=coNews"

 

 

Please note the value "https://metalTin.abcd.com" is always changing.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Valued Contributor

Re: extracting a string starting from a known value

The URI class (https://docs.oracle.com/javase/7/docs/api/java/net/URI.html) can also be a more Java API centric option:

 

def uri =  new URI('https://metalTin.abcd.com/dbname/dbname_WebUI/views/home/knownpage.aspx?uniquecode=coNews&area=home&view=coNews')
log.info uri.path
log.info uri.query
log.info uri.path+"?"+uri.query

Logs:

Tue Nov 22 10:16:16 GMT 2016:INFO:/dbname/dbname_WebUI/views/home/knownpage.aspx
Tue Nov 22 10:16:16 GMT 2016:INFO:uniquecode=coNews&area=home&view=coNews
Tue Nov 22 10:16:16 GMT 2016:INFO:/dbname/dbname_WebUI/views/home/knownpage.aspx?uniquecode=coNews&area=home&view=coNews
Author of SoapUI Cookbook
2 REPLIES 2
Super Contributor

Re: extracting a string starting from a known value

I'm assuming that your string is always a URL, if so the following should work:

 

def urlFromResponse = context.expand( '${#TestSuite#url_link}')
def thirdSlashIndex = urlFromResponse.indexOf('/', 9)
def partialString = urlFromResponse.substring(thirdSlashIndex)

 

The indexOf looks for the first occurance a slash, from character 9 of your string, i.e. after the "https://".

Valued Contributor

Re: extracting a string starting from a known value

The URI class (https://docs.oracle.com/javase/7/docs/api/java/net/URI.html) can also be a more Java API centric option:

 

def uri =  new URI('https://metalTin.abcd.com/dbname/dbname_WebUI/views/home/knownpage.aspx?uniquecode=coNews&area=home&view=coNews')
log.info uri.path
log.info uri.query
log.info uri.path+"?"+uri.query

Logs:

Tue Nov 22 10:16:16 GMT 2016:INFO:/dbname/dbname_WebUI/views/home/knownpage.aspx
Tue Nov 22 10:16:16 GMT 2016:INFO:uniquecode=coNews&area=home&view=coNews
Tue Nov 22 10:16:16 GMT 2016:INFO:/dbname/dbname_WebUI/views/home/knownpage.aspx?uniquecode=coNews&area=home&view=coNews
Author of SoapUI Cookbook