Forum Discussion

sachin-chanchal's avatar
sachin-chanchal
Occasional Contributor
7 years ago
Solved

groovy script to add HTTP step in test case

Hi,

I am looking for a groovy script by which i would able to add HTTP type step in my test case. I am able to create/add test case in desire test suite but unable to find a groovy code/script to add HTTP type step in added test cases.

Please help.

 

Thanks

Sachin chanchal

  • nmrao's avatar
    nmrao
    7 years ago

    sachin-chanchal, thank you for the details.

     

    Try:

     

    import static com.eviware.soapui.impl.wsdl.teststeps.registry.HttpRequestStepFactory.HTTPREQUEST_TYPE 
    //Provide the http request endpoint in the below
    def endpoint = 'http://google.com'
    //Valid http method GET | PUT | POST | DELETE etc
    def method = 'GET'
    def stepName = 'httpRequestStep'
    
    //Adds http request step to given test case assumes tc is valid object of TestCase
    tc.addTestStep(HTTPREQUEST_TYPE , stepName, endpoint, method)

     

  • nmrao's avatar
    nmrao
    7 years ago

     

    sachin-chanchal,

     

    Try:

    //Assign the step object of the required test step in the below statement
    
    def step =
    
    def request = """<Request Object="System" Action="Logon"
    Username="ABC"
    Password="DEF"/>"""
    step.testRequest.setRequestContent( request )

7 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    If you can post current script, it would be easy pointing what portion of the script having problem?
    • sachin-chanchal's avatar
      sachin-chanchal
      Occasional Contributor

      Hi Rao,

      In my current scenario, I am able to create test suite and test case by groovy script

      suite = context.testCase.testSuite.project.addNewTestSuite(suiteName)
      and in another groovy, I  am using the below shown code for creating a test case

      def testSuite = context.testCase.testSuite.project.getTestSuiteByName(suiteName);

      def tc = testSuite.addNewTestCase(tcName)

       

      Now I want to add "HTTP" test step under above-created test case, I got code to create groovy step in test case

      tc.addTestStep(GroovyScriptStepFactory.GROOVY_TYPE, "TestStep1")
      tc.addTestStep(GroovyScriptStepFactory.GROOVY_TYPE, "TestStep2")

       

      But unable to find the way to create new test step in desired test case.

      OR

      if I will get got groovy code to copy Test step from one test suite to another then that will also work for me...

       

      Please suggest

      • nmrao's avatar
        nmrao
        Champion Level 3

        sachin-chanchal, thank you for the details.

         

        Try:

         

        import static com.eviware.soapui.impl.wsdl.teststeps.registry.HttpRequestStepFactory.HTTPREQUEST_TYPE 
        //Provide the http request endpoint in the below
        def endpoint = 'http://google.com'
        //Valid http method GET | PUT | POST | DELETE etc
        def method = 'GET'
        def stepName = 'httpRequestStep'
        
        //Adds http request step to given test case assumes tc is valid object of TestCase
        tc.addTestStep(HTTPREQUEST_TYPE , stepName, endpoint, method)