Forum Discussion

Emil91's avatar
Emil91
Contributor
8 years ago

Is it possible to randomize test steps in test cases using soapUI NG pro?

Hey guys,   I need to randomize test steps in my tests, as we all know there are plenty of sequences and combinations and randomizing such steps could help to catch more unwanted problems/bugs, I ...
  • groovyguy's avatar
    8 years ago

     

    This is something easily done in groovy. Here's a very simple mocked up script:

     

     

    def proj = testRunner.testCase.testSuite.project;
    
    def TS = proj.getTestSuiteList();
    
    if (proj.getTestSuiteCount() > 1)
    {
    	Collections.shuffle(TS);
    }
    
    for (int i = 0; i < proj.getTestSuiteCount(); i++)
    {
    	def testSuite = TS[i];
    
    	def TC = testSuite.getTestCaseList();
    
    	if (testSuite.getTestCaseCount() > 1)
    	{
    		Collections.shuffle(TC);
    	}
    	for (int j = 0; j < testSuite.getTestCaseCount(); j++)
    	{
    		def testCase = TC[j];
    
    		def TSteps = testCase.getTestStepList();
    
    		if (testCase.getTestStepCount() > 1)
    		{
    			Collections.shuffle(TSteps);
    		}
    		
    		for (int k = 0; k < testCase.getTestStepCount(); k++)
    		{
    			def properties = new com.eviware.soapui.support.types.StringToObjectMap()
    			def async = false
    			//--run object string against TC
    			log.info(TSteps[k].toString());
    			def testStep = TSteps[k];
    			def label = testStep.getLabel();
    			log.info(label);
    			// tesStep.run (properties, async)
    		}
    	}
    }
    
    

     

  • groovyguy's avatar
    groovyguy
    8 years ago

    Try replacing

     

    testStep.run (properties, async)

     

    with 

     

    testRunner.runTestStepByName(label)
  • groovyguy's avatar
    groovyguy
    8 years ago

    You really don't need groovy skills at this point. You have the script. You know at any given point what the label of the test running is from this line:

     

     

    		def label = testStep.getLabel();

     

    So, if you know the test whose label is "Test X" and that means you need to run transfer Y, you could set a new test step to the property transfer and run that.

     

    if (label == "Test X")
    {
    	def propTransferTestStep = context.testCase.testStep["PropertyTransferStepName"];
    	propTransferTesttStep.run(testRunner, context);	
    }