set or change boolean values in script

goofy78270goofy78270 Posts: 28

I have the following scripts that simply flips the value of a boolean, but when I try to set the value to a testsuite variable, I get a compile error as a string cannot be set to a boolean although the variable is defined as a boolean.

Any help on my mistake(s) or work arounds would be greatly appreciated.


Variable definition at test suite level:

script to change variable:

import com.parasoft.api.*
import java.lang.*
public void flipBoolean(Object input, ExtensionToolContext context) {
//Capture setting of Boolean field
def initBoolean = context.getValue("Generated Data Source", "db_Orig_Boolean").toBoolean()
//Application.showMessage("Boolean is initially set to: " + initBoolean)
//Flip Boolean value
def newBoolean = !initBoolean
//Application.showMessage("Updated Boolean is set to: " + newBoolean)
context.setValue("ts_flipBoolean", newBoolean)
}

Error Message from compiler:
Error Message:
Error during script execution. View Details for more information.

Additional Details:
No signature of method: webtool.scripting.MethodToolContext.setValue() is applicable for argument
types: (java.lang.String, java.lang.Boolean) values: [ts_flipBoolean, true]
Possible solutions: setValue(java.lang.String, java.lang.String), getValue(java.lang.String),
getValue(java.lang.String, java.lang.String), getValue(java.lang.String, java.lang.String),
getValue(java.lang.String, java.lang.String, boolean), getValues(java.lang.String,
java.lang.String)

Comments

  • jakubiakjakubiak Posts: 525 admin

    The setValue() method takes a String for the 2nd parameter, not a boolean. So you need to convert the boolean value to a String before calling setValue().

Sign In or Register to comment.