Forum Discussion

itsmylife's avatar
itsmylife
New Contributor
6 years ago

Modularize the soapui test suites: Groovy script in eclipse, create a jar file & call it into soapUI

I need to create a sample Soap request by calling the endpoint URL and give the necessary login and password info and then send a request and get a response in XML. I'm writing the groovy script in eclipse IDE and creating a jar file and call that jar file into SoapUI and call the code within the jar file into SoapUI.

 

I am getting an error and how should I resolve this? Is there any other way to achieve my goal? Please help me.

 

The Output:

Caught: groovy.lang.GroovyRuntimeException: This script or class could not be run. It should either: - have a main method, - be a JUnit test or extend GroovyTestCase, - implement the Runnable interface, - or be compatible with a registered script runner. Known runners: * org.apache.groovy.plugin.DefaultRunners$Junit3TestRunner * org.apache.groovy.plugin.DefaultRunners$Junit3SuiteRunner * org.apache.groovy.plugin.DefaultRunners$Junit4TestRunner

 

Here is the code:

package com.xyz.demo

class ABC {
public setUP() {
    // set data
    def url = new URL("https://qwertywq.asmx").openConnection();
    if(soapaction != null) connection.setRequestProperty("SOAPAction", soapaction);
    connection.setRequestProperty("Content-Type", "Text/xml");
    String AuthorizationString = "Basic " + (username + ":" +  password).bytes.encodeBase64();
    connection.setRequestProperty("Authorization", authorizationString);
    OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
    wr.write(xml);
    wr.close();

    // Get the response
        String response;
        InputStream responseStream;
        try {
            responseStream = connection.getInputStream();
            success = 1;
        } catch( IOException e ) {
            success = 0;
            if( connection.getResponseCode() == 500 ) {
                responseStream = connection.getErrorStream();
            } else throw e;
        }

    response = responseStream.getText("utf-8");
    responseStream.close();
    return response;
}

2 Replies

  • itsmylife's avatar
    itsmylife
    New Contributor

    When I add a main method to the above code I am getting another error. Please help me to sort out the best way to deal with this task.

     

    Caught: groovy.lang.MissingMethodException: No signature of method: static com.qwertyqw.main() is applicable for argument types: ([Ljava.lang.String; ) values: [[]]
    Possible solutions: main([Ljava.lang.String; ), wait(), wait(long), any(), find(), wait(long, int)
    groovy.lang.MissingMethodException: No signature of method: static com.swsim.demo.CreateEnvelopeIndicium.main() is applicable for argument types: ([Ljava.lang.String; ) values: [[]]
    Possible solutions: main([Ljava.lang.String; ), wait(), wait(long), any(), find(), wait(long, int)

    • Olga_T's avatar
      Olga_T
      SmartBear Alumni (Retired)

      Hi itsmylife, thanks for reaching out.

       

      Community, has anyone faced a similar situation? Can anyone assist please?