Forum Discussion

letstestthisfas's avatar
letstestthisfas
Occasional Contributor
13 years ago

Is there a way to use a variable in soapui

Hi

I am just testing out the soap ui trial version and am looking for a way to use a variable for my REST requests instead of retyping my values for each request. Is there a way to do this?

Apologies if this has been answered before
  • letstestthisfas's avatar
    letstestthisfas
    Occasional Contributor
    Got a little confused by the article

    So, If I want to use variables in the following request, how do i do that? -

    {

    "eventType": "check",
    "emailAddress": "email@emailtesting.com",
    "source": "mobile",
    "customerSegment": "gold",
    "custId": "1111111111"
    }
  • jmistrik's avatar
    jmistrik
    Occasional Contributor
    depends where "do the variables belong" - you choose a scope eg. custId (i believe it is sth like customerID) in TestCase scope, if you need the custId visible in all teststeps

    Lets have the example on TestCase scope - you go to Custom Properties tab in soapui (left bottom corner), create there a property (variable) you need = "custId" with value "1111". Then this variable is accessible in all testSteps:

    {

    "eventType": "check",
    "emailAddress": "email@emailtesting.com",
    "source": "mobile",
    "customerSegment": "gold",
    "custId": "${#TestCase#custId}" [-> will expand to 1111]
    }
  • letstestthisfas's avatar
    letstestthisfas
    Occasional Contributor
    Getting closer here

    I am in the box that says Workspace properties at the bottom left corner, how do I add a new property? I dont see a way to do that. What am i missing?
  • letstestthisfas's avatar
    letstestthisfas
    Occasional Contributor
    I was at the wrong level. Thanks for your help! this worked

    And just in case this helps others - you can set this up at Project, TestSuite, TestCase levels like this -

    "emailAddress": "${#Project#emailAddress}", for Project

    "emailAddress": "${#TestSuite#emailAddress}", for TestSuite

    "emailAddress": "${#TestCase#emailAddress}", for TestCase