In my test case I wanted to use a Random number for a particular soap request and use that number in subsequent test steps. I used the following Groovy script within my soap request:
<PersNumber>${=(int)(Math.random()*10000)}</PersNumber>
Then I wanted to use this generated number within a JDBC Step to check whether the customer was correctly inserted within a database. So I used a JDBC step with a persnumber property:
Then the next thing I did was to create a Transfer step to transfer the <PersNumber> content within the request to the persnumber property of the JDBC step.
This did not work because in the end the persnumber property contained:
${=(int)(Math.random()*10000)}
The trick here is to use a test Property for this and to use this property within the soap step and within the JDBC SQL Query.
So first define a property:
Use this property within the soap request:
<PersNumber>${Properties#persnumber}</tns1:PersNumber>
And use the following construction within the SQL Query:
select * from nummers_update where
pers_nummer = ${Properties#persnumber}
Note:
The only disadvantage is that the property is not initialized with a new random value in case you restart the case.
<PersNumber>${=(int)(Math.random()*10000)}</PersNumber>
Then I wanted to use this generated number within a JDBC Step to check whether the customer was correctly inserted within a database. So I used a JDBC step with a persnumber property:
Then the next thing I did was to create a Transfer step to transfer the <PersNumber> content within the request to the persnumber property of the JDBC step.
This did not work because in the end the persnumber property contained:
${=(int)(Math.random()*10000)}
The trick here is to use a test Property for this and to use this property within the soap step and within the JDBC SQL Query.
So first define a property:
Use this property within the soap request:
<PersNumber>${Properties#persnumber}</tns1:PersNumber>
And use the following construction within the SQL Query:
select * from nummers_update where
pers_nummer = ${Properties#persnumber}
Note:
The only disadvantage is that the property is not initialized with a new random value in case you restart the case.
The reason I got the same "random" number of and over again was due to the fact that I multiplied with too many zero's. Use less than <11 and you are safe.
BeantwoordenVerwijderen