Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

set or change boolean values in script

goofy78270
goofy78270 Posts: 133

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

  • jakubiak
    jakubiak Posts: 795 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().

  • goofy78270
    goofy78270 Posts: 133

    Sorry for just getting back to this, but I did change the value to a string and it worked as expected. However, I am curious as to the purpose of this. If a user can define variable at a test suite or script level as something other than a string, why should they be forced to cast/convert to and from their designated classification just to set the value. Appears to be a possible bug; at a minimum, extra work on the users side that should not be needed.