We are building a new experience for our SmartBear Community.
This site is now read-only. You can still browse and search as usual. Learn More
This site is now read-only. You can still browse and search as usual. Learn More
Hi, I'm trying to test a test case where I have to pass the last three digits of an order number that I have created from another groovy script.
Below is my original script that creates the order number
int a = 9
nr = "N"
for(i = 0; i < 7; i++)
{
random = new Random()
randomInteger= random.nextInt(a)
nr = nr + randomInteger
}
//return nr
testRunner.testCase.setPropertyValue("OrderNumber",nr)
It creates an order Number for example N0382254.
Now in another script I want get the last three digits of that order number and save it into a property.
How can I call the original script and then get the last 3 digits?
Any help will be highly appreciated. Thanks!
Not sure why are you using like that while it can be done easily by:
Note that if you need to use that extracted value in a request, no addition groovy script is required. Instead use in-line script in the request itself as shown below:
<id>${= def id = testRunner.testCase.getPropertyValue("OrderNumber"); id.substring(5, id.size())}</id>
Use "substring" method to get the required value.
For example:
def s = 'N0382254'
log.info s.substring(5, s.size())
I'm using the below script..
def s = context.expand( '${CreateOrderNumber#result}' )
log.info s.substring(3, s.size());I'm getting the below error
java.lang.StringIndexOutOfBoundsException: String index out of range: -3
error at line: 2
Not sure why are you using like that while it can be done easily by:
Note that if you need to use that extracted value in a request, no addition groovy script is required. Instead use in-line script in the request itself as shown below:
<id>${= def id = testRunner.testCase.getPropertyValue("OrderNumber"); id.substring(5, id.size())}</id>