user3745193
user3745193

Reputation: 97

How to run testcase and testsuite using Groovy in soapui?

i have some projects in soapui. i want to execute testsuites and testcases of these projects. i tried with this groovy code:

//get test case from other project or from the same one
project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("Project1")
testSuite = project.getTestSuiteByName("TestSuite 1 - Login");
testCase = testSuite.getTestCaseByName("TestCase 1-Login");
Thread.sleep(3000)
testSuite2 = project.getTestSuiteByName("TestSuite3 - Report");
testCase2 = testSuite.getTestCaseByName("TestCase1 - Report");

// run test case
runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);
Thread.sleep(3000)
runner2 = testCase2.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);

When i run this groovy code, i have the following error message: java.lang.NullPointer.Exception cannot invoke method run() on null object for the last line

runner2 = testCase2.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);

If i remove the last line it's working well.

Any help please. Thank you

Upvotes: 3

Views: 13632

Answers (3)

himanshu tayal
himanshu tayal

Reputation: 21

I know this is super late to answer this question, but i will answer this so that it can help help seeking for help.

instead of Thread.sleep(3000), just use:

runner.waitUntilFinished()

Now it will wait until execution of step 1 get finished. Then it will start executing Step 2.

Upvotes: 2

Dipesh Udhlani
Dipesh Udhlani

Reputation: 11

// TO RUN A TEST SUITEs ALL get APIs, getting testSuite handle from current          //test_Case
// TO POST COMMENT I HAVE ADDED underscore char BELOW

// u need to import here
 def my_TestSuite = testRunner.testCase.testSuite
 log.info(my_TestSuite.name)

 for (my_TestCase in my_TestSuite.get_TestCaseList())
 {
      for (testStep in myTestCase.get_TestStepList())
      {
         if( testStep instanceof WsdlTestRequestStep || testStep instanceof                       RestTestRequestStep ) {
                  def http_Verb = (testStep.getTestRequest().getMethod())
                  String apiType = http_Verb.toString()
                  if (apiType == "GET"){
                    log.info(myTestCase.name)   
                 }
             }
         }  
  }

Upvotes: 0

user3280424
user3280424

Reputation: 167

The only thing I can think of is that you're calling the wrong testcase on the step2, I tested the same with other test cases I have and it's happening the same If I put a wrong name for the test case I want to execute.

Upvotes: 0

Related Questions