Incremented test variable

asinghasingh Posts: 11

I have a test variable which stores value from Text data Bank , how can I use the incremented value of variable in my test case.

Tagged:

Comments

  • jakubiakjakubiak Posts: 306 ✭✭✭

    You should be able to write a simple script that increments the value. Can you provide more details about where the variable is being used: what kind of test it is, where in the UI you are inputting the variable? This will help guide any suggestions about where to put the script.

  • asinghasingh Posts: 11

    I am trying with script

    import com.parasoft.api.*;
    
    def incrementSerialId(ScriptingContext scriptContext) {
    iSerial=scriptContext.getValue("iSerial").toInteger()+1;
    scriptContext.setValue("iSerial",iSerial.toString());
    
    //return iSerial;
    }
    

    however it is giving me below error

    Error during script execution. View Details for more information.

        No signature of method: Script596.incrementSerialId() is applicable for argument types:
         (webtool.packet.ScriptingFriendlyTextUsable) values: [3633
        ]
        Possible solutions: incrementSerialId(com.parasoft.api.ScriptingContext)
    

  • jakubiakjakubiak Posts: 306 ✭✭✭

    In your example I am assuming that "iSerial" is the name of the data source column that you defined within the Text Data Bank. If so, you cannot write back into that data bank column with a script. Instead, you should define a variable within the test suite, and then set the incremented value into the variable instead of trying to update the data bank value. Also, you are having problems since the signature of your method needs to contain two input parameters if you want to get the ScriptingContext - you can see what signature to use by clicking the "Expected number of arguments" link at the bottom of the Extension Tool editor. The code would look like this:

    import com.parasoft.api.*;
    
    def incrementSerialId(Object input, ScriptingContext scriptContext) {
        // iSerial is the name of the column name as defined in the Text Data Bank
        iSerial=scriptContext.getValue("Generated Data Source", "iSerial").toInteger()+1;
        // myVar is the name of a variable defined in the Variable section of the Test Suite
        scriptContext.setValue("myVar",iSerial.toString());
    }
    
Sign In or Register to comment.