0
votes

I want to use SoapUI 5.0 to connect with a groovy script to the testlink server and then pass the test result to the test link

Before I tried to do this, I installed the TestLink Java API library downloaded from GitHub (https://github.com/kinow/testlink-java-api) as a jar file.

I copied the testlink-java-api-1.9.17-1 archive.jar to the directory with SoapUI the following paths: \SoapUI\lib and \SoapUI\bin\ext

//here is my code from the groovy script test step

    import testlink.api.java.client.TestLinkAPIResults.*;
    import testlink.api.java.client.TestLinkAPIClient.*;

     def DEVKEY="2f404203b306bd8dd811a7f824c194d0";
     def  URL="http://172.29.0.73/testlink/lib/api/xmlrpc/v1/xmlrpc.php";

    TestLinkAPIClient api = new TestLinkAPIClient(DEVKEY, URL);

When running this script, the following unable to resolve class error occurs

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script74.groovy: 7: unable to resolve class TestLinkAPIClient @ line 7, column 19. TestLinkAPIClient api = new TestLinkAPIClient(DEVKEY, URL); ^ org.codehaus.groovy.syntax.SyntaxException: unable to resolve class TestLinkAPIClient @ line 7, column 19. at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146) at ....... 

enter image description here

Is it possible in my case to connect using the groovy script from SoapUI to testlink? And can anyone give an example of how to do it correctly?

2
Do you want to update the each test case to call TestLink and update? or Update all the test result at end of the test execution? - Rao
I want to add a groovy script test step to each test case, the results of which should be passed to the testlink. But first I need to deal with the connection to the testlink from soapui - victor

2 Answers

1
votes

maybe someone will be useful. It turned out to solve this problem in two ways:

  1. Having analyzed the examples in the test link manual, I added the following code to a Groovy script test step:

    import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.Hashtable;
    import java.util.Map;
    
    import org.apache.xmlrpc.XmlRpcException;
    import org.apache.xmlrpc.client.XmlRpcClient;
    import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
    def TranId= "TranId : " + testRunner.testCase.getPropertyValue( "TranId" )
    def  Response= "Response: "+ testRunner.testCase.getPropertyValue( "Response" )
    def  TL_extid = testRunner.testCase.getPropertyValue( "TL_extid" )
    def add_info = TranId +" " + Response;
    
    public class TestlinkAPIXMLRPCClient 
    {   
        // Substitute your Dev Key Here
        public static final String DEV_KEY =  "fcd38512b5c3e44befbc8b862e678894";
        // Substitute your Server URL Here
        public static final String SERVER_URL = "http://172.29.0.78/testlink/lib/api/xmlrpc/v1/xmlrpc.php"; 
    
        /**
         * report test execution to TestLink API
         * 
         * @param int tcid
         * @param int tpid
         * @param String status
         */
        public static void testLinkReport(String tcid, int tpid,int bid,String plname, String status, String notes)
        {
            try 
            {
                XmlRpcClient rpcClient;
                XmlRpcClientConfigImpl config;
    
                config = new XmlRpcClientConfigImpl();
                config.setServerURL(new URL(SERVER_URL));
                rpcClient = new XmlRpcClient();
                rpcClient.setConfig(config);        
    
                ArrayList<Object> params = new ArrayList<Object>();
                Hashtable<String, Object> executionData = new Hashtable<String, Object>();              
                executionData.put("devKey", DEV_KEY);
                executionData.put("testcaseexternalid", tcid);
                executionData.put("testplanid", tpid);
                executionData.put("buildid", bid);
                executionData.put("platformname", plname);
                executionData.put("status", status);
                executionData.put("notes", notes);
                params.add(executionData);
    
                Object[] result = (Object[]) rpcClient.execute("tl.reportTCResult", params);
    
                // Typically you'd want to validate the result here and probably do something more useful with it
                System.out.println("Result was:\n");                
                for (int i=0; i< result.length; i++)
                {
                    Map item = (Map)result[i];
                    System.out.println("Keys: " + item.keySet().toString() + " values: " + item.values().toString());
                }
            }
            catch (MalformedURLException e)
            {
                e.printStackTrace();
            }
            catch (XmlRpcException e)
            {
                e.printStackTrace();
            }
        }
    }
        //Send to testlink:
        //TestCaseID tcid, TestLpanID  tpid, BuildId bid, PlatformName plname,  status  ,notes
    
        TestlinkAPIXMLRPCClient.testLinkReport("$TL_extid", 7367,238 ,"FLORAWARE", "p",  
        "Result from  GROOVY SOAPUI $add_info");
    
  2. I think the most elegant way.

in the soapui test project I`ve created a new rest service by specifying the path to the testlink api in the path to the resource with the testlink server address. Like this: TestLink rest service

and then added the following REST request for passing parameters to the testlink:

<methodCall>
   <methodName>tl.reportTCResult</methodName>
   <params>
      <param>
         <value>
            <struct>
               <member>
                  <name>devKey</name>
                  <value>${#TestSuite#DEV_KEY}</value>
               </member>
               <member>
                  <name>status</name>
                  <value>${TL_Properties#TestResult}</value>
               </member>
               <member>
                  <name>buildid</name>
                  <value>
                     <i4>${TL_Properties#LatestBuildID}</i4>
                  </value>
               </member>
               <member>
                  <name>platformname</name>
                  <value>FLORAWARE</value>
               </member>
               <member>
                  <name>notes</name>
                  <value>TEST RUN FROM SOAPUI Transaction ID: ${TL_Properties#TranID} Response: ${TL_Properties#Response}</value>
               </member>
               <member>
                  <name>testplanid</name>
                  <value>
                     <i4>7367</i4>
                  </value>
               </member>
               <member>
                  <name>testcaseexternalid</name>
                  <value>${#TestCase#TL_extid}</value>
               </member>
                   <member>
                  <name>execduration</name>
                  <value>1</value>
               </member>
            </struct>
         </value>
      </param>
   </params>
</methodCall>
0
votes

You have to import the library dinamically like this:

this.getClass().classLoader.addURL(new File(context.expand(project.resourceRoot) + "/libs/testlink.jar").toURL());

Or better yet, put all the dependencies in one jar file and use that script line. You have the use the decorated name of the class:

testlink.api.java.client.TestLinkAPIClient api = new testlink.api.java.client.TestLinkAPIClient(DEVKEY, URL);

This is about right 90% of the times.

Since Groovy and SoapUI are inconsistent, you may have to use two steps:

  1. import the libraries dynamically
  2. use the TestLinkAPIClient.

Once the classes are loaded, that error won't show up anymore.