Updating TestSuite Variable using groovy script
I have a testSuite variable named and want to increment and update the testSuite variable using groovy. I could not figure out why it's not updating the testsuite Variable.
Here's my Groovy
import com.parasoft.api.*;
import java.lang.*;
public myTransactionId( context ){
Application.showMessage("here the application " + Application.getContext())
Application.showMessage("myTransactionId " + context.getValue("transactionId")) myObj = context.getValue("transactionId") myValue = Integer.parseInt( myObj ) + 1 Application.showMessage("INcremented value " + myValue.toString()) return context.setValue("transactionId", myValue)
}
Comments
-
I tried running your script from an Extension tool. When run this way, unlike certain other scripted fields, the ScriptingContext object is actually the second argument instead of the first argument. So, in my case, I changed
myTransactionId(context)
tomyTransactionId(input, context)
. Next, the script throws the following Exception:java.lang.NoSuchMethodException: No signature of method: webtool.scripting.MethodToolContext.setValue() is applicable for argument types: (java.lang.String, java.lang.Integer) values: [transactionId, 1]
I fixed that part by changing
context.setValue("transactionId", myValue)
tocontext.setValue("transactionId", myValue.toString())
0 -
I tried that again, from the cosole you would that the transaction is getting incremented but if you looked back at the test Suite variable it's still having the same value. Btw, I am not using the extension tool here. I was adding the script into the element. The increment works but it's not updating the TSV value. Please see attached.
0 -
-
incremented but if you looked back at the test Suite variable it's still having the same value
The value configured in the test suite is the variable's initial value. A copy of the value is stored in memory for use at runtime. If you increment the value in your script then any subsequent tests in that same run will see the updated value until the test run completes. You can prove this to yourself by adding another test that reads the current value of the test suite variable.
Running a tst will never updated any saved configuration or otherwise trigger the tst to re-save itself with different configuration. Things like variables and data bank columns are dynamic, where their values can change during the execution of the tst but those values only exist within the context of that particular execution, not something that's saved or gets updated in the tst file on disk.
1 -
thank you for the explanation. Now, I understood how it suppose to work.
0