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.

Groovy REST Request - Scripted Input

Gambit
Gambit Posts: 28

When creating a REST request, I have three options for the data I send 1) Fixed, 2) Parameterized, and 3) Script

I am attempting to use the script option to create a groovy script that will generate a random number each time I run a test. This is the script I have so far and I'm seeing the error "Argument count should be 0 or 1 instead of 2". Can someone help?

import com.parasoft.api.*
import java.util.*
import org.apache.commons.lang.RandomStringUtils

def setup(input, context){
Random random = new Random()
x = UUID.randomUUID().toString()
return x
}

Comments

  • jakubiak
    jakubiak Posts: 813 admin

    In the dialog that pops up there is a link that says "Expected number of arguments: 0 or 1". When you click the link, you get a message that tells you that the script expects 0 or 1 arguments, and if you do include the 1 argument that it is of type ScriptingContext. So in your case you need to modify your script and simply remove the "input" parameter. You also can optionally remove the "context" parameter as well since your script doesn't use it.

  • Gambit
    Gambit Posts: 28

    That was the problem! I was going in circles trying to figure out why this exact script works outside of this particular menu, but not embedded.