我想使用groovy 5.0通过SoapUI脚本连接到测试链接服务器,然后将测试结果传递给测试链接
在尝试这样做之前,我安装了作为jar文件从GitHub (https://github.com/kinow/testlink-java-api)下载的TestLink Java API库。
我使用SoapUI将testlink-java-api-1.9.17-1Ext复制到以下路径:\SoapUI和\SoapUI\ archive.jar
//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);运行此脚本时,会出现以下unable to resolve类错误
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 ....... 在我的例子中,是否可以使用groovy脚本从SoapUI连接到testlink?有没有人能举个例子来说明如何正确地做到这一点?
发布于 2019-06-20 22:05:41
也许有人能帮上忙。事实证明,解决这个问题的方法有两种:
在分析了测试链接手册中的示例之后,我将以下代码添加到了脚本测试步骤中:
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;公共类TestlinkAPIXMLRPCClient { //在此处替换您的开发密钥公共静态最终字符串DEV_KEY = "fcd38512b5c3e44befbc8b862e678894";//在此处替换您的服务器URL公共静态最终字符串SERVER_URL = "http://172.29.0.78/testlink/lib/api/xmlrpc/v1/xmlrpc.php";/** *向TestLink接口上报测试执行情况** @param int tpid * @param int tpid* @param String status */ public static void testLinkReport(String tcid,int tpid,int bid,String plname,String status,String note){TestLink{ XmlRpcClient rpcClient;XmlRpcClientConfigImpl config;config =新的XmlRpcClientConfigImpl();Config.setServerURL(新的URL(SERVER_URL));rpcClient =新的XmlRpcClient();rpcClient.setConfig(配置);ArrayList参数=新的ArrayList();Hashtable executionData =新的Hashtable();executionData.put("devKey",DEV_KEY);executionData.put(“测试用例外部URL”,tcid);executionData.put("testplanid",tpid);executionData.put("buildid",bid);executionData.put("platformname",plname);executionData.put("status",状态);executionData.put("notes",备注);params.add(executionData);Object[] result = (Object[]) rpcClient.execute("tl.reportTCResult",params);//通常,您可能希望在此处验证结果,并可能对其执行更有用的操作(“result was:\n");for (int i=0;i< result.length;i++) { Map item = (Map)resulti;System.out.println("Keys:“+ item.keySet().toString() +”values:“+ item.values().toString());}} catch (MalformedURLException e) { e.printStackTrace();} catch (XmlRpcException e) { e.printStackTrace();}//发送到测试链接: //TestCaseID tcid,TestLpanID tpid,BuildId bid,PlatformName plname,status,notes Send 7367,238,"FLORAWARE","p","Result from GROOVY SOAPUI $add_info");
在soapui测试项目中,我创建了一个新的rest服务,方法是在带有testlink服务器地址的资源的路径中指定testlink api的路径。像这样:TestLink rest service
然后添加了以下传递参数到testlink的REST请求:
<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>发布于 2019-06-19 15:29:48
您必须像这样按顺序导入库:
this.getClass().classLoader.addURL(new File(context.expand(project.resourceRoot) + "/libs/testlink.jar").toURL());或者更好的做法是,将所有依赖项放在一个jar文件中,并使用该脚本行。您可以使用类的修饰名称:
testlink.api.java.client.TestLinkAPIClient api = new testlink.api.java.client.TestLinkAPIClient(DEVKEY, URL);这在90%的情况下都是正确的。
因为Groovy和SoapUI是不一致的,所以你可能需要使用两个步骤:
dynamically
的
一旦类被加载,这个错误就不会再出现了。
https://stackoverflow.com/questions/54536052
复制相似问题