java如何连接testlink

1.下载相关的jar包

java如何连接testlink

2.获取到testlink的url和key,注意:url不是testlink的连接地址,是连接地址+/lib/api/xmlrpc.php

java如何连接testlink

3.测试是否连接成功

	public static void main(String args[]) {
String url = "http://test.tl.gmsd.lan/lib/api/xmlrpc.php";
String devKey = "223f929e98e3d74fa3c000b67668e305";
TestLinkAPI api = null; URL testlinkURL = null; try {
testlinkURL = new URL(url);
} catch ( MalformedURLException mue ) {
mue.printStackTrace( System.err );
System.exit(-1);
} //api = new
try {
api = new TestLinkAPI(testlinkURL, devKey);
} catch( Exception te) {
te.printStackTrace( System.err );
System.exit(-1);
} System.out.println(api.ping());
}

  运行后,出现hello即表明连接成功

4. 更改测试用例执行结果

        /*批量根据用例id执行*/
TestPlan tp = api.getTestPlanByName("XXXX((2015/7/21-2015/7/30)", "交易系统"); String buildName = "XXXX";
Integer testPlanId = tp.getId(); TestSuite[] ts = api.getTestSuitesForTestPlan(tp.getId());
System.out.println(ts.length);
TestCaseDetails tcd = null;
int index = 0;
for(int i=0;i<ts.length;i++) {
TestCase[] tc = api.getTestCasesForTestSuite(ts[i].getId(), true, tcd);
//System.out.println(tc.length);
System.out.println(ts[i].getName());
for(int j=0;j<tc.length;j++) {
Integer testCaseId = tc[j].getId();
// api.reportTCResult(testCaseId, null, testPlanId, ExecutionStatus.PASSED, null, buildName, "自动化上传结果的备注", null, null, null, null, null, null);
//api.createTestPlan("testPlanqjf1", projectName, notes, isActive, isPublic)
} index += tc.length;
}
System.out.println("共执行 "+index+" 条用例");

/*跟进用例id更改*/

//获取测试计划id
Integer testPlanId = api.getTestPlanByName("新增还款方式(最新)", "交易系统").getId();
String buildName = "交易新增还款方式";

Integer testCaseId = 3734;

api.reportTCResult(testCaseId, null, testPlanId, ExecutionStatus.FAILED, null, buildName, "自动化上传结果的备注", null, null, null, null, null, null);

  

        /*创建测试用例*/
String testCaseName= "居间人管理:添加居间人";
Integer testSuiteId = 6762;
Integer testProjectId = 214;
//Integer testSuiteId1 = 6762; //获取测试用例集id
System.out.println(api.getTestCase(6763, null, null).getTestSuiteId());
//获取getAuthorLogin
System.out.println("getAuthorLogin="+api.getTestCase(6763, null, null).getAuthorLogin());
//api.getTestSuiteByID(6762)
//获取getSummary
System.out.println(api.getTestCase(6763, null, null).getTestProjectId());
api.getTestCase(6763, null, null);
System.out.println("id="+api.getTestProjectByName("交易系统").getId()); // System.out.println(api.getTestCase(6763, null, null).getSummary());
// api.createTestCase(testCaseName, testSuiteId, 170, "qusername", "点击一级菜单【居间人管理】选择二级菜单【居间人管理】功能,进入居间人管理界面", null, null, null, null, null, null, null, null);

相关的用例id和buildname可以从导出的测试计划xml文件中得到。如下图

java如何连接testlink

java如何连接testlink

附录:

testlink常用的方法:http://testlinkjavaapi.sourceforge.net/implemented_methods.html

testlink接口:http://testlinkjavaapi.sourceforge.net/structure.html

上一篇:centos和windows添加路由命令记录


下一篇:ubuntu实现ramdisk