Understanding how to add ,retreive custom variables

Let us make a new SoapUi Project and copy the following WSDL into it.

http://footballpool.dataaccess.eu/data/info.wso?wsdl

Then we make two test Suites in this project.

First test suite is named players and we add two test cases into it. Test case 1- getPlayers-new test step –SoapRequest- getPlayers.

Test case 2- Forwards-new test step –SoapRequest- getForwards

Second test Suite is named Cards and we add two test cases into it. Test case 1- getRedCards-new test step –SoapRequest- getRedCards.

Test case 2- getYellowCards-new test step –SoapRequest- getYellowCards.

Then if we click our Project we see on bottom left corner we have some Project level properties that are common for our project.

We can click the + buttom and add custom properties that will be common for the entire project.

Same way we can click test suite,or any test case and see or make properties that are common to them.

Note-:We cant define custom variable for a test Step.

Now in Test Suite Cards,in test case yellow cards let us make a Groovy script and in that we can retrieve some project level properties or adding some more properties programmatically i.e instead of clicking the + button.Same way we can make properties at this test suite level or at a different test suite level

So in TestSuite 2 in the test case for cards we add a test step as groovy script and in that we can retrieve the custom property we stored at project level

def project_level = testRunner.testCase.testSuite.project//go to project  level
def user_name = project_level.getPropertyValue("adminusername") //get value for key adminusername
log.info  "Username from project level -"+user_name //print

project_level.setPropertyValue("totalnumberofteams","30") //we can even set a new customer property at project level. This is similar to what we do manually using the + sign.

So after executing the script and if we go to project level and custom properties we see out new property totalnumberofteams there.

Similarly we can go to testSuite level and write a property there. In our case it will be written in suite2 as we are executing groovy script in suite 2 and test case within it.

def testsuite_level = testRunner.testCase.testSuite;
testsuite_level.setPropertyValue("name","Cards")//write a property to test suite level
def  suite_name = testsuite_level.getPropertyValue("name")
log.info suite_name

Now lets see how we can set Property in a different test suite

def testsuite_level_players = project_level.testSuites["Players"];
testsuite_level_players.setPropertyValue("name","players")  ////write a property to test suite level
def  suite_name_players = testsuite_level_players.getPropertyValue("name")
log.info suite_name_players

Similarly instead of jumping up and down these levels we can get the variables from various levels like this as well.

log.info "Project level--------" +context.expand('${#Project#adminname}') 
log.info "TestSuite level--------" +context.expand('${#TestSuite#name}') 
log.info "TestCase level--------" +context.expand('${#TestCase#testcasename}')

But here we were in getYellowCards test case and GroovyScript test step,so using above commands we were able to get all variables corresponding to project level ,TestSuite level and test case level for this test step.

What if we want variables from some other test Suite or test case.Note-:We cant define custom variable for a test Step.

The below commands will give all values for test suites, test cases etc corresponding to test step getPlayers only.

def testStep =  project_level.testSuites['Players'].testCases['getPlayers'].testSteps['getPlayers']
def testStepContext  =  new WsdlTestRunContext(testStep);
log.info "Project level--------" +testStepContext.expand('${#Project#adminname}') 
log.info "TestSuite level--------" +testStepContext.expand('${#TestSuite#name}')