Forum Discussion
nmrao
12 years agoChampion Level 3
Hi,
Here is the groovy code which extracts the AccountID.
Note that, i had to modify the url as the snippet you mentioned is malformed url and created a map manually to test for the intended value (you may remove map as you dont need it)
Output:
Location from headers is http://example.com/account-api/rest/12345AB
Account ID 12345AB
Now, how it needs to be used is upto you few suggestions though:
1. You may add it as script assertion in your response
2. Additionally you can add a line of code into the above script to set the Project/TestSuite/TestCase level property to the ACCOUNTID, for eg: project.setProperty('ACCOUNTID',accountID). Then access the value in any step, depends on where you set the property like ${#Project#ACCOUNTID}/${#TestSuite#ACCOUNTID}/${#TestCase#ACCOUNTID}.
Is this what you are looking for?
Regards,
Rao.
Here is the groovy code which extracts the AccountID.
Note that, i had to modify the url as the snippet you mentioned is malformed url and created a map manually to test for the intended value (you may remove map as you dont need it)
def header = ['HTTP/1.1 201 Created':'',
'Server': 'Apache-Coyote/1.1',
'Location': 'http://example.com/account-api/rest/12345AB',
'Content-Type': 'application/xml',
'Content-Length': '0',
'Date': 'Thu, 23 May 2013 14:59:42 GMT',
'Connection': 'close']
def location = header['Location']
System.out.println('Location from headers is '+location)
def pathStrings = location.toURL().path.split('/')
def accountID = pathStrings[pathStrings.length - 1]
System.out.println('Account ID '+accountID)
Output:
Location from headers is http://example.com/account-api/rest/12345AB
Account ID 12345AB
Now, how it needs to be used is upto you few suggestions though:
1. You may add it as script assertion in your response
2. Additionally you can add a line of code into the above script to set the Project/TestSuite/TestCase level property to the ACCOUNTID, for eg: project.setProperty('ACCOUNTID',accountID). Then access the value in any step, depends on where you set the property like ${#Project#ACCOUNTID}/${#TestSuite#ACCOUNTID}/${#TestCase#ACCOUNTID}.
Is this what you are looking for?
Regards,
Rao.
Related Content
Recent Discussions
- 11 days ago