LowCool
LowCool

Reputation: 1411

How to run particular Test step of soapUi in java

I want to run particular testStep of my testcase of soap ui using java code. My problem is when I try to run at test step level it need argument of TestCase runner which is anonymous inner type and TestCaseRunContext which is interface. Do I have to implement both to run the same? if yes can please any sample how to do that??

here's my code

package com.testauto.soaprunner.soap.impl;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eviware.soapui.SoapUI;
import com.eviware.soapui.StandaloneSoapUICore;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
import com.eviware.soapui.model.TestPropertyHolder;
import com.eviware.soapui.model.iface.MessageExchange;
import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
import com.eviware.soapui.model.testsuite.TestCase;
import com.eviware.soapui.model.testsuite.TestCaseRunContext;
import com.eviware.soapui.model.testsuite.TestProperty;
import com.eviware.soapui.model.testsuite.TestStepResult;
import com.eviware.soapui.model.testsuite.TestSuite;
import com.eviware.soapui.support.types.StringToObjectMap;
import com.eviware.soapui.support.types.StringToStringsMap;
import com.testauto.soaprunner.data.InputData;
import com.testauto.soaprunner.data.ReportData;

public class RunTestImpl{

    static Logger logger = LoggerFactory.getLogger(RunTestImpl.class);
    List<ReportData> reportDatList=new ArrayList<ReportData>();
    public  List<ReportData> process(Map<String, String> readDataMap, InputData input, Map<List<String>, String> configurationMap, List<String> configuration, WsdlTestSuite testSuite)
    {
         List<ReportData>  report = new ArrayList<ReportData>();
            logger.info("Into the Class for running test cases");
            try{
    report= getTestSuite(readDataMap,input,configurationMap,configuration,testSuite);
            }
            catch(Exception e)
            {
                logger.info(e.getMessage());
            }
            return report;
    }

    private  List<ReportData> getTestSuite(Map<String, String> readDataMap, InputData input, Map<List<String>, String> configurationMap, List<String> configuration, WsdlTestSuite testSuite) throws Exception {

        ReportData report=new ReportData();

         logger.info("Into the Class for running test cases");

        String suiteName = "";
        String reportStr = "";






    List<String>  testCaseNameList=  setPropertyValues(readDataMap,input);





      WsdlTestCaseRunner runner = null;

        List<TestSuite> suiteList = new ArrayList<TestSuite>();
        List<TestCase> caseList = new ArrayList<TestCase>();

        SoapUI.setSoapUICore(new StandaloneSoapUICore(true));


      System.out.println("testcase name "+ configurationMap.get(configuration));

    //  WsdlTestCase testCase= testSuite.getTestCaseByName(input.getApiName()+"_"+testCaseName+"_TestCase");
       WsdlTestCase testCase= testSuite.getTestCaseByName("my_TESTCASE");

       WsdlTestStep tesStep=testCase.getTestStepByName(configurationMap.get(testCaseNameList));
System.out.println("test case name:"+testCase.getName());
report.setTestCase(testCase.getName());


      suiteList.add(testSuite);






    runner=  tesStep.run(?,?);






        return reportDatList;
    }
    private List<String> setPropertyValues(Map<String, String> readDataMap, InputData input) {
        String testCaseName="";
         TestPropertyHolder holder = PropertyExpansionUtils.getGlobalProperties();
         List<String> dataConfigurationList=new ArrayList<String>();
         Iterator entries = readDataMap.entrySet().iterator();
          while (entries.hasNext()) {
              Entry thisEntry = (Entry) entries.next();
             String key = (String) thisEntry.getKey();
            String value = (String) thisEntry.getValue();

                testCaseName+=key;
                holder.setPropertyValue(key, holder.getPropertyValue(key));
                dataConfigurationList.add(key);

                  }


         System.out.println("testCaseName"+testCaseName);
          return dataConfigurationList;

    }

    }

}

Upvotes: 0

Views: 779

Answers (1)

LowCool
LowCool

Reputation: 1411

After trying different things I got something like this.

 TestCaseRunContext context = new MockTestRunContext(new MockTestRunner(testStep.getTestCase()), testStep);

        MockTestRunner runner = new MockTestRunner(testStep.getTestCase());

        TestStepResult testStepResult=   testStep.run(runner, context);

I don't know how it works this trick worked for me. if someone know the reason behind this please share

Upvotes: 1

Related Questions